HelTecAutomation / CubeCell-Arduino

Heltec CubeCell Series (based on ASR6501, ASR6502 chip) Arduino support.
251 stars 138 forks source link

Timereq cause multiple join if uplinkmode set to UNCONFIRMED #240

Closed SebDominguez closed 2 years ago

SebDominguez commented 2 years ago

I don't know if this is by design or a bug, but if I try to use timereq while setting my uplinkmode to UNCONFIRMED first of dev_time_updated() is never triggered (but I successfully get the current time) and the second thing (more annoying) is that the CubeCell is sending infinite joins...

UNCONFIRMED

LoRaWAN EU868 Class A start!

joining...TX on freq 868300000 Hz at DR 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Done
joined
Unix time:6.38
This uplink added time req.
unconfirmed uplink sending ...
TX on freq 867100000 Hz at DR 5
TX on freq 867100000 Hz at DR 5
Event : Tx Done
RX on freq 867100000 Hz at DR 5
Event : Rx Done
TX on freq 868300000 Hz at DR 5
received unconfirmed downlink: rssi = -104, snr = 7, datarate = 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Done
TX on freq 868500000 Hz at DR 5
TX on freq 868500000 Hz at DR 5
Event : Tx Done
RX on freq 868500000 Hz at DR 5
Event : Rx Done
TX on freq 868500000 Hz at DR 5
TX on freq 868500000 Hz at DR 5
Event : Tx Done
RX on freq 868500000 Hz at DR 5
Event : Rx Done
TX on freq 868300000 Hz at DR 5
Capture d’écran 2022-06-22 à 21 06 09

CONFIRMED

LoRaWAN EU868 Class A start!

joining...TX on freq 868300000 Hz at DR 5
TX on freq 868300000 Hz at DR 5
Event : Tx Done
RX on freq 868300000 Hz at DR 5
Event : Rx Done
joined
Unix time:6.38
This uplink added time req.
confirmed uplink sending ...
TX on freq 867900000 Hz at DR 5
TX on freq 867900000 Hz at DR 5
Event : Tx Done
RX on freq 867900000 Hz at DR 5
Event : Rx Done
Once device time updated, this function run
received unconfirmed downlink: rssi = -108, snr = 4, datarate = 5
Capture d’écran 2022-06-22 à 21 07 51
SebDominguez commented 2 years ago

Ok so the solution is to isTxConfirmed = true; just before sending the payload and then set it to isTxConfirmed = false; inside the dev_time_updatedcallback

inside your loop you need to:

if (timeReq) {
    isTxConfirmed = true;
    timeReq = false;
    MlmeReq_t mlmeReq;
    mlmeReq.Type = MLME_DEVICE_TIME;
    LoRaMacMlmeRequest(&mlmeReq);
}

and then the callback should look like this:

void dev_time_updated() {
    isTxConfirmed = false;
    led.colorDelay(magenta, 500);
    sysTimeCurrent = TimerGetSysTime();
    setTime((time_t)sysTimeCurrent.Seconds);
}