Commit 01ad5633 authored by Eric Duminil's avatar Eric Duminil
Browse files

Fixing lorawan config and refactor

parent 8e15be18
Pipeline #5739 canceled with stage
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
*/ */
// 1) Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE". // 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 // 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, // 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/ // e.g. on https://www.thethingsnetwork.org/docs/applications/
......
...@@ -20,24 +20,22 @@ ...@@ -20,24 +20,22 @@
#include <hal/hal.h> #include <hal/hal.h>
#include <arduino_lmic_hal_boards.h> #include <arduino_lmic_hal_boards.h>
// Check that a Region was defined namespace config {
#if defined(CFG_eu868) #if defined(CFG_eu868)
# define LMIC_FREQUENCY_PLAN "Europe 868" const char *lorawan_frequency_plan = "Europe 868";
#elif defined(CFG_us915) #elif defined(CFG_us915)
# define LMIC_FREQUENCY_PLAN "US 915" const char *lorawan_frequency_plan = "US 915";
#elif defined(CFG_au915) #elif defined(CFG_au915)
# define LMIC_FREQUENCY_PLAN "Australia 915" const char *lorawan_frequency_plan = "Australia 915";
#elif defined(CFG_as923) #elif defined(CFG_as923)
# define LMIC_FREQUENCY_PLAN "Asia 923" const char *lorawan_frequency_plan = "Asia 923";
#elif defined(CFG_kr920) #elif defined(CFG_kr920)
# define LMIC_FREQUENCY_PLAN "Korea 920" const char *lorawan_frequency_plan = "Korea 920";
#elif defined(CFG_in866) #elif defined(CFG_in866)
# define LMIC_FREQUENCY_PLAN "India 866" const char *lorawan_frequency_plan = "India 866";
#else #else
# error "Region should be specified" # error "Region should be specified"
#endif #endif
namespace config {
// Values should be defined in config.h // Values should be defined in config.h
uint16_t lorawan_sending_interval = LORAWAN_SENDING_INTERVAL; // [s] uint16_t lorawan_sending_interval = LORAWAN_SENDING_INTERVAL; // [s]
...@@ -72,7 +70,9 @@ namespace lorawan { ...@@ -72,7 +70,9 @@ namespace lorawan {
char last_transmission[23] = ""; char last_transmission[23] = "";
void initialize() { 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 // 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. // Has been tested successfully with ESP32 TTGO LoRa32 V1, and might work with other ESP32+LoRa boards.
...@@ -87,7 +87,7 @@ namespace lorawan { ...@@ -87,7 +87,7 @@ namespace lorawan {
} }
// Checks if OTAA is connected, or if payload should be sent. // 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. // 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() { void process() {
os_runloop_once(); os_runloop_once();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace config { namespace config {
extern uint16_t lorawan_sending_interval; // [s] extern uint16_t lorawan_sending_interval; // [s]
extern const char *lorawan_frequency_plan; // e.g. "Europe 868"
} }
namespace lorawan { namespace lorawan {
......
...@@ -236,7 +236,7 @@ namespace web_server { ...@@ -236,7 +236,7 @@ namespace web_server {
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval, mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval,
#endif #endif
#if defined(AMPEL_LORAWAN) && defined(ESP32) #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, config::lorawan_sending_interval,
#endif #endif
config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId, config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId,
......
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