Commit 63f78eea authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying to use a config

parent 56f99df8
...@@ -112,6 +112,9 @@ void setup() { ...@@ -112,6 +112,9 @@ void setup() {
sensor::initialize(); sensor::initialize();
Serial.print("JUST A CONFIG TEST : ");
Serial.println(config::stringParam.value());
#ifdef AMPEL_CSV #ifdef AMPEL_CSV
csv_writer::initialize(ampel.sensorId); csv_writer::initialize(ampel.sensorId);
#endif #endif
......
#include "web_config.h" #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 { namespace web_config {
#if defined(ESP8266) #if defined(ESP8266)
ESP8266WebServer http(80); // Create a webserver object that listens for HTTP request on port 80 ESP8266WebServer http(80); // Create a webserver object that listens for HTTP request on port 80
...@@ -11,16 +16,12 @@ namespace web_config { ...@@ -11,16 +16,12 @@ namespace web_config {
IotWebConf *iotWebConf; IotWebConf *iotWebConf;
#define STRING_LEN 64
// -- 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_v3"; const char config_version[] = "ampel_test_v3";
static const char chooserValues[][STRING_LEN] = { "red", "blue", "darkYellow" }; static const char chooserValues[][STRING_LEN] = { "red", "blue", "darkYellow" };
static const char chooserNames[][STRING_LEN] = { "Red", "Blue", "Dark yellow" }; 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::ParameterGroup group1 = iotwebconf::ParameterGroup("group1", "");
iotwebconf::IntTParameter<int16_t> intParam = iotwebconf::IntTParameter<int16_t> intParam =
iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("intParam").label("Int param").defaultValue(30).min(1).max( iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("intParam").label("Int param").defaultValue(30).min(1).max(
...@@ -54,6 +55,27 @@ namespace web_config { ...@@ -54,6 +55,27 @@ namespace web_config {
void initialize() { void initialize() {
iotWebConf = new IotWebConf(ampel.sensorId, &dnsServer, &http, HTTP_PASSWORD, config_version); 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; const int ONBOARD_LED_PIN = 2;
# ifdef ESP8266 # ifdef ESP8266
iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW); iotWebConf->setStatusPin(ONBOARD_LED_PIN, LOW);
...@@ -63,20 +85,11 @@ namespace web_config { ...@@ -63,20 +85,11 @@ namespace web_config {
iotWebConf->setWifiConnectionTimeoutMs(1000UL * WIFI_TIMEOUT); iotWebConf->setWifiConnectionTimeoutMs(1000UL * WIFI_TIMEOUT);
#if defined(ESP8266) #if defined(ESP8266)
WiFi.hostname(ampel.sensorId); WiFi.hostname(ampel.sensorId);
#elif defined(ESP32) #elif defined(ESP32)
WiFi.setHostname(ampel.sensorId); WiFi.setHostname(ampel.sensorId);
#endif #endif
group1.addItem(&intParam);
group2.addItem(&floatParam);
group2.addItem(&checkboxParam);
group2.addItem(&chooserParam);
iotWebConf->addSystemParameter(&stringParam);
iotWebConf->addParameterGroup(&group1);
iotWebConf->addParameterGroup(&group2);
iotWebConf->skipApStartup(); iotWebConf->skipApStartup();
//TODO: Add callbacks //TODO: Add callbacks
//TODO: Add LED effects //TODO: Add LED effects
...@@ -89,23 +102,7 @@ namespace web_config { ...@@ -89,23 +102,7 @@ namespace web_config {
//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)
// iotWebConf->loadConfig();
Serial.println("<<<<<<<<<<<<<<<");
Serial.println(stringParam.value());
Serial.println(intParam.value());
Serial.println(floatParam.value());
iotWebConf->init(); 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: Authenticate only if required?
//TODO: / captive fast return? //TODO: / captive fast return?
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
# include <WebServer.h> # include <WebServer.h>
#endif #endif
#define STRING_LEN 64
//#include "config.h" //#include "config.h"
#include <IotWebConf.h> #include <IotWebConf.h>
...@@ -15,6 +17,10 @@ ...@@ -15,6 +17,10 @@
#include "util.h" #include "util.h"
//#include "sensor_console.h" //#include "sensor_console.h"
namespace config {
extern iotwebconf::TextTParameter<STRING_LEN> stringParam;
}
namespace web_config { namespace web_config {
void initialize(); void initialize();
void setWifiConnectionCallback(void (*function)()); void setWifiConnectionCallback(void (*function)());
......
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