diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h index 71df084c0b62100267725f6365e2f1cfe44ab240..cf0325f388367658469cede1eb3b29874eca83bd 100644 --- a/ampel-firmware/config.public.h +++ b/ampel-firmware/config.public.h @@ -119,7 +119,7 @@ */ // 1) Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE". -// 2) If you really want, region and transceiver type can be specified in lorawan.cpp +// 2) If you need to, region and transceiver type can be specified in lorawan.cpp. Default is "Europe 868" // 3) It has been tested with "TTGO ESP32 SX1276 LoRa 868" and will only work with an ESP32 + LoRa modem // 4) In order to use LoRaWAN, a gateway should be close to the co2ampel, and an account, an application and a device should be registered, // e.g. on https://www.thethingsnetwork.org/docs/applications/ diff --git a/ampel-firmware/lorawan.cpp b/ampel-firmware/lorawan.cpp index c29b312a2752631c731f792bbc021b66e10193a1..7bc1e3d0bc74633a6e685a3d91377d8901e1ed09 100644 --- a/ampel-firmware/lorawan.cpp +++ b/ampel-firmware/lorawan.cpp @@ -20,24 +20,22 @@ #include <hal/hal.h> #include <arduino_lmic_hal_boards.h> -// Check that a Region was defined +namespace config { #if defined(CFG_eu868) -# define LMIC_FREQUENCY_PLAN "Europe 868" + const char *lorawan_frequency_plan = "Europe 868"; #elif defined(CFG_us915) -# define LMIC_FREQUENCY_PLAN "US 915" + const char *lorawan_frequency_plan = "US 915"; #elif defined(CFG_au915) -# define LMIC_FREQUENCY_PLAN "Australia 915" + const char *lorawan_frequency_plan = "Australia 915"; #elif defined(CFG_as923) -# define LMIC_FREQUENCY_PLAN "Asia 923" + const char *lorawan_frequency_plan = "Asia 923"; #elif defined(CFG_kr920) -# define LMIC_FREQUENCY_PLAN "Korea 920" + const char *lorawan_frequency_plan = "Korea 920"; #elif defined(CFG_in866) -# define LMIC_FREQUENCY_PLAN "India 866" + const char *lorawan_frequency_plan = "India 866"; #else # error "Region should be specified" #endif - -namespace config { // Values should be defined in config.h uint16_t lorawan_sending_interval = LORAWAN_SENDING_INTERVAL; // [s] @@ -72,7 +70,9 @@ namespace lorawan { char last_transmission[23] = ""; void initialize() { - Serial.println(F("Starting LoRaWAN. Frequency plan : " LMIC_FREQUENCY_PLAN " MHz.")); + Serial.print(F("Starting LoRaWAN. Frequency plan : ")); + Serial.print(config::lorawan_frequency_plan); + Serial.println(F(" MHz.")); // More info about pin mapping : https://github.com/mcci-catena/arduino-lmic#pin-mapping // Has been tested successfully with ESP32 TTGO LoRa32 V1, and might work with other ESP32+LoRa boards. @@ -87,7 +87,7 @@ namespace lorawan { } // Checks if OTAA is connected, or if payload should be sent. - // NOTE: while a transaction is in process (i.e. until the TXcomplete event has been received, no blocking code (e.g. delay loops etc.) are allowed, otherwise the LMIC/OS code might miss the event. + // NOTE: while a transaction is in process (i.e. until the TXcomplete event has been received), no blocking code (e.g. delay loops etc.) are allowed, otherwise the LMIC/OS code might miss the event. // If this rule is not followed, a typical symptom is that the first send is ok and all following ones end with the 'TX not complete' failure. void process() { os_runloop_once(); diff --git a/ampel-firmware/lorawan.h b/ampel-firmware/lorawan.h index 290368325abb6154bb21a90c4098917c42833059..ed005f5c3a09e38591009e487b97a6a74e2d2b28 100644 --- a/ampel-firmware/lorawan.h +++ b/ampel-firmware/lorawan.h @@ -9,6 +9,7 @@ namespace config { extern uint16_t lorawan_sending_interval; // [s] + extern const char *lorawan_frequency_plan; // e.g. "Europe 868" } namespace lorawan { diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 75897bc253172c7459be4f1a1a557ff132c73c55..bad5faf787d9b11fe6589644adba1a41eacf3d13 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -236,7 +236,7 @@ namespace web_server { mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval, #endif #if defined(AMPEL_LORAWAN) && defined(ESP32) - lorawan::connected ? "Yes" : "No", LMIC_FREQUENCY_PLAN, lorawan::last_transmission, + lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval, #endif config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId,