Commit 62f272ee authored by Eric Duminil's avatar Eric Duminil
Browse files

Optional groups for CSV/MQTT/LoRa

parent 482cb28b
...@@ -114,9 +114,6 @@ void setup() { ...@@ -114,9 +114,6 @@ 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
......
...@@ -7,6 +7,8 @@ namespace config { ...@@ -7,6 +7,8 @@ namespace config {
//TODO: Is there any conflict with SPIFFS/LittleFS? //TODO: Is there any conflict with SPIFFS/LittleFS?
//TODO: Actually use those parameters //TODO: Actually use those parameters
//TODO: Check memory consumption. Disable DEBUG info?
//TODO: Convert all strings to F-strings
namespace web_config { namespace web_config {
#if defined(ESP8266) #if defined(ESP8266)
...@@ -20,23 +22,15 @@ namespace web_config { ...@@ -20,23 +22,15 @@ namespace web_config {
IotWebConf *iotWebConf; IotWebConf *iotWebConf;
// -- 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.
// Also shouldn't be longer than
const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a01"; const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a03";
using namespace iotwebconf;
/** /**
* Services * Services
*/ */
iotwebconf::ParameterGroup serviceParams = iotwebconf::ParameterGroup("Services", "Services");
iotwebconf::CheckboxTParameter ampelWifiParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("WiFi").label( iotwebconf::CheckboxTParameter ampelWifiParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("WiFi").label(
"WiFi").defaultValue(true).build(); "WiFi").defaultValue(true).build();
iotwebconf::CheckboxTParameter ampelCSVParam =
iotwebconf::Builder<iotwebconf::CheckboxTParameter>("CSV").label("CSV").defaultValue(true).build();
iotwebconf::CheckboxTParameter ampelMQTTParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("MQTT").label(
"MQTT").defaultValue(true).build();
iotwebconf::CheckboxTParameter ampelLoRaWANParam =
iotwebconf::Builder<iotwebconf::CheckboxTParameter>("LoRaWAN").label("LoRaWAN").defaultValue(false).build();
//TODO: Distribute to corresponding classes, possibly with callbacks? //TODO: Distribute to corresponding classes, possibly with callbacks?
/** /**
...@@ -66,7 +60,7 @@ namespace web_config { ...@@ -66,7 +60,7 @@ namespace web_config {
/** /**
* CSV * CSV
*/ */
iotwebconf::ParameterGroup csvParams = iotwebconf::ParameterGroup("csvs", "CSV"); iotwebconf::OptionalParameterGroup csvParams = iotwebconf::OptionalParameterGroup("csvs", "CSV", true);
iotwebconf::IntTParameter<uint16_t> csvTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>( iotwebconf::IntTParameter<uint16_t> csvTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>(
"csv_timestep").label("CSV timestep").defaultValue(CSV_INTERVAL).min(0).step(1).build(); "csv_timestep").label("CSV timestep").defaultValue(CSV_INTERVAL).min(0).step(1).build();
...@@ -74,7 +68,7 @@ namespace web_config { ...@@ -74,7 +68,7 @@ namespace web_config {
/** /**
* MQTT * MQTT
*/ */
iotwebconf::ParameterGroup mqttParams = iotwebconf::ParameterGroup("mqtts", "MQTT"); iotwebconf::OptionalParameterGroup mqttParams = iotwebconf::OptionalParameterGroup("mqtts", "MQTT", true);
iotwebconf::IntTParameter<uint16_t> mqttTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>( iotwebconf::IntTParameter<uint16_t> mqttTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>(
"mqtt_timestep").label("MQTT timestep").defaultValue( "mqtt_timestep").label("MQTT timestep").defaultValue(
...@@ -101,6 +95,14 @@ namespace web_config { ...@@ -101,6 +95,14 @@ namespace web_config {
* NTP Time * NTP Time
*/ */
iotwebconf::ParameterGroup timeParams = iotwebconf::ParameterGroup("ntp", "Time server");
iotwebconf::TextTParameter<STRING_LEN> ntpParam = iotwebconf::Builder<iotwebconf::TextTParameter< STRING_LEN>>(
"ntp_server").label("NTP Server").build();
iotwebconf::IntTParameter<int16_t> timeOffsetParam = iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>(
"timezone").label("Timezone").defaultValue((UTC_OFFSET_IN_SECONDS) / 3600).min(-23).max(23).step(1).build();
iotwebconf::CheckboxTParameter dstParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("dst").label(
"Daylight Saving Time").defaultValue(false).build();
/** /**
* LED * LED
*/ */
...@@ -108,6 +110,12 @@ namespace web_config { ...@@ -108,6 +110,12 @@ namespace web_config {
/** /**
* LoRa & Stuff * LoRa & Stuff
*/ */
iotwebconf::OptionalParameterGroup loraParams = iotwebconf::OptionalParameterGroup("LoRaWan", "LoRaWan", false);
iotwebconf::IntTParameter<uint16_t> loraTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>(
"lora_timestep").label("LoRa timestep").defaultValue(
LORAWAN_SENDING_INTERVAL).min(0).step(1).defaultValue(300).build();
iotwebconf::OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider;
void update() { void update() {
iotWebConf->doLoop(); // Listen for HTTP requests from clients iotWebConf->doLoop(); // Listen for HTTP requests from clients
...@@ -127,10 +135,9 @@ namespace web_config { ...@@ -127,10 +135,9 @@ 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);
serviceParams.addItem(&ampelWifiParam); iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider);
serviceParams.addItem(&ampelMQTTParam);
serviceParams.addItem(&ampelCSVParam); iotWebConf->addSystemParameter(&ampelWifiParam);
serviceParams.addItem(&ampelLoRaWANParam);
co2Params.addItem(&timestepParam); co2Params.addItem(&timestepParam);
co2Params.addItem(&temperatureOffsetParam); co2Params.addItem(&temperatureOffsetParam);
...@@ -138,6 +145,10 @@ namespace web_config { ...@@ -138,6 +145,10 @@ namespace web_config {
co2Params.addItem(&atmosphericCO2Param); co2Params.addItem(&atmosphericCO2Param);
co2Params.addItem(&autoCalibrateParam); co2Params.addItem(&autoCalibrateParam);
timeParams.addItem(&ntpParam);
timeParams.addItem(&timeOffsetParam);
timeParams.addItem(&dstParam);
csvParams.addItem(&csvTimestepParam); csvParams.addItem(&csvTimestepParam);
mqttParams.addItem(&mqttTimestepParam); mqttParams.addItem(&mqttTimestepParam);
...@@ -147,10 +158,13 @@ namespace web_config { ...@@ -147,10 +158,13 @@ namespace web_config {
mqttParams.addItem(&mqttUserParam); mqttParams.addItem(&mqttUserParam);
mqttParams.addItem(&mqttPasswordParam); mqttParams.addItem(&mqttPasswordParam);
iotWebConf->addParameterGroup(&serviceParams); loraParams.addItem(&loraTimestepParam);
iotWebConf->addParameterGroup(&co2Params); iotWebConf->addParameterGroup(&co2Params);
iotWebConf->addParameterGroup(&timeParams);
iotWebConf->addParameterGroup(&csvParams); iotWebConf->addParameterGroup(&csvParams);
iotWebConf->addParameterGroup(&mqttParams); iotWebConf->addParameterGroup(&mqttParams);
iotWebConf->addParameterGroup(&loraParams);
sensor_console::defineCommand("reset_config", []() { sensor_console::defineCommand("reset_config", []() {
Serial.println(F("Resetting config...")); Serial.println(F("Resetting config..."));
......
...@@ -11,8 +11,11 @@ ...@@ -11,8 +11,11 @@
#include "config.h" #include "config.h"
#define IOTWEBCONF_DEBUG_DISABLED // Did it change anything?
#include <IotWebConf.h> #include <IotWebConf.h>
#include <IotWebConfTParameter.h> #include <IotWebConfTParameter.h>
#include <IotWebConfOptionalGroup.h>
#include "util.h" #include "util.h"
//#include "sensor_console.h" //#include "sensor_console.h"
......
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