diff --git a/ampel-firmware/ampel-firmware.h b/ampel-firmware/ampel-firmware.h index 177cd9909498cf91e5d2f20564785ea3a4a8215b..f48f603fdf1b631d89627e0a130265ef261efa46 100644 --- a/ampel-firmware/ampel-firmware.h +++ b/ampel-firmware/ampel-firmware.h @@ -21,9 +21,7 @@ # endif #endif -#ifdef AMPEL_LORAWAN -# include "lorawan.h" -#endif +#include "lorawan.h" #include "util.h" #include "ntp.h" diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index bc0e3c2ef7cef07876b4fcddc650146b2a6d33aa..d1f0c3b5cc300cbc32228ff06c8124155bf074c0 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -122,8 +122,10 @@ void setup() { # endif #endif -#if defined(AMPEL_LORAWAN) && defined(ESP32) - lorawan::initialize(); +#if defined(ESP32) + if (config::lorawan_active()) { + lorawan::initialize(); + } #endif } @@ -138,13 +140,15 @@ void checkSerialInput(); * Main loop * *****************************************************************/ void loop() { -#if defined(AMPEL_LORAWAN) && defined(ESP32) - //LMIC Library seems to be very sensitive to timing issues, so run it first. - lorawan::process(); - - if (lorawan::waiting_for_confirmation) { - // If node is waiting for join confirmation from Gateway, nothing else should run. - return; +#if defined(ESP32) + if (config::lorawan_active()) { + //LMIC Library seems to be very sensitive to timing issues, so run it first. + lorawan::process(); + + if (lorawan::waiting_for_confirmation) { + // If node is waiting for join confirmation from Gateway, nothing else should run. + return; + } } #endif //NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed. @@ -170,8 +174,10 @@ void loop() { } #endif -#if defined(AMPEL_LORAWAN) && defined(ESP32) - lorawan::preparePayloadIfTimeHasCome(sensor::co2, sensor::temperature, sensor::humidity); +#if defined(ESP32) + if (config::lorawan_active()) { + lorawan::preparePayloadIfTimeHasCome(sensor::co2, sensor::temperature, sensor::humidity); + } #endif } diff --git a/ampel-firmware/lorawan.cpp b/ampel-firmware/lorawan.cpp index 5dfad5e5c1fadb1df3018bc142e438ef7a55a9a9..c8034c13ba9249fbf4cb4532dca35d7bd212c74f 100644 --- a/ampel-firmware/lorawan.cpp +++ b/ampel-firmware/lorawan.cpp @@ -1,6 +1,6 @@ #include "lorawan.h" -#if defined(AMPEL_LORAWAN) && defined(ESP32) +#if defined(ESP32) #include "led_effects.h" #include "sensor_console.h" diff --git a/ampel-firmware/lorawan.h b/ampel-firmware/lorawan.h index ed005f5c3a09e38591009e487b97a6a74e2d2b28..a30e54fbc26ee345d2f44dd1389a107e9125722f 100644 --- a/ampel-firmware/lorawan.h +++ b/ampel-firmware/lorawan.h @@ -3,7 +3,7 @@ #include "config.h" -# if defined(AMPEL_LORAWAN) && defined(ESP32) +# if defined(ESP32) #include <stdint.h> // For uint32_t & uint16_t diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index 9a02186d697f324e99de2b78fdee7e6a6abf88aa..5dc1079975f7375e9c36447fb91b5d7a83559bd3 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -67,6 +67,7 @@ namespace web_config { /** * LED */ + //NOTE: Could also be optional : for LED 0 / 1 ParameterGroup ledParams = ParameterGroup("LED", "LED"); IntTParameter<uint8_t> maxBrightnessParam = @@ -81,10 +82,6 @@ namespace web_config { // # define HTTP_USER "co2ampel" // # define HTTP_PASSWORD "my_password" -// WARNING: If AMPEL_LORAWAN is enabled, you need to modify the 3 following constants! -// This EUI must be in little-endian format, so least-significant-byte first. -// When copying an EUI from ttnctl output, this means to reverse the bytes. - /** * CSV */ @@ -134,13 +131,10 @@ namespace web_config { CheckboxTParameter dstParam = Builder<CheckboxTParameter>("dst").label("Daylight Saving Time?").defaultValue(false).build(); - /** - * LED - */ - /** * LoRa & Stuff */ +#if defined(ESP32) OptionalParameterGroup loraParams = OptionalParameterGroup("LoRaWan", "LoRaWan", AMPEL_LORAWAN); IntTParameter<uint16_t> loraTimestepParam = Builder<IntTParameter<uint16_t>>("lora_timestep").label("LoRa timestep").defaultValue( @@ -152,6 +146,7 @@ namespace web_config { Builder<TextTParameter<17>>("app_eui").label("App EUI").defaultValue("00EA07...").build(); TextTParameter<32> appKeyParam = Builder<TextTParameter<32>>("app_key").label("App key").defaultValue("81CCFE...").build(); +#endif OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider; @@ -202,18 +197,21 @@ namespace web_config { mqttParams.addItem(&mqttEncryptionParam); mqttParams.addItem(&mqttCommandsParam); - //TODO: Only for ESP32 +#if defined(ESP32) loraParams.addItem(&loraTimestepParam); loraParams.addItem(&deviceEUIParam); loraParams.addItem(&appEUIParam); loraParams.addItem(&appKeyParam); +#endif iotWebConf->addParameterGroup(&co2Params); iotWebConf->addParameterGroup(&ledParams); iotWebConf->addParameterGroup(&timeParams); iotWebConf->addParameterGroup(&csvParams); iotWebConf->addParameterGroup(&mqttParams); +#if defined(ESP32) iotWebConf->addParameterGroup(&loraParams); +#endif sensor_console::defineCommand("reset_config", []() { Serial.println(F("Resetting config...")); @@ -304,4 +302,11 @@ namespace config { uint16_t &mqtt_sending_interval = web_config::mqttTimestepParam.value(); bool &mqtt_encryption = web_config::mqttEncryptionParam.value(); bool &allow_mqtt_commands = web_config::mqttCommandsParam.value(); + + // LORAWAN +#if defined(ESP32) + bool lorawan_active() { + return web_config::loraParams.isActive(); + } +#endif } diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index 5e67ebe98384506b6d4dc9471cc570e8fb9b8e40..7a2cf7a16afeb2a7b8518333514e86afd8f6adff 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -40,6 +40,11 @@ namespace config { extern uint16_t &mqtt_sending_interval; // [s] extern bool &mqtt_encryption; // [true / false] extern bool &allow_mqtt_commands; // [true / false] + + // LORAWAN +#if defined(ESP32) + bool lorawan_active(); // also defined for ESP8266, and set to false +#endif } namespace web_config { diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 37ed6e7d075282b03046d2070236027cc16dc52c..8249991f4eb8bb84f08299c991eb4bb91e832515 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -9,9 +9,7 @@ #include "sensor_console.h" #include "csv_writer.h" #include "mqtt.h" -#ifdef AMPEL_LORAWAN -# include "lorawan.h" -#endif +#include "lorawan.h" #include <IotWebConf.h> #include <IotWebConfUsing.h> // This loads aliases for easier class names. @@ -106,7 +104,7 @@ namespace web_server { "<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(AMPEL_LORAWAN) && defined(ESP32) +#if defined(ESP32) "<tr><th colspan='2'>LoRaWAN</th></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Frequency</td><td>%s MHz</td></tr>\n" @@ -227,7 +225,7 @@ namespace web_server { sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write, config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval, -#if defined(AMPEL_LORAWAN) && defined(ESP32) +#if defined(ESP32) lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval, #endif