lora_device_lib
lora_device_lib copied to clipboard
Fix channel selection for AU915-928 US902-928
When selecting the channel to transmit, the library is omitting that not all channels can use all SF. That is the case for AU915-928 and US902-928. I noticed that TTN was forcing a SF7 (with ADR) but something my device was transmitting at SF8BW500 (channel 65). Immediately after that TX, TTN was sending a new ADR command to use SF7 again.
After debugging the library, I've found out that the selectChannel function was selecting any available channel, regardless if the desired data rate was obtainable or not (the function requiredRate was approximating the closest data rate, which I'm not sure if it's valid, at least TTN didn't like it). I've added a new parameter (desired_rate) to the function isAvailable to check if the required channel index is compatible with the desired SF. Probably the selectChannel function needs a refactoring. But for now I think this works fine.