diff --git a/ampel-firmware/ampel-firmware.h b/ampel-firmware/ampel-firmware.h index f48f603fdf1b631d89627e0a130265ef261efa46..5f50b5138af1e0495e971db2141f8ce034d6289b 100644 --- a/ampel-firmware/ampel-firmware.h +++ b/ampel-firmware/ampel-firmware.h @@ -3,12 +3,10 @@ /***************************************************************** * Libraries * *****************************************************************/ -#include "config.h" -#ifndef MEASUREMENT_TIMESTEP -# error Missing config.h file. Please copy config.public.h to config.h. -#endif +//NOTE: Too many headers. Move them to include/ folder? // Needed for offline config too. +#include "config.h" //TODO: Replace with just web_config #include "web_config.h" #include "csv_writer.h" diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index d1f0c3b5cc300cbc32228ff06c8124155bf074c0..a9db9aeb35e0542959f480f32bcebc73b8d5cfc1 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -67,7 +67,7 @@ void setup() { web_config::initialize(); -#ifdef AMPEL_WIFI +#ifdef AMPEL_WIFI // TODO: What to do with those? Replace with webconf::wifi_active? web_config::setWifiConnectionCallback([]() { //TODO: Move somewhere else led_effects::showKITTWheel(color::green); @@ -113,7 +113,7 @@ void setup() { csv_writer::initialize(ampel.sensorId); -#ifdef AMPEL_WIFI // Structure doesn't make sense anymore +#ifdef AMPEL_WIFI wifi::defineCommands(); # ifdef AMPEL_HTTP web_server::definePages(); diff --git a/ampel-firmware/lorawan.cpp b/ampel-firmware/lorawan.cpp index c8034c13ba9249fbf4cb4532dca35d7bd212c74f..4b53d5af96b542dbf72de60fe7f85ec63389f403 100644 --- a/ampel-firmware/lorawan.cpp +++ b/ampel-firmware/lorawan.cpp @@ -2,6 +2,7 @@ #if defined(ESP32) +#include "config.h" //TODO: Replace with just web_config #include "led_effects.h" #include "sensor_console.h" #include "util.h" diff --git a/ampel-firmware/lorawan.h b/ampel-firmware/lorawan.h index a30e54fbc26ee345d2f44dd1389a107e9125722f..3c9443af0fb9ddd95e0d85c22cedb661e3ddc8e4 100644 --- a/ampel-firmware/lorawan.h +++ b/ampel-firmware/lorawan.h @@ -1,8 +1,6 @@ #ifndef AMPEL_LORAWAN_H_ #define AMPEL_LORAWAN_H_ -#include "config.h" - # if defined(ESP32) #include <stdint.h> // For uint32_t & uint16_t diff --git a/ampel-firmware/mqtt.cpp b/ampel-firmware/mqtt.cpp index c01c08512c2a8e090eaee607464877869a429557..cbe98daf62be728edfde7c97e76612bb9474d5a1 100644 --- a/ampel-firmware/mqtt.cpp +++ b/ampel-firmware/mqtt.cpp @@ -1,7 +1,6 @@ #include "mqtt.h" #include "web_config.h" -#include "config.h" #include "led_effects.h" #include "sensor_console.h" #include "wifi_util.h" @@ -121,7 +120,7 @@ namespace mqtt { Serial.print(F("User:'")); Serial.print(config::mqtt_user); Serial.print(F("' Password:'")); - for (int i = 0; i < strlen(config::mqtt_password); ++i) { + for (size_t i = 0; i < strlen(config::mqtt_password); ++i) { Serial.print("*"); } Serial.print(F("' ...")); @@ -201,7 +200,7 @@ namespace mqtt { char payload[75]; // Should be enough for info json... const char *json_info_format = PSTR("{\"local_ip\":\"%s\", \"ssid\":\"%s\"}"); - snprintf(payload, sizeof(payload), json_info_format, wifi::local_ip, WIFI_SSID); + snprintf(payload, sizeof(payload), json_info_format, wifi::local_ip, config::current_ssid()); mqttClient.publish(info_topic, payload); } diff --git a/ampel-firmware/mqtt.h b/ampel-firmware/mqtt.h index 7cc77b0bf0c2b524837f3eaa195ae2e62030249a..d9ee39efcdbe649f4ef2e3311a5e40317bbc1978 100644 --- a/ampel-firmware/mqtt.h +++ b/ampel-firmware/mqtt.h @@ -3,8 +3,6 @@ #include <stdint.h> // For uint32_t & uint16_t -#include "config.h" - namespace mqtt { extern char last_successful_publish[]; extern bool connected; diff --git a/ampel-firmware/util.h b/ampel-firmware/util.h index 7709595ef0fbeff08e0808e60264af8c22e08f8f..a7225edf778f2edefd4c46b52f37f3424fb0b601 100644 --- a/ampel-firmware/util.h +++ b/ampel-firmware/util.h @@ -26,7 +26,7 @@ class Ampel { private: static void showFreeSpace(); public: - const char *version = "v0.2.3-DEV"; // Update manually after significant changes. + const char *version = "webconf-DEV"; // Update manually after significant changes. const char *board; const char *sensorId; const char *macAddress; diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index 5dc1079975f7375e9c36447fb91b5d7a83559bd3..e0c129713ec21e00a184d6bf725193893901fe49 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -7,6 +7,10 @@ #endif #include "config.h" +#ifndef MEASUREMENT_TIMESTEP +# error Missing config.h file. Please copy config.public.h to config.h. +#endif + #include "util.h" #include "sensor_console.h" @@ -268,6 +272,11 @@ namespace web_config { * Define all the corresponding config values as reference, so that they can be updated. */ namespace config { + + char* current_ssid() { + return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer; + } + // Sensor uint16_t &measurement_timestep = web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor). uint16_t &altitude_above_sea_level = web_config::altitudeParam.value(); // [m] diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index 7a2cf7a16afeb2a7b8518333514e86afd8f6adff..87c66058cdf785e1b4925490da489ef4c34c052a 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -10,6 +10,7 @@ #endif namespace config { + char* current_ssid(); // Sensor extern uint16_t &measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor). extern uint16_t &altitude_above_sea_level; // [m] diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 8249991f4eb8bb84f08299c991eb4bb91e832515..05f2c3ab91ad6468f1ccf84c27605a6019b6140c 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -1,7 +1,7 @@ #include "web_server.h" #include "web_config.h" -#include "config.h" +#include "config.h" // TODO: Remove once HTTP_USER and HTTP_PASSWORD are in web_config #include "util.h" #include "ntp.h" #include "wifi_util.h" @@ -96,16 +96,16 @@ namespace web_server { "<tr><td>Humidity</td><td>%.1f%%</td></tr>\n" "<tr><td>Last measurement</td><td>%s</td></tr>\n" "<tr><td>Measurement timestep</td><td>%5d s</td></tr>\n" - "<tr><th colspan='2'>CSV</th></tr>\n" + "<tr><th colspan='2'>CSV</th></tr>\n" //TODO: Gray out if !config::csv_active "<tr><td>Last write</td><td>%s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n" "<tr><td>Available drive space</td><td>%d kB</td></tr>\n" - "<tr><th colspan='2'>MQTT</th></tr>\n" + "<tr><th colspan='2'>MQTT</th></tr>\n"//TODO: Gray out if !config::mqtt_active "<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Last publish</td><td>%s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n" #if defined(ESP32) - "<tr><th colspan='2'>LoRaWAN</th></tr>\n" + "<tr><th colspan='2'>LoRaWAN</th></tr>\n" //TODO: Gray out if !config::lora_active "<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Frequency</td><td>%s MHz</td></tr>\n" "<tr><td>Last transmission</td><td>%s</td></tr>\n" diff --git a/ampel-firmware/wifi_util.cpp b/ampel-firmware/wifi_util.cpp index 5c19f6531c0dd9e5d0f8b64c0219e91830791f83..852e20806c6764196bffbdddf024eed43d8e11e0 100644 --- a/ampel-firmware/wifi_util.cpp +++ b/ampel-firmware/wifi_util.cpp @@ -1,6 +1,6 @@ #include "wifi_util.h" -#include "config.h" +#include "web_config.h" #include "util.h" #include "ntp.h" #include "led_effects.h" @@ -12,18 +12,6 @@ # include <WiFi.h> #endif -namespace config { - // WiFi config. See 'config.h' if you want to modify those values. - const char *wifi_ssid = WIFI_SSID; - const char *wifi_password = WIFI_PASSWORD; - -#ifdef WIFI_TIMEOUT - const uint8_t wifi_timeout = WIFI_TIMEOUT; // [s] Will try to connect during wifi_timeout seconds before failing. -#else - const uint8_t wifi_timeout = 60; // [s] Will try to connect during wifi_timeout seconds before failing. -#endif -} - namespace wifi { char local_ip[16]; // "255.255.255.255\0" @@ -53,9 +41,9 @@ namespace wifi { Serial.print(F("WiFi - Local IP : ")); Serial.println(wifi::local_ip); Serial.print(F("WiFi - SSID : ")); - Serial.println(WIFI_SSID); + Serial.println(config::current_ssid()); } - + void defineCommands() { sensor_console::defineCommand("wifi_scan", scanNetworks, F("(Scans available WiFi networks)")); sensor_console::defineCommand("local_ip", showLocalIp, F("(Displays local IP and current SSID)"));