DynaConfig
DynaConfig is an Arduino library for managing WiFi configuration on ESP32 devices using a captive portal.
Loading...
Searching...
No Matches
dynaconfig.h
Go to the documentation of this file.
1/*
2 * This file is part of the Arduino dynaconfig library (https://github.com/nthnn/dynaconfig).
3 * Copyright (c) 2024 Nathanne Isip.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
39#ifndef DYNACONFIG_H
40#define DYNACONFIG_H
41
42#include <AsyncTCP.h>
43#include <ESPAsyncWebServer.h>
44
45#include <DNSServer.h>
46#include <Preferences.h>
47#include <WiFi.h>
48
63public:
69 DynaConfig(const char* captivePortalName);
70
80 void checkWiFiConfig();
81
85 void close();
86
93 bool hasCredentials();
94
101 bool removeCredentials();
102
108 String getConfigSSID();
109
115 String getConfigPasskey();
116
117private:
118 AsyncWebServer server;
119 DNSServer dnsServer;
120 Preferences preferences;
121 String portalName;
122
132 class CaptiveRequestHandler : public AsyncWebHandler {
133 public:
139 CaptiveRequestHandler(const char* html);
140
147 bool canHandle(AsyncWebServerRequest *request) override;
148
154 void handleRequest(AsyncWebServerRequest *request) override;
155
156 private:
157 const char* index_html;
158 };
159
166 void handleCycle();
167
174 void setupServer();
175
176 static const char* index_html;
177 static const char* success_html;
178 static const char* error_html;
179};
180
181#endif // DYNACONFIG_H
Manages dynamic WiFi configuration through a captive portal.
Definition dynaconfig.h:62
String getConfigSSID()
Retrieves the stored WiFi SSID from Preferences.
Definition dynaconfig.cpp:54
void close()
Closes the Preferences storage.
Definition dynaconfig.cpp:41
bool removeCredentials()
Removes stored WiFi credentials from Preferences.
Definition dynaconfig.cpp:50
String getConfigPasskey()
Retrieves the stored WiFi password from Preferences.
Definition dynaconfig.cpp:58
void checkWiFiConfig()
Checks and manages the WiFi configuration.
Definition dynaconfig.cpp:24
bool hasCredentials()
Checks if WiFi credentials are stored in Preferences.
Definition dynaconfig.cpp:45