fix join DR2 for TTN; RTC save FCnt in event

This commit is contained in:
Verkehrsrot 2019-10-22 07:16:04 +02:00
parent 76d5957313
commit b786323036
3 changed files with 13 additions and 6 deletions

View File

@ -24,7 +24,6 @@
extern TaskHandle_t lmicTask, lorasendTask;
extern RTC_NOINIT_ATTR u4_t RTCnetid, RTCdevaddr;
extern RTC_NOINIT_ATTR u1_t RTCnwkKey[16], RTCartKey[16];
extern RTC_NOINIT_ATTR int RTCseqnoUp, RTCseqnoDn;
// table of LORAWAN MAC commands
typedef struct {

View File

@ -91,7 +91,7 @@ void lora_setupForNetwork(bool preJoin) {
#elif CFG_LMIC_EU_like
// setting for TheThingsNetwork
// TTN uses SF9, not SF12, for RX2 window
// LMIC.dn2Dr = EU868_DR_SF9;
LMIC.dn2Dr = EU868_DR_SF9;
// Enable link check validation
LMIC_setLinkCheckMode(true);
#endif
@ -478,6 +478,12 @@ static void myEventCallback(void *pUserData, ev_t ev) {
lora_setupForNetwork(false);
break;
case EV_TXCOMPLETE:
// save current Fcnt to RTC RAM
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
break;
case EV_JOIN_TXCOMPLETE:
// replace descriptor from library with more descriptive term
snprintf(lmic_event_msg, LMIC_EVENTMSG_LEN, "%-16s", "JOIN_WAIT");

View File

@ -13,8 +13,6 @@ void do_reset(bool warmstart) {
// store LMIC keys and counters in RTC memory
#if (HAS_LORA)
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
#endif
ESP_LOGI(TAG, "restarting device (warmstart), keeping runmode %d",
RTC_runmode);
@ -67,6 +65,12 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) {
if ((!wakeup_sec) && (!wakeup_gpio) && (RTC_runmode == RUNMODE_NORMAL))
return;
// assure LMIC is in safe state
#if (HAS_LORA)
if (os_queryTimeCriticalJobs(ms2osticks(10000)))
return;
#endif
// set up power domains
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
@ -83,8 +87,6 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) {
// store LMIC keys and counters in RTC memory
#if (HAS_LORA)
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
#endif
// halt interrupts accessing i2c bus