diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 5b890bd51a432e5ecc6e7ca7ef547201883bc31a..56650e3f176c7e96c7013cf7c7b6689e29ec60df 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -25,6 +25,7 @@ #endif #include <IotWebConf.h> #include <IotWebConfUsing.h> // This loads aliases for easier class names. +#include <IotWebConfTParameter.h> namespace config { // Values should be defined in config.h @@ -65,34 +66,30 @@ namespace web_server { IotWebConf *iotWebConf; -#define STRING_LEN 128 -#define NUMBER_LEN 32 +#define STRING_LEN 64 // -- Configuration specific key. The value should be modified if config structure was changed. - const char config_version[] = "ampel_test_v1"; - - char stringParamValue[STRING_LEN]; - char intParamValue[NUMBER_LEN]; - char floatParamValue[NUMBER_LEN]; - char checkboxParamValue[STRING_LEN]; - char chooserParamValue[STRING_LEN]; - - static char chooserValues[][STRING_LEN] = { "red", "blue", "darkYellow" }; - static char chooserNames[][STRING_LEN] = { "Red", "Blue", "Dark yellow" }; - - IotWebConfTextParameter stringParam = IotWebConfTextParameter("String param", "stringParam", stringParamValue, - STRING_LEN); - IotWebConfParameterGroup group1 = IotWebConfParameterGroup("group1", ""); - IotWebConfNumberParameter intParam = IotWebConfNumberParameter("Int param", "intParam", intParamValue, NUMBER_LEN, - "20", "1..100", "min='1' max='100' step='1'"); + 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( + 100).step(1).placeholder("1..100").build(); // -- We can add a legend to the separator - IotWebConfParameterGroup group2 = IotWebConfParameterGroup("c_factor", "Calibration factor"); - IotWebConfNumberParameter floatParam = IotWebConfNumberParameter("Float param", "floatParam", floatParamValue, - NUMBER_LEN, NULL, "e.g. 23.4", "step='0.1'"); - IotWebConfCheckboxParameter checkboxParam = IotWebConfCheckboxParameter("Check param", "checkParam", - checkboxParamValue, STRING_LEN, true); - IotWebConfSelectParameter chooserParam = IotWebConfSelectParameter("Choose param", "chooseParam", chooserParamValue, - STRING_LEN, (char*) chooserValues, (char*) chooserNames, sizeof(chooserValues) / STRING_LEN, STRING_LEN); + iotwebconf::ParameterGroup group2 = iotwebconf::ParameterGroup("c_factor", "Calibration factor"); + iotwebconf::FloatTParameter floatParam = iotwebconf::Builder<iotwebconf::FloatTParameter>("floatParam").label( + "Float param").defaultValue(0.0).step(0.1).placeholder("e.g. 23.4").build(); + iotwebconf::CheckboxTParameter checkboxParam = + iotwebconf::Builder<iotwebconf::CheckboxTParameter>("checkParam").label("Check param").defaultValue(true).build(); + iotwebconf::SelectTParameter<STRING_LEN> chooserParam = + iotwebconf::Builder<iotwebconf::SelectTParameter< STRING_LEN>>("chooseParam").label("Choose param").optionValues( + (const char*) chooserValues).optionNames((const char*) chooserNames).optionCount( + sizeof(chooserValues) / STRING_LEN).nameLength(STRING_LEN).build(); void update() { iotWebConf->doLoop(); // Listen for HTTP requests from clients @@ -170,10 +167,16 @@ namespace web_server { //TODO: Save LoRaWAN key if possible? //FIXME: Why does MQTT fail? (on ESP32) - Serial.println(intParamValue); // iotWebConf->loadConfig(); + Serial.println("<<<<<<<<<<<<<<<"); + Serial.println(stringParam.value()); + Serial.println(intParam.value()); + Serial.println(floatParam.value()); iotWebConf->init(); - Serial.println(intParamValue); + Serial.println(stringParam.value()); + Serial.println(intParam.value()); + Serial.println(floatParam.value()); + Serial.println(">>>>>>>>>>>>>>>"); sensor_console::defineCommand("reset_config", []() { Serial.println(F("Resetting config..."));