TheThingsNetwork / arduino-device-lib

Arduino Library for TTN Devices
MIT License
206 stars 96 forks source link

RX2 should not be configured when using OTAA #253

Open avbentem opened 5 years ago

avbentem commented 5 years ago

Calling join for OTAA invokes configureChannels, which for some regions erroneously changes the RX2 settings:

void TheThingsNetwork::configureEU868()
{
  sendMacSet(MAC_RX2, "3 869525000");
  sendChSet(MAC_CHANNEL_DRRANGE, 1, "0 6");

  char buf[10];
  ...

...showing in the serial output as:

Sending: mac set rx2 3 869525000

However, an OTAA Join Accept should use the defaults for RX2, not some TTN specific settings. Indeed, the TTN backend uses the default settings which implies that a node will never be able to receive a Join Accept in RX2 when using this library.

One might think that the RN2xx3 module should ignore the RX2 settings for OTAA, but a forum post suggests that removing sendMacSet(MAC_RX2, "3 869525000") indeed makes OTAA work with SF12:

That seemed to do the trick! Disabling: // sendMacSet(MAC_RX2, “3 869525000”);

SendOTAA now joins TTN and payloads are coming through.

Of course, the above would make RX2 fail in ABP nodes. I'm not sure if this could be fixed by just relying on the RN2xx3 module's factory defaults for OTAA, or needs an additional condition to only suppress changing RX2 for OTAA.

Full log from the same forum topic, for EU868 when using examples/SendOTAA/SendOTAA.ino but then with SF12:

-- STATUS
EUI: <redacted>
Battery: 3325
AppEUI: 70B3D57ED00168DA
DevEUI: <redacted>
Data Rate: 0
RX Delay 1: 1000
RX Delay 2: 2000
-- JOIN
Model: RN2483
Version: 1.0.4
Sending: mac set deveui <redacted>
Sending: mac set adr off
Sending: mac set deveui <redacted>
Sending: mac set appeui 70B3D57ED00168DA
Sending: mac set appkey <redacted>
Sending: mac save 
Sending: mac set rx2 3 869525000
Sending: mac set ch drrange 1 0 6
Sending: mac set ch dcycle 0 799
Sending: mac set ch dcycle 1 799
Sending: mac set ch dcycle 2 799
Sending: mac set ch dcycle 3 799
Sending: mac set ch freq 3 867100000
Sending: mac set ch drrange 3 0 5
Sending: mac set ch status 3 on
Sending: mac set ch dcycle 4 799
Sending: mac set ch freq 4 867300000
Sending: mac set ch drrange 4 0 5
Sending: mac set ch status 4 on
Sending: mac set ch dcycle 5 799
Sending: mac set ch freq 5 867500000
Sending: mac set ch drrange 5 0 5
Sending: mac set ch status 5 on
Sending: mac set ch dcycle 6 799
Sending: mac set ch freq 6 867700000
Sending: mac set ch drrange 6 0 5
Sending: mac set ch status 6 on
Sending: mac set ch dcycle 7 799
Sending: mac set ch freq 7 867900000
Sending: mac set ch drrange 7 0 5
Sending: mac set ch status 7 on
Sending: mac set pwridx 1
Sending: mac set retx 7
Sending: mac set dr 0
Sending: mac join otaa 
Join not accepted: denied
Check your coverage, keys and backend status.
Sending: mac join otaa 

(The same forum topic also shows problems for OTAA with SF7, using RX1, hence unrelated.)

johanstokking commented 5 years ago

Yes, this is correct indeed.

Can you file a PR?

jpmeijers commented 2 years ago

We need to look at this next.