beegee-tokyo / SX126x-Arduino

Arduino library to use Semtech SX126x LoRa chips and modules to communicate
MIT License
235 stars 64 forks source link

LoRaWAN Change Region #53

Closed Muuhoooo closed 2 years ago

Muuhoooo commented 2 years ago

Hi Bernd, I hope you're fine.

I am working on ESP32 Sx1262 LoRaWAN on Arduino Plartform and first of all I has tried to connect EU868 and I have successfully sent the package. Then I changed the region inside the void loop and called the lmh_init and lmh_join functions again. The region has changed, I saw on the serial screen, but normally when I called the lmh_join function, it would enter the lorawan_has_joined_handler function, but in the code, it went into the tx_lora_periodic_handler function and "Did not join network, skip sending frame"

is this normal? What should we do if we want to join another region after joining a region?

beegee-tokyo commented 2 years ago

The library does not support changing the region after it has joined. You have to set the region before starting lmh_join() in lmh_init().

The only option is to reset the device and do a fresh initialization.

IMHO it makes no sense to change the region during runtime in a real application (unless your ESP32 can teleport from continent to continent).

Muuhoooo commented 2 years ago

I understand 😂, thank you very much.

Muuhoooo commented 2 years ago

In fact, we fly the card with a balloon and transfer data to the gateway, so a region change was required. Thank you.

beegee-tokyo commented 2 years ago

Ah, I heard about that balloon thing.

A possible workaround: What you can try is to use the ESP32 Preferences class. Save the new required region in the preferences, force reboot of the ESP32, read new region from the preferences , do initialization with new region.

Muuhoooo commented 2 years ago

Thank you so much for the most logical solution.

beegee-tokyo commented 2 years ago

I did something like this in my MHC-Sunnyboy application: prefs.cpp I setup the complete LoRaWAN credentials and settings over BLE instead of having them hard-coded. Then I save them in the Preferences and read them back on boot.

beegee-tokyo commented 2 years ago

@Muuhoooo Now you sparked my curiosity.

How do you handle the fact that LoRaWAN nodes are registered with a specific Region setting in the LoRaWAN server? You might need to change the DevEUI as well I guess.

Muuhoooo commented 2 years ago

I tried to change it while in the same region(EU868) for now. First of all I defined it as follows: LoRaMacRegion_t CurrentRegion = LORAMAC_REGION_US915;
Serial.println(CurrentRegion); And I saw CurrentRegion=0 and OTAA joined failed,Check LPWAN credentials and if a gateway is in range,Restart network join request and if i enter the function i get this output i updated the value and I defined it as follows: LoRaMacRegion_t CurrentRegion = LORAMAC_REGION_EU868;
Serial.println(CurrentRegion); And I saw CurrentRegion=5 and I changed my region and transmit packet.

beegee-tokyo commented 2 years ago

Never tried something like this. Just gave away my EU868 gateway unfortunately, now I have only AS923-3 available.

Muuhoooo commented 2 years ago

Hi Bernd, I have tried run time to change region even I started with EU868 and I send 3 packet and I tried again EU868 and code started and send data no problem then I started as EU868 and send 3 packet and change region AS915 I saw did not join and when it came to the function I returned a value again than tried EU868 successfully joined at runtime. I change in "void loop" function. It was a surprise to me, but when the region was changed, it was successfully rejoined. I wanted to share with you.

beegee-tokyo commented 2 years ago

@Muuhoooo 👏 Just to confirm I understand correct, you were able to change the Region "on the fly" by calling lmh_init again with the new region?

If that works, it is great.

Muuhoooo commented 2 years ago

We've just tested it on the ground. There's time for us to take off. While I was in the European region, I started the Asian region with lmh_init, then I returned to the European frequency again, I called the lmh_init function, I joined again.

Muuhoooo commented 2 years ago

but I'll let you know when we do our air fly tests.

beegee-tokyo commented 2 years ago

I should get my EU868 gateway back in 1 or 2 weeks. Then I can test if it joins both regions (EU868 and AS923-3) when I call lmh_init with each of the regions without restart.

Muuhoooo commented 2 years ago

Hmm, I'm looking forward to the results

beegee-tokyo commented 2 years ago

No more feedback. Closed.