diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h index 501dcedd3e2b423409e49b9a1fdc018a5d2f6c33..4b7432159dfa1ea1e924b29ef3d3551b5106f7f7 100644 --- a/ampel-firmware/config.public.h +++ b/ampel-firmware/config.public.h @@ -133,16 +133,17 @@ // How often should measurements be sent over LoRaWAN? # define LORAWAN_SENDING_INTERVAL 300 // [s] This value should not be too low. See https://www.thethingsnetwork.org/docs/lorawan/duty-cycle.html#maximum-duty-cycle -// WARNING: If AMPEL_LORAWAN is true, 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. -# define LORAWAN_DEVICE_EUI {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11} -// This should also be in little endian format, see above. -# define LORAWAN_APPLICATION_EUI {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from ttnctl can be copied as-is. -# define LORAWAN_APPLICATION_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } +// WARNING: If AMPEL_LORAWAN is true, you need to modify the 3 following constants +// They are written as hexadecimal strings, and will be parsed in the correct order. +// They are written as hexadecimal strings, and will be parsed in the correct order. + +// This EUI must be in big-endian format, so most-significant-byte first. +// You can copy the string from thethings network as-is, without reversing the bytes. +# define LORAWAN_DEVICE_EUI "70B3D57ED004CB17" +// This should also be in big-endian format, and can be copied as is from thethings network. +# define LORAWAN_APPLICATION_EUI "0102030405060708" +// This should also be in big-endian format, and can be copied as is from thethings network. +# define LORAWAN_APPLICATION_KEY "9D06308E20B974919DA6404E063BE01D" /** * NTP diff --git a/ampel-firmware/lorawan.cpp b/ampel-firmware/lorawan.cpp index 243ee413ec59f9e4e7c4b82345ccb56e1bf66912..2d0496e2c4753198e91303c3270e766f66cb3552 100644 --- a/ampel-firmware/lorawan.cpp +++ b/ampel-firmware/lorawan.cpp @@ -3,7 +3,6 @@ #if defined(ESP32) #include "web_config.h" -#include "config.h" //TODO: Replace with just web_config #include "led_effects.h" #include "sensor_console.h" #include "util.h" @@ -32,12 +31,6 @@ namespace config { #else # error "Region should be specified" #endif - // Values should be defined in config.h - uint16_t lorawan_sending_interval = LORAWAN_SENDING_INTERVAL; // [s] - - static const u1_t PROGMEM APPEUI[8] = LORAWAN_APPLICATION_EUI; - static const u1_t PROGMEM DEVEUI[8] = LORAWAN_DEVICE_EUI; - static const u1_t PROGMEM APPKEY[16] = LORAWAN_APPLICATION_KEY; } // Payloads will be automatically sent via MQTT by TheThingsNetwork, and can be seen with: @@ -68,7 +61,15 @@ void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) { Serial.println(n); for (int i = 0; i < n; i++) { - uint8_t r = hexToByte(hex[i * 2]) * 16 + hexToByte(hex[i * 2 + 1]); + int j; + if (step == 1) { + // MSB + j = i; + } else { + // LSB + j = n - 1 - i; + } + uint8_t r = hexToByte(hex[j * 2]) * 16 + hexToByte(hex[j * 2 + 1]); buf[i] = r; } @@ -82,17 +83,14 @@ void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) { void os_getArtEui(u1_t *buf) { parseConfig(buf, config::lorawan_app_eui, 8, -1); -// memcpy_P(buf, config::APPEUI, 8); } void os_getDevEui(u1_t *buf) { parseConfig(buf, config::lorawan_device_eui, 8, -1); -// memcpy_P(buf, config::DEVEUI, 8); } void os_getDevKey(u1_t *buf) { parseConfig(buf, config::lorawan_app_key, 16, 1); -// memcpy_P(buf, config::APPKEY, 16); } namespace lorawan { diff --git a/ampel-firmware/lorawan.h b/ampel-firmware/lorawan.h index 3c9443af0fb9ddd95e0d85c22cedb661e3ddc8e4..e89e8c3c474ed678921f9d817a3acb11f18636a0 100644 --- a/ampel-firmware/lorawan.h +++ b/ampel-firmware/lorawan.h @@ -6,7 +6,6 @@ #include // For uint32_t & uint16_t namespace config { - extern uint16_t lorawan_sending_interval; // [s] extern const char *lorawan_frequency_plan; // e.g. "Europe 868" } diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index 3e1cd1ca3994a19657b60cd7d5d25423404c636e..2ce6a1ecdced8abdbd20c99c220d87fe0fe16d4f 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -149,14 +149,13 @@ namespace web_config { Builder>("lora_interval").label("LoRa interval").defaultValue( LORAWAN_SENDING_INTERVAL).min(0).step(1).defaultValue(300).placeholder("[s]").build(); - //TODO: Use those parameters - TextTParameter<17> deviceEUIParam = Builder>("device_eui").label("Device EUI").defaultValue( - "70B3D5...").build(); - TextTParameter<17> appEUIParam = - Builder>("app_eui").label("App EUI").defaultValue("00EA07...").build(); - TextTParameter<33> appKeyParam = - Builder>("app_key").label("App key").defaultValue("81CCFE...").build(); - //TODO: Save LoRa session to hidden parameter after first OTAA successful login + TextTParameter<17> deviceEUIParam = Builder>("device_eui").label("Device EUI (MSB)").defaultValue( + LORAWAN_DEVICE_EUI).build(); + TextTParameter<17> appEUIParam = Builder>("app_eui").label("App EUI (MSB)").defaultValue( + LORAWAN_APPLICATION_EUI).build(); + TextTParameter<33> appKeyParam = Builder>("app_key").label("App key (MSB)").defaultValue( + LORAWAN_APPLICATION_KEY).build(); + #endif OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider; @@ -345,6 +344,7 @@ namespace config { bool is_lorawan_active() { return web_config::loraParams.isActive(); } + uint16_t &lorawan_sending_interval = web_config::loraIntervalParam.value(); char *lorawan_device_eui = web_config::deviceEUIParam.value(); char *lorawan_app_key = web_config::appKeyParam.value(); char *lorawan_app_eui = web_config::appEUIParam.value(); diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index b952941189d49c4c6ff6aa7b62ac794428abdeb2..c9b23af91bb82c49fa26dfd141b388600d10ff7c 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -54,6 +54,7 @@ namespace config { // LORAWAN #if defined(ESP32) bool is_lorawan_active(); // also defined for ESP8266, and set to false + extern uint16_t &lorawan_sending_interval; extern char *lorawan_device_eui; extern char *lorawan_app_key; extern char *lorawan_app_eui;