Commit a79fc50f authored by Eric Duminil's avatar Eric Duminil
Browse files

Some refactor

parent accc8d0d
...@@ -30,8 +30,6 @@ const char wifiInitialApPassword[] = "smrtTHNG8266"; ...@@ -30,8 +30,6 @@ const char wifiInitialApPassword[] = "smrtTHNG8266";
// -- Method declarations. // -- Method declarations.
void handleRoot(); void handleRoot();
// -- Callback methods.
void configSaved();
DNSServer dnsServer; DNSServer dnsServer;
WebServer server(80); WebServer server(80);
...@@ -94,55 +92,34 @@ iotwebconf::TimeTParameter timeParam = ...@@ -94,55 +92,34 @@ iotwebconf::TimeTParameter timeParam =
defaultValue(""). defaultValue("").
build(); build();
void setup() void defineConsoleCommands() {
{ sensor_console::defineCommand("reset", []() {
Serial.begin(115200); ESP.restart();
Serial.println(); }, F("(Restarts the ESP)"));
Serial.println("Starting up...");
group1.addItem(&intParam);
group2.addItem(&floatParam);
group2.addItem(&checkboxParam);
group2.addItem(&chooserParam);
group2.addItem(&colorParam);
group2.addItem(&dateParam);
group2.addItem(&timeParam);
iotWebConf.addSystemParameter(&stringParam);
iotWebConf.addParameterGroup(&group1);
iotWebConf.addParameterGroup(&group2);
iotWebConf.setConfigSavedCallback(&configSaved);
iotWebConf.getApTimeoutParameter()->visible = true;
// -- 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(); });
sensor_console::defineCommand("reset", [](){ ESP.restart(); }, F("(Restarts the ESP)")); sensor_console::defineCommand("save_config", []() {
iotWebConf.saveConfig();
}, F("(Saves the config to EEPROM)"));
sensor_console::defineCommand("save_config", [](){ iotWebConf.saveConfig(); }, F("(Saves the config to EEPROM)"));
sensor_console::defineCommand("reset_config", []() { sensor_console::defineCommand("reset_config", []() {
Serial.println(F("Resetting config...")); Serial.println(F("Resetting config..."));
iotWebConf.getRootParameterGroup()->applyDefaultValue(); iotWebConf.getRootParameterGroup()->applyDefaultValue();
Serial.println(F("Done!")); Serial.println(F("Done!"));
}, F("(Resets the complete IotWeb config)")); }, F("(Resets the complete IotWeb config)"));
sensor_console::defineStringCommand("ssid", [](char *ssid) { sensor_console::defineStringCommand("ssid", [](char *ssid) {
Serial.print(F("Setting WiFi ssid to ")); Serial.print(F("Setting WiFi ssid to "));
Serial.println(ssid); Serial.println(ssid);
strlcpy(iotWebConf.getWifiSsidParameter()->valueBuffer, ssid, iotWebConf.getWifiSsidParameter()->getLength()); strlcpy(iotWebConf.getWifiSsidParameter()->valueBuffer, ssid, iotWebConf.getWifiSsidParameter()->getLength());
}, F("name (Sets SSID to name)")); }, F("name (Sets SSID to name)"));
sensor_console::defineStringCommand("wifi_pwd", [](char *pwd) { sensor_console::defineStringCommand("wifi_pwd",
Serial.print(F("Setting WiFi password to ")); [](char *pwd) {
Serial.println(pwd); Serial.print(F("Setting WiFi password to "));
strlcpy(iotWebConf.getWifiPasswordParameter()->valueBuffer, pwd, iotWebConf.getWifiPasswordParameter()->getLength()); Serial.println(pwd);
}, F("abc (Sets WiFi password to abc)")); strlcpy(iotWebConf.getWifiPasswordParameter()->valueBuffer, pwd,
iotWebConf.getWifiPasswordParameter()->getLength());
}, F("abc (Sets WiFi password to abc)"));
sensor_console::defineStringCommand("ap_pwd", [](char *pwd) { sensor_console::defineStringCommand("ap_pwd", [](char *pwd) {
Serial.print(F("Setting AP password to ")); Serial.print(F("Setting AP password to "));
...@@ -150,6 +127,12 @@ void setup() ...@@ -150,6 +127,12 @@ void setup()
strlcpy(iotWebConf.getApPasswordParameter()->valueBuffer, pwd, iotWebConf.getApPasswordParameter()->getLength()); strlcpy(iotWebConf.getApPasswordParameter()->valueBuffer, pwd, iotWebConf.getApPasswordParameter()->getLength());
}, F("abc (Sets AP password to abc)")); }, F("abc (Sets AP password to abc)"));
sensor_console::defineStringCommand("name", [](char *name) {
Serial.print(F("Setting Thing name to "));
Serial.println(name);
strlcpy(iotWebConf.getThingNameParameter()->valueBuffer, name, iotWebConf.getThingNameParameter()->getLength());
}, F("abc (Sets AP password to abc)"));
sensor_console::defineIntCommand("ap", [](int onOff) { sensor_console::defineIntCommand("ap", [](int onOff) {
if (onOff) { if (onOff) {
Serial.print(F("Enable ")); Serial.print(F("Enable "));
...@@ -162,19 +145,43 @@ void setup() ...@@ -162,19 +145,43 @@ void setup()
sensor_console::defineIntCommand("wifi", [](int onOff) { sensor_console::defineIntCommand("wifi", [](int onOff) {
if (onOff) { if (onOff) {
Serial.print(F("Enable ")); Serial.print(F("Enable Wifi!"));
iotWebConf.goOnLine(); iotWebConf.goOnLine();
} else { } else {
Serial.print(F("Disable ")); Serial.print(F("Disable Wifi!"));
iotWebConf.goOffLine(); iotWebConf.goOffLine();
} }
Serial.println(F("Wifi!"));
}, F("0/1 (Enables/disables WiFi)")); }, F("0/1 (Enables/disables WiFi)"));
}
//TODO: Remove fluff
//TODO: Add wifi on/off?
Serial.println("Ready."); void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("Starting up...");
group1.addItem(&intParam);
group2.addItem(&floatParam);
group2.addItem(&checkboxParam);
group2.addItem(&chooserParam);
group2.addItem(&colorParam);
group2.addItem(&dateParam);
group2.addItem(&timeParam);
iotWebConf.addSystemParameter(&stringParam);
iotWebConf.addParameterGroup(&group1);
iotWebConf.addParameterGroup(&group2);
// -- 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(); });
defineConsoleCommands();
Serial.println(F("Ready."));
} }
void loop() void loop()
...@@ -224,11 +231,6 @@ void handleRoot() ...@@ -224,11 +231,6 @@ void handleRoot()
server.send(200, "text/html", s); server.send(200, "text/html", s);
} }
void configSaved()
{
Serial.println("Configuration was updated.");
}
/*** /***
* Sensor console * Sensor console
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment