TheThingsNetwork / arduino-device-lib

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

Fix infinite join retry #207

Closed jpmeijers closed 7 years ago

johanstokking commented 7 years ago

This changes behavior as it will try once more.

What's wrong with the original code, is that if retries == 0, it goes in infinite mode. I'd suggest introducing an attempts variable set to retries + 1 and check retries == -1 || attempts-- > 0

jpmeijers commented 7 years ago

In the original code any positive value will make it go into an infinite retry. The original check was just wrong.

The fix does not change the behaviour. Confirmed on a device: ttn.join(appEui, appKey, 2, 10000); - Tries 2 times to join. ttn.join(appEui, appKey, 0, 10000); - Does not try to join. ttn.join(appEui, appKey, -1, 10000); - Infinitely tries to join. ttn.join(appEui, appKey, -2, 10000); - Does not try to join. ttn.join(appEui, appKey); - Infinitely tries to join.

jpmeijers commented 7 years ago

I think I see the issue. "Try" vs "retry".

"Number of times to retry after failed or unconfirmed join. Defaults to -1 which means infinite."

So according to the documentation if the value is 0, you want it to try to join once.

jpmeijers commented 7 years ago

Behaviour is now: ttn.join(appEui, appKey, 2); - Tries 3 times to join. ttn.join(appEui, appKey, 0); - Tries 1 time to join. ttn.join(appEui, appKey, -1); - Tries infinitely to join. ttn.join(appEui, appKey, -2); - Tries 0 times to join.

Also did a minor version number bump.