diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index 43f11c01..027e97f9 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -10,9 +10,8 @@ /* // Only define DEVEUI here if you don't want it to be derived from device's MAC address -// Use little endian format (lsb) - -//static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +// Use same format as in TTN console (cut & paste, for your convenience) +static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // This EUI must be in little-endian format, so least-significant-byte // first. When copying an EUI from ttnctl output, this means to reverse diff --git a/src/lorawan.cpp b/src/lorawan.cpp index b47d6ea3..85164280 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -36,6 +36,16 @@ void gen_lora_deveui(uint8_t *pdeveui) { } } +// Function to do a byte swap in a byte array +void RevBytes(unsigned char* b, size_t c) +{ + u1_t i; + for (i = 0; i < c / 2; i++) + { unsigned char t = b[i]; + b[i] = b[c - 1 - i]; + b[c - 1 - i] = t; } +} + #ifdef VERBOSE // Display a key diff --git a/src/main.cpp b/src/main.cpp index c1cf2128..5ac7daaf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,8 @@ void loadConfig(void); // defined in lorawan.cpp void gen_lora_deveui(uint8_t * pdeveui); +void RevBytes(unsigned char* b, size_t c); + #ifdef VERBOSE void printKeys(void); #endif // VERBOSE @@ -82,11 +84,14 @@ void gen_lora_deveui(uint8_t * pdeveui); // LMIC callback functions void os_getArtEui (u1_t *buf) { memcpy(buf, APPEUI, 8);} void os_getDevKey (u1_t *buf) { memcpy(buf, APPKEY, 16);} -#ifdef DEVEUI // if DEVEUI defined in loraconf.h use that and hardwire it in code ... - void os_getDevEui (u1_t *buf) { memcpy(buf, DEVEUI, 8);} -#else // ... otherwise generate DEVEUI at runtime from devices's MAC - void os_getDevEui (u1_t *buf) { gen_lora_deveui(buf);} -#endif +void os_getDevEui (u1_t* buf) { + #ifdef DEVEUI + memcpy(buf, DEVEUI, 8); + RevBytes(buf, 8); // TTN requires it in LSB First order, so we swap bytes + #else + gen_lora_deveui(buf); + #endif +} // LMIC enhanced Pin mapping const lmic_pinmap lmic_pins = { diff --git a/src/main.h b/src/main.h index 84392654..50191325 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,5 @@ // program version -#define PROGVERSION "1.2.31" // use max 10 chars here! +#define PROGVERSION "1.2.32" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output