Commit 464466ed authored by Eric Duminil's avatar Eric Duminil
Browse files

First working lora with parameter

parent 00cd00e2
Pipeline #5830 passed with stage
in 2 minutes and 31 seconds
...@@ -133,16 +133,17 @@ ...@@ -133,16 +133,17 @@
// How often should measurements be sent over LoRaWAN? // 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 # 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! // 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. // They are written as hexadecimal strings, and will be parsed in the correct order.
// When copying an EUI from ttnctl output, this means to reverse the bytes. // They are written as hexadecimal strings, and will be parsed in the correct order.
# define LORAWAN_DEVICE_EUI {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11}
// This should also be in little endian format, see above. // This EUI must be in big-endian format, so most-significant-byte first.
# define LORAWAN_APPLICATION_EUI {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // You can copy the string from thethings network as-is, without reversing the bytes.
// This key should be in big endian format (or, since it is not really a # define LORAWAN_DEVICE_EUI "70B3D57ED004CB17"
// number but a block of memory, endianness does not really apply). In // This should also be in big-endian format, and can be copied as is from thethings network.
// practice, a key taken from ttnctl can be copied as-is. # define LORAWAN_APPLICATION_EUI "0102030405060708"
# define LORAWAN_APPLICATION_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // This should also be in big-endian format, and can be copied as is from thethings network.
# define LORAWAN_APPLICATION_KEY "9D06308E20B974919DA6404E063BE01D"
/** /**
* NTP * NTP
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#if defined(ESP32) #if defined(ESP32)
#include "web_config.h" #include "web_config.h"
#include "config.h" //TODO: Replace with just web_config
#include "led_effects.h" #include "led_effects.h"
#include "sensor_console.h" #include "sensor_console.h"
#include "util.h" #include "util.h"
...@@ -32,12 +31,6 @@ namespace config { ...@@ -32,12 +31,6 @@ namespace config {
#else #else
# error "Region should be specified" # error "Region should be specified"
#endif #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: // 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) { ...@@ -68,7 +61,15 @@ void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) {
Serial.println(n); Serial.println(n);
for (int i = 0; i < n; i++) { 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; buf[i] = r;
} }
...@@ -82,17 +83,14 @@ void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) { ...@@ -82,17 +83,14 @@ void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) {
void os_getArtEui(u1_t *buf) { void os_getArtEui(u1_t *buf) {
parseConfig(buf, config::lorawan_app_eui, 8, -1); parseConfig(buf, config::lorawan_app_eui, 8, -1);
// memcpy_P(buf, config::APPEUI, 8);
} }
void os_getDevEui(u1_t *buf) { void os_getDevEui(u1_t *buf) {
parseConfig(buf, config::lorawan_device_eui, 8, -1); parseConfig(buf, config::lorawan_device_eui, 8, -1);
// memcpy_P(buf, config::DEVEUI, 8);
} }
void os_getDevKey(u1_t *buf) { void os_getDevKey(u1_t *buf) {
parseConfig(buf, config::lorawan_app_key, 16, 1); parseConfig(buf, config::lorawan_app_key, 16, 1);
// memcpy_P(buf, config::APPKEY, 16);
} }
namespace lorawan { namespace lorawan {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <stdint.h> // For uint32_t & uint16_t #include <stdint.h> // For uint32_t & uint16_t
namespace config { namespace config {
extern uint16_t lorawan_sending_interval; // [s]
extern const char *lorawan_frequency_plan; // e.g. "Europe 868" extern const char *lorawan_frequency_plan; // e.g. "Europe 868"
} }
......
...@@ -149,14 +149,13 @@ namespace web_config { ...@@ -149,14 +149,13 @@ namespace web_config {
Builder<IntTParameter<uint16_t>>("lora_interval").label("LoRa interval").defaultValue( Builder<IntTParameter<uint16_t>>("lora_interval").label("LoRa interval").defaultValue(
LORAWAN_SENDING_INTERVAL).min(0).step(1).defaultValue(300).placeholder("[s]").build(); LORAWAN_SENDING_INTERVAL).min(0).step(1).defaultValue(300).placeholder("[s]").build();
//TODO: Use those parameters TextTParameter<17> deviceEUIParam = Builder<TextTParameter<17>>("device_eui").label("Device EUI (MSB)").defaultValue(
TextTParameter<17> deviceEUIParam = Builder<TextTParameter<17>>("device_eui").label("Device EUI").defaultValue( LORAWAN_DEVICE_EUI).build();
"70B3D5...").build(); TextTParameter<17> appEUIParam = Builder<TextTParameter<17>>("app_eui").label("App EUI (MSB)").defaultValue(
TextTParameter<17> appEUIParam = LORAWAN_APPLICATION_EUI).build();
Builder<TextTParameter<17>>("app_eui").label("App EUI").defaultValue("00EA07...").build(); TextTParameter<33> appKeyParam = Builder<TextTParameter<33>>("app_key").label("App key (MSB)").defaultValue(
TextTParameter<33> appKeyParam = LORAWAN_APPLICATION_KEY).build();
Builder<TextTParameter<33>>("app_key").label("App key").defaultValue("81CCFE...").build();
//TODO: Save LoRa session to hidden parameter after first OTAA successful login
#endif #endif
OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider; OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider;
...@@ -345,6 +344,7 @@ namespace config { ...@@ -345,6 +344,7 @@ namespace config {
bool is_lorawan_active() { bool is_lorawan_active() {
return web_config::loraParams.isActive(); return web_config::loraParams.isActive();
} }
uint16_t &lorawan_sending_interval = web_config::loraIntervalParam.value();
char *lorawan_device_eui = web_config::deviceEUIParam.value(); char *lorawan_device_eui = web_config::deviceEUIParam.value();
char *lorawan_app_key = web_config::appKeyParam.value(); char *lorawan_app_key = web_config::appKeyParam.value();
char *lorawan_app_eui = web_config::appEUIParam.value(); char *lorawan_app_eui = web_config::appEUIParam.value();
......
...@@ -54,6 +54,7 @@ namespace config { ...@@ -54,6 +54,7 @@ namespace config {
// LORAWAN // LORAWAN
#if defined(ESP32) #if defined(ESP32)
bool is_lorawan_active(); // also defined for ESP8266, and set to false 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_device_eui;
extern char *lorawan_app_key; extern char *lorawan_app_key;
extern char *lorawan_app_eui; extern char *lorawan_app_eui;
......
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