/**
IotWebConf01Minimal.ino -- IotWebConf is an ESP8266/ESP32
non blocking WiFi/AP web configuration library for Arduino.
https://github.com/prampec/IotWebConf
Copyright (C) 2018 Balazs Kelemen
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.
*/
/**
Example: Minimal
Description:
This example will shows the bare minimum required for IotWeConf to start up.
After starting up the thing, please search for WiFi access points e.g. with
your phone. Use password provided in the code!
After connecting to the access point the root page will automatically appears.
We call this "captive portal".
Please set a new password for the Thing (for the access point) as well as
the SSID and password of your local WiFi. You cannot move on without these steps.
You have to leave the access point before to let the Thing continue operation
with connecting to configured WiFi.
Note that you can find detailed debug information in the serial console depending
on the settings IOTWEBCONF_DEBUG_TO_SERIAL, IOTWEBCONF_DEBUG_PWD_TO_SERIAL set
in the IotWebConf.h .
*/
#include
#include
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;
// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point.
const char thingName[] = "EFrame";
// -- Initial password to connect to the Thing, when it creates an own Access Point.
const char wifiInitialApPassword[] = "smartframe";
DNSServer dnsServer;
WebServer server(80);
IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Starting Wifi configuration...");
// -- Initializing the configuration.
iotWebConf.init();
// -- Set up required URL handlers on the web server.
server.on("/", handleRoot);
server.on("/config", [] { iotWebConf.handleConfig(); });
server.onNotFound([]() {
iotWebConf.handleNotFound();
});
Serial.println("Ready.");
}
void loop() {
// -- doLoop should be called as frequently as possible.
iotWebConf.doLoop();
if (WiFi.status() == WL_CONNECTED) {
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
Serial.println("................ Here to do the e-paper thing for 15 seconds...............");
delay(15000);
Serial.flush();
Serial.println("then start sleeping...");
esp_deep_sleep_start();
}
}
/**
Handle web requests to "/" path.
*/
void handleRoot()
{
// -- Let IotWebConf test and handle captive portal requests.
if (iotWebConf.handleCaptivePortal()) {
// -- Captive portal request were already served.
return;
}
String s = "
";s += "
s += "
Go to configure page to change settings.
";s += "\n";
server.send(200, "text/html", s);
}