diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 370541aad3d5add9063b7695d1ec259ff27b3628..522aa6d88d027917be7325fbaacbd802142811fa 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -112,6 +112,9 @@ void setup() { sensor::initialize(); + Serial.print("JUST A CONFIG TEST : "); + Serial.println(config::stringParam.value()); + #ifdef AMPEL_CSV csv_writer::initialize(ampel.sensorId); #endif diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index 7c844ead22c9ccd672b3ae8d6b0742ade6f21bd0..23735145fea39c748c893e40917891e6a2d7ff8f 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -1,5 +1,10 @@ #include "web_config.h" +namespace config { + iotwebconf::TextTParameter<STRING_LEN> stringParam = iotwebconf::Builder<iotwebconf::TextTParameter< STRING_LEN>>( + "stringParam").label("String param").build(); +} + namespace web_config { #if defined(ESP8266) ESP8266WebServer http(80); // Create a webserver object that listens for HTTP request on port 80 @@ -11,16 +16,12 @@ namespace web_config { IotWebConf *iotWebConf; -#define STRING_LEN 64 - // -- Configuration specific key. The value should be modified if config structure was changed. const char config_version[] = "ampel_test_v3"; static const char chooserValues[][STRING_LEN] = { "red", "blue", "darkYellow" }; static const char chooserNames[][STRING_LEN] = { "Red", "Blue", "Dark yellow" }; - iotwebconf::TextTParameter<STRING_LEN> stringParam = iotwebconf::Builder<iotwebconf::TextTParameter< STRING_LEN>>( - "stringParam").label("String param").build(); iotwebconf::ParameterGroup group1 = iotwebconf::ParameterGroup("group1", ""); iotwebconf::IntTParameter<int16_t> intParam = iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("intParam").label("Int param").defaultValue(30).min(1).max( @@ -54,6 +55,27 @@ namespace web_config { void initialize() { iotWebConf = new IotWebConf(ampel.sensorId, &dnsServer, &http, HTTP_PASSWORD, config_version); + group1.addItem(&intParam); + group2.addItem(&floatParam); + group2.addItem(&checkboxParam); + group2.addItem(&chooserParam); + + iotWebConf->addSystemParameter(&config::stringParam); + iotWebConf->addParameterGroup(&group1); + iotWebConf->addParameterGroup(&group2); + + sensor_console::defineCommand("reset_config", []() { + Serial.println(F("Resetting config...")); + iotWebConf->getSystemParameterGroup()->applyDefaultValue(); + iotWebConf->saveConfig(); + Serial.println(F("Done!")); + }, F("(resets the complete IotWeb config)")); + +#if !defined(AMPEL_WIFI) + iotWebConf->loadConfig(); + return; +#endif + const int ONBOARD_LED_PIN = 2; # ifdef ESP8266 iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW); @@ -63,20 +85,11 @@ namespace web_config { iotWebConf->setWifiConnectionTimeoutMs(1000UL * WIFI_TIMEOUT); #if defined(ESP8266) - WiFi.hostname(ampel.sensorId); + WiFi.hostname(ampel.sensorId); #elif defined(ESP32) WiFi.setHostname(ampel.sensorId); #endif - group1.addItem(&intParam); - group2.addItem(&floatParam); - group2.addItem(&checkboxParam); - group2.addItem(&chooserParam); - - iotWebConf->addSystemParameter(&stringParam); - iotWebConf->addParameterGroup(&group1); - iotWebConf->addParameterGroup(&group2); - iotWebConf->skipApStartup(); //TODO: Add callbacks //TODO: Add LED effects @@ -89,23 +102,7 @@ namespace web_config { //TODO: Save LoRaWAN key if possible? //FIXME: Why does MQTT fail? (on ESP32) -// iotWebConf->loadConfig(); - Serial.println("<<<<<<<<<<<<<<<"); - Serial.println(stringParam.value()); - Serial.println(intParam.value()); - Serial.println(floatParam.value()); iotWebConf->init(); - Serial.println(stringParam.value()); - Serial.println(intParam.value()); - Serial.println(floatParam.value()); - Serial.println(">>>>>>>>>>>>>>>"); - - sensor_console::defineCommand("reset_config", []() { - Serial.println(F("Resetting config...")); - iotWebConf->getSystemParameterGroup()->applyDefaultValue(); - iotWebConf->saveConfig(); - Serial.println(F("Done!")); - }, F("(resets the complete IotWeb config)")); //TODO: Authenticate only if required? //TODO: / captive fast return? diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index 03a56d338a4c59bc3fad717d055e5bf6ed4764f7..91e4077a13b8db8b601c02921ad994a41a0b646a 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -7,6 +7,8 @@ # include <WebServer.h> #endif +#define STRING_LEN 64 + //#include "config.h" #include <IotWebConf.h> @@ -15,6 +17,10 @@ #include "util.h" //#include "sensor_console.h" +namespace config { + extern iotwebconf::TextTParameter<STRING_LEN> stringParam; +} + namespace web_config { void initialize(); void setWifiConnectionCallback(void (*function)());