diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 5a9f5acefd4b83d7e1be0487fd403cfb24c908d3..27a9071620bfd783b1fd10441f397c3d876f6685 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -30,8 +30,6 @@ const char wifiInitialApPassword[] = "smrtTHNG8266"; // -- Method declarations. void handleRoot(); -// -- Callback methods. -void configSaved(); DNSServer dnsServer; WebServer server(80); @@ -94,55 +92,34 @@ iotwebconf::TimeTParameter timeParam = defaultValue(""). build(); -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); - 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(); }); +void defineConsoleCommands() { + sensor_console::defineCommand("reset", []() { + ESP.restart(); + }, F("(Restarts the ESP)")); - 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", []() { Serial.println(F("Resetting config...")); iotWebConf.getRootParameterGroup()->applyDefaultValue(); Serial.println(F("Done!")); }, F("(Resets the complete IotWeb config)")); - + sensor_console::defineStringCommand("ssid", [](char *ssid) { Serial.print(F("Setting WiFi ssid to ")); Serial.println(ssid); strlcpy(iotWebConf.getWifiSsidParameter()->valueBuffer, ssid, iotWebConf.getWifiSsidParameter()->getLength()); - }, F("name (Sets SSID to name)")); - - sensor_console::defineStringCommand("wifi_pwd", [](char *pwd) { - Serial.print(F("Setting WiFi password to ")); - Serial.println(pwd); - strlcpy(iotWebConf.getWifiPasswordParameter()->valueBuffer, pwd, iotWebConf.getWifiPasswordParameter()->getLength()); - }, F("abc (Sets WiFi password to abc)")); + }, F("name (Sets SSID to name)")); + + sensor_console::defineStringCommand("wifi_pwd", + [](char *pwd) { + Serial.print(F("Setting WiFi password to ")); + Serial.println(pwd); + strlcpy(iotWebConf.getWifiPasswordParameter()->valueBuffer, pwd, + iotWebConf.getWifiPasswordParameter()->getLength()); + }, F("abc (Sets WiFi password to abc)")); sensor_console::defineStringCommand("ap_pwd", [](char *pwd) { Serial.print(F("Setting AP password to ")); @@ -150,6 +127,12 @@ void setup() strlcpy(iotWebConf.getApPasswordParameter()->valueBuffer, pwd, iotWebConf.getApPasswordParameter()->getLength()); }, 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) { if (onOff) { Serial.print(F("Enable ")); @@ -162,19 +145,43 @@ void setup() sensor_console::defineIntCommand("wifi", [](int onOff) { if (onOff) { - Serial.print(F("Enable ")); + Serial.print(F("Enable Wifi!")); iotWebConf.goOnLine(); } else { - Serial.print(F("Disable ")); + Serial.print(F("Disable Wifi!")); iotWebConf.goOffLine(); } - Serial.println(F("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() @@ -224,11 +231,6 @@ void handleRoot() server.send(200, "text/html", s); } -void configSaved() -{ - Serial.println("Configuration was updated."); -} - /*** * Sensor console */