JackGruber / ESP32-LMIC-DeepSleep-example

31 stars 6 forks source link

TTN stack v3 compatibility #1

Closed xentux closed 3 years ago

xentux commented 3 years ago

Thanks a lot for this great code! It works very good with a TTN stack v2 application. I tried the same code with a stack v3 application:

But after a deep sleep it is blocked for about 10...15 secs waiting for queued data. Then the data frame is sent and the TTGO T3 goes into deep sleep again.

After every deep sleep the queue needs additional 10..15 secs before sending. That means, the next cycle needs 30, then 45 and so on. The time is varying.

I'm used to code in Python, so I didn't find out how to debug/print queued messages. I tried different settings concerning the timing, interrupts and so on. It's no solution.

Maybe you have an idea? I'm using a TTGO Lora32 v2.6.1 board with an ESP32 Pico D4.

Thanks in advance.

JackGruber commented 3 years ago

I haven't looked at V3 yet, so I can't say anything about it at the moment.

wapel commented 3 years ago

HI. I have exactly the same problem like xentux. TTN V3 otaa with TTGO Lora32 v2.6.1 board. After joining the first message is send. Go to DeepSleep works. After wakeup it is not possible to do the next "do_send" job.

// Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND)

I tried with some delays and change timing settings. Relax the RX2 with:

    // Relax RX Window
    LMIC_setClockError(MAX_CLOCK_ERROR * 10 / 100);

But no success for the moment.

jdgarcia99 commented 3 years ago

Hi.

I have the exact same problem that my colleagues with v3 version

only first deep Sleep works then the controller gets stuck waiting

JackGruber commented 3 years ago

@xentux I have tested the code with the v3 stach on my test my device need, 6 secend for each cycle. Which band plan do you use?

@wapel and @jdgarcia99 You describe not the same error as the issue opener!

jdgarcia99 commented 3 years ago

I’m using EU 868 Band

JackGruber commented 3 years ago

@jdgarcia99 please create new issue including the log output, because you descripe a different problem

jdgarcia99 commented 3 years ago

@jdgarcia99 please create new issue including the log output, because you descripe a different problem

created! ;-)

xentux commented 3 years ago

@JackGruber I use the EU868 band plan. So, I use exactly the build flags given in the platform.ini file. Except the board, where I have a ttgo-lora32-v2.

JackGruber commented 3 years ago

Could you use please the updated code, I have added some debug outputs and post the output.

xentux commented 3 years ago

Good afternoon!

I just cloned the repository, adjusted the credentials, compiled and uploaded it to the TTGO v2. It joined successfully and went to deep sleep. After that I reseted it and started again. It joined successfully and went to deep sleep, but after waking up after 300s it endlessly stuck in OP_TXRXPEND.

Monitor output:

> Executing task: platformio device monitor <

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on /dev/cu.usbserial-020603F0  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
Starting DeepSleep test
LMIC: 3.3.0.0

LMIC.opmode: 
LMIC.seqnoUp = 0
LMIC.globalDutyRate = 0 osTicks, 0 sec
LMIC.globalDutyAvail = 0 osTicks, 0 sec
LMICbandplan_nextTx = 0 osTicks, 0 sec
os_getTime = 2393 osTicks, 0 sec
LMIC.txend = 0
LMIC.txChnl = 0
Band    avail           avail_sec       lastchnl        txcap
0       0               0               0               0
1       0               0               0               0
2       0               0               0               0
3       0               0               0               0

Packet queued
3318: EV_JOINING
Cannot sleep
Runtime: 2 seconds
Cannot sleep
Runtime: 4 seconds
339592: EV_TXSTART
Cannot sleep
Runtime: 6 seconds
Cannot sleep
Runtime: 8 seconds
Cannot sleep
Runtime: 10 seconds
660639: EV_JOINED
netid: 19
devaddr: 260B951E
artKey: B85AFE31F2CD6BE028DAF9201D1317
nwkKey: AC0FDD5A21EBCDDA68BAC911B01F8F
660686: EV_TXSTART
Cannot sleep
Runtime: 12 seconds
Cannot sleep
Runtime: 14 seconds
980175: EV_TXCOMPLETE (includes waiting for RX windows)
Cannot sleep
Runtime: 16 seconds
1045648: EV_TXSTART
Save LMIC to RTC
Reset CFG_LMIC_EU_like band avail
Go DeepSleep
Runtime: 16 seconds

----- 300 sec deep sleep --------------------------------------------------------------------------

ets Jun  8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
Starting DeepSleep test
LMIC: 3.3.0.0
Load LMIC from RTC

LMIC.opmode: OP_TXRXPEND OP_NEXTCHNL 
LMIC.seqnoUp = 2
LMIC.globalDutyRate = 0 osTicks, 0 sec
LMIC.globalDutyAvail = 0 osTicks, 0 sec
LMICbandplan_nextTx = 0 osTicks, 0 sec
os_getTime = 2651 osTicks, 0 sec
LMIC.txend = 0
LMIC.txChnl = 1
Band    avail           avail_sec       lastchnl        txcap
0       0               0               2               1000
1       0               0               1               100
2       0               0               10              10
3       0               0               0               0

OP_TXRXPEND, not sending
Cannot sleep
Runtime: 2 seconds
Cannot sleep
Runtime: 4 seconds
Cannot sleep
Runtime: 6 seconds
Cannot sleep
Runtime: 8 seconds
Cannot sleep
Runtime: 10 seconds
Cannot sleep
Runtime: 12 seconds
Cannot sleep
Runtime: 14 seconds
Cannot sleep
Runtime: 16 seconds

...

Cannot sleep
Runtime: 348 seconds
Cannot sleep
Runtime: 350 seconds
Cannot sleep
Runtime: 352 seconds
Cannot sleep
Runtime: 354 seconds
Cannot sleep
Runtime: 356 seconds
Cannot sleep
Runtime: 358 seconds
Cannot sleep
Runtime: 360 seconds

... and so on.

Thank you for your help! Andy

MarcESP32 commented 3 years ago

Hi all,

I'm using an EZSBC ESP32 Dev board with separate rfm95w (EU868) and having the same problem when using TTN V3 credeńtials. Problem starts when TTN sends an unconfirmed downlink LinkADReq after a regular unconfirmed uplink by the node (FCnt 19 in the attachment) and this gets answered with an LinkADRAns. After this, the node is starting it's deepsleep , and the value for LMIC.opmode that is written to RTC seems to refer to a busy mode. After waking up, the node continues with LMIC.opmode: OP_TXRXPEND OP_NEXTCHNL which causes the system to be unable to send data to TTN See Attachments.

@JackGruber : can we solve this issue by checking the LMIC.opmode status before writing it to RTC and -if necessary- correct it. Do we need the value for LMIC.opmode saved to RTC anyway?

Thanks a lot!

BR Marc Error ESP32 DeepSleep TTNV3.txt Screenshot_2021-06-29 RAK7258 - LoRa Packet Logger - LuCI

JackGruber commented 3 years ago

@MarcESP32 Your problem has nothing todo with the problem from the issue!