diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h index 2c9047e2e047bf4c40330d5684569c197de11da7..71df084c0b62100267725f6365e2f1cfe44ab240 100644 --- a/ampel-firmware/config.public.h +++ b/ampel-firmware/config.public.h @@ -119,10 +119,7 @@ */ // 1) Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE". -// 2) Region and transceiver type should be specified in: -// * Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/lmic_project_config.h for Arduino IDE -// * platformio.ini for PlatformIO -// See https://github.com/mcci-catena/arduino-lmic#configuration for more information +// 2) If you really want, region and transceiver type can be specified in lorawan.cpp // 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 5cb9593accbf5c84c3f3f30af249ccb6d6583978..c29b312a2752631c731f792bbc021b66e10193a1 100644 --- a/ampel-firmware/lorawan.cpp +++ b/ampel-firmware/lorawan.cpp @@ -6,10 +6,37 @@ #include "sensor_console.h" #include "util.h" +/*** Define region and transceiver type, and ignore the library lmic_project_config.h ***/ +// Those values are probably okay if you're in Europe. +#define ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS +#define CFG_eu868 1 +#define CFG_sx1276_radio 1 +/****************************************************************************************/ + +// Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE" +// Tested successfully with v3.2.0 and connected to a thethingsnetwork.org app. +#include <lmic.h> #include <SPI.h> #include <hal/hal.h> #include <arduino_lmic_hal_boards.h> +// Check that a Region was defined +#if defined(CFG_eu868) +# define LMIC_FREQUENCY_PLAN "Europe 868" +#elif defined(CFG_us915) +# define LMIC_FREQUENCY_PLAN "US 915" +#elif defined(CFG_au915) +# define LMIC_FREQUENCY_PLAN "Australia 915" +#elif defined(CFG_as923) +# define LMIC_FREQUENCY_PLAN "Asia 923" +#elif defined(CFG_kr920) +# define LMIC_FREQUENCY_PLAN "Korea 920" +#elif defined(CFG_in866) +# define LMIC_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] diff --git a/ampel-firmware/lorawan.h b/ampel-firmware/lorawan.h index d91dacd16f6b47796f76e30fd71431f0cf0df75b..290368325abb6154bb21a90c4098917c42833059 100644 --- a/ampel-firmware/lorawan.h +++ b/ampel-firmware/lorawan.h @@ -3,33 +3,14 @@ #include "config.h" -#if defined(AMPEL_LORAWAN) && defined(ESP32) +# if defined(AMPEL_LORAWAN) && defined(ESP32) #include <stdint.h> // For uint32_t & uint16_t -// Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE". -// Tested successfully with v3.2.0 and connected to a thethingsnetwork.org app. -#include <lmic.h> namespace config { extern uint16_t lorawan_sending_interval; // [s] } -#if defined(CFG_eu868) -# define LMIC_FREQUENCY_PLAN "Europe 868" -#elif defined(CFG_us915) -# define LMIC_FREQUENCY_PLAN "US 915" -#elif defined(CFG_au915) -# define LMIC_FREQUENCY_PLAN "Australia 915" -#elif defined(CFG_as923) -# define LMIC_FREQUENCY_PLAN "Asia 923" -#elif defined(CFG_kr920) -# define LMIC_FREQUENCY_PLAN "Korea 920" -#elif defined(CFG_in866) -# define LMIC_FREQUENCY_PLAN "India 866" -#else -# error "Region should be specified" -#endif - namespace lorawan { extern bool waiting_for_confirmation; extern bool connected; @@ -41,5 +22,5 @@ namespace lorawan { void setLoRaInterval(int32_t sending_interval); } -#endif +# endif #endif diff --git a/platformio.ini b/platformio.ini index becf69fc263e19f956d1cf7a7ff4701dd7322247..3d016a6c7c5d7c0a985c08a37e29b23aa2c3a69c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,8 +24,3 @@ monitor_speed = 115200 lib_deps = MCCI LoRaWAN LMIC library - -build_flags = - -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS - -D CFG_eu868=1 - -D CFG_sx1276_radio=1