diff --git a/ampel-firmware/sensor_console.cpp b/ampel-firmware/sensor_console.cpp index 88790b461c2ec9aa0969d4d73e21dd091db7553f..f6e182784bd8755983fcc822ed95b98af5deb9bd 100644 --- a/ampel-firmware/sensor_console.cpp +++ b/ampel-firmware/sensor_console.cpp @@ -1,7 +1,7 @@ #include "sensor_console.h" namespace sensor_console { - const uint8_t MAX_COMMANDS = 25; + const uint8_t MAX_COMMANDS = 26; const uint8_t MAX_COMMAND_SIZE = 20; // Should be enough for "set_time 1618829570\n" uint8_t commands_count = 0; diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index 852f1293d5ff58ce16424300631a6ea4bc5a4ae7..e3066c0831b24e9475b20ef648ba629331333e4f 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -164,10 +164,7 @@ namespace web_config { iotWebConf->setWifiConnectionFailedHandler(fail_and_return_null); } - void initialize() { - iotWebConf = new IotWebConf(strlen(AMPEL_NAME) == 0 ? ampel.sensorId : AMPEL_NAME, &dnsServer, &http, "", - config_version); - + void defineStructure() { iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider); iotWebConf->addSystemParameter(&elWifiParam); @@ -219,10 +216,9 @@ namespace web_config { #if defined(ESP32) iotWebConf->addParameterGroup(&loraParams); #endif + } - //TODO: Add "ap" command? - //TODO: Add "wifi_ssid" command? - //TODO: Add "wifi_password" command? + void defineCommands() { sensor_console::defineCommand("save_config", config::save, F("(Saves the config to EEPROM)")); sensor_console::defineCommand("reset_config", []() { @@ -232,12 +228,35 @@ namespace web_config { 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); + strncpy(iotWebConf->getWifiSsidParameter()->valueBuffer, ssid, iotWebConf->getWifiSsidParameter()->getLength()); + iotWebConf->saveConfig(); + }, F(" name (Sets SSID to name)")); + + sensor_console::defineStringCommand("pwd", [](char *ssid) { + Serial.print(F("Setting WiFi password to ")); + Serial.println(ssid); + strncpy(iotWebConf->getWifiPasswordParameter()->valueBuffer, ssid, iotWebConf->getWifiPasswordParameter()->getLength()); + iotWebConf->saveConfig(); + }, F(" abc (Sets WiFi password to abc)")); + sensor_console::defineIntCommand("wifi", [](int32_t onOff) { config::is_wifi_on = onOff; iotWebConf->saveConfig(); Serial.print(F("WiFi - ")); Serial.println(onOff ? F("On!") : F("Off!")); }, F("0/1 (Turns Wifi on/off)")); + } + + void initialize() { + iotWebConf = new IotWebConf(strlen(AMPEL_NAME) == 0 ? ampel.sensorId : AMPEL_NAME, &dnsServer, &http, "", + config_version); + + defineStructure(); + + defineCommands(); iotWebConf->loadConfig(); @@ -246,6 +265,12 @@ namespace web_config { return; } + //NOTE: Can only work if wifi is on. + sensor_console::defineCommand("ap!", []() { + Serial.println(F("Forcing AP mode!")); + iotWebConf->forceApMode(true); + }, F("(Forces access point mode)")); + const int ONBOARD_LED_PIN = 2; # ifdef ESP8266 iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW);