From 33483b3d5389dba09937e2735f4d4574eb4f86a3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 17 Jan 2020 20:49:26 -0800 Subject: [PATCH] share common init and make OTAA work correctly with a non single-ch gway --- main/main.ino | 38 +++++++++++++++++++++++++++++++++++++- main/ttn.ino | 39 ++++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/main/main.ino b/main/main.ino index 18d973b..837640f 100644 --- a/main/main.ino +++ b/main/main.ino @@ -101,9 +101,45 @@ void sleep() { #endif } +void printHex2(unsigned v) { + v &= 0xff; + if (v < 16) + Serial.print('0'); + Serial.print(v, HEX); +} + + void callback(uint8_t message) { if (EV_JOINING == message) screen_print("Joining TTN...\n"); - if (EV_JOINED == message) screen_print("TTN joined!\n"); + if (EV_JOINED == message) { + screen_print("TTN joined!\n"); + + Serial.println(F("EV_JOINED")); + + u4_t netid = 0; + devaddr_t devaddr = 0; + u1_t nwkKey[16]; + u1_t artKey[16]; + LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey); + Serial.print("netid: "); + Serial.println(netid, DEC); + Serial.print("devaddr: "); + Serial.println(devaddr, HEX); + Serial.print("AppSKey: "); + for (size_t i=0; i