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

Typed parameters are so much better

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