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() {
sensor::initialize();
Serial.print("JUST A CONFIG TEST : ");
Serial.println(config::stringParam.value());
#ifdef AMPEL_CSV
csv_writer::initialize(ampel.sensorId);
#endif
......
......@@ -7,6 +7,8 @@ namespace config {
//TODO: Is there any conflict with SPIFFS/LittleFS?
//TODO: Actually use those parameters
//TODO: Check memory consumption. Disable DEBUG info?
//TODO: Convert all strings to F-strings
namespace web_config {
#if defined(ESP8266)
......@@ -20,23 +22,15 @@ namespace web_config {
IotWebConf *iotWebConf;
// -- 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
*/
iotwebconf::ParameterGroup serviceParams = iotwebconf::ParameterGroup("Services", "Services");
iotwebconf::CheckboxTParameter ampelWifiParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("WiFi").label(
"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?
/**
......@@ -66,7 +60,7 @@ namespace web_config {
/**
* 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>>(
"csv_timestep").label("CSV timestep").defaultValue(CSV_INTERVAL).min(0).step(1).build();
......@@ -74,7 +68,7 @@ namespace web_config {
/**
* 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>>(
"mqtt_timestep").label("MQTT timestep").defaultValue(
......@@ -101,6 +95,14 @@ namespace web_config {
* 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
*/
......@@ -108,6 +110,12 @@ namespace web_config {
/**
* 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() {
iotWebConf->doLoop(); // Listen for HTTP requests from clients
......@@ -127,10 +135,9 @@ namespace web_config {
void initialize() {
iotWebConf = new IotWebConf(ampel.sensorId, &dnsServer, &http, HTTP_PASSWORD, config_version);
serviceParams.addItem(&ampelWifiParam);
serviceParams.addItem(&ampelMQTTParam);
serviceParams.addItem(&ampelCSVParam);
serviceParams.addItem(&ampelLoRaWANParam);
iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider);
iotWebConf->addSystemParameter(&ampelWifiParam);
co2Params.addItem(&timestepParam);
co2Params.addItem(&temperatureOffsetParam);
......@@ -138,6 +145,10 @@ namespace web_config {
co2Params.addItem(&atmosphericCO2Param);
co2Params.addItem(&autoCalibrateParam);
timeParams.addItem(&ntpParam);
timeParams.addItem(&timeOffsetParam);
timeParams.addItem(&dstParam);
csvParams.addItem(&csvTimestepParam);
mqttParams.addItem(&mqttTimestepParam);
......@@ -147,10 +158,13 @@ namespace web_config {
mqttParams.addItem(&mqttUserParam);
mqttParams.addItem(&mqttPasswordParam);
iotWebConf->addParameterGroup(&serviceParams);
loraParams.addItem(&loraTimestepParam);
iotWebConf->addParameterGroup(&co2Params);
iotWebConf->addParameterGroup(&timeParams);
iotWebConf->addParameterGroup(&csvParams);
iotWebConf->addParameterGroup(&mqttParams);
iotWebConf->addParameterGroup(&loraParams);
sensor_console::defineCommand("reset_config", []() {
Serial.println(F("Resetting config..."));
......
......@@ -11,8 +11,11 @@
#include "config.h"
#define IOTWEBCONF_DEBUG_DISABLED // Did it change anything?
#include <IotWebConf.h>
#include <IotWebConfTParameter.h>
#include <IotWebConfOptionalGroup.h>
#include "util.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