Merge pull request #473 from cyberman54/development

fix join DR2 for TTN; RTC save FCnt in event
This commit is contained in:
Verkehrsrot 2019-10-22 08:12:46 +02:00 committed by GitHub
commit 8f92d4153d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

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

View File

@ -91,7 +91,7 @@ void lora_setupForNetwork(bool preJoin) {
#elif CFG_LMIC_EU_like #elif CFG_LMIC_EU_like
// setting for TheThingsNetwork // setting for TheThingsNetwork
// TTN uses SF9, not SF12, for RX2 window // TTN uses SF9, not SF12, for RX2 window
// LMIC.dn2Dr = EU868_DR_SF9; LMIC.dn2Dr = EU868_DR_SF9;
// Enable link check validation // Enable link check validation
LMIC_setLinkCheckMode(true); LMIC_setLinkCheckMode(true);
#endif #endif
@ -478,6 +478,12 @@ static void myEventCallback(void *pUserData, ev_t ev) {
lora_setupForNetwork(false); lora_setupForNetwork(false);
break; break;
case EV_TXCOMPLETE:
// save current Fcnt to RTC RAM
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
break;
case EV_JOIN_TXCOMPLETE: case EV_JOIN_TXCOMPLETE:
// replace descriptor from library with more descriptive term // replace descriptor from library with more descriptive term
snprintf(lmic_event_msg, LMIC_EVENTMSG_LEN, "%-16s", "JOIN_WAIT"); 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 // store LMIC keys and counters in RTC memory
#if (HAS_LORA) #if (HAS_LORA)
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey); LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
#endif #endif
ESP_LOGI(TAG, "restarting device (warmstart), keeping runmode %d", ESP_LOGI(TAG, "restarting device (warmstart), keeping runmode %d",
RTC_runmode); 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)) if ((!wakeup_sec) && (!wakeup_gpio) && (RTC_runmode == RUNMODE_NORMAL))
return; return;
// assure LMIC is in safe state
#if (HAS_LORA)
if (os_queryTimeCriticalJobs(ms2osticks(10000)))
return;
#endif
// set up power domains // set up power domains
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON); 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 // store LMIC keys and counters in RTC memory
#if (HAS_LORA) #if (HAS_LORA)
LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey); LMIC_getSessionKeys(&RTCnetid, &RTCdevaddr, RTCnwkKey, RTCartKey);
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
#endif #endif
// halt interrupts accessing i2c bus // halt interrupts accessing i2c bus