LoRa and BLE simultaneously
-
Hello everyone!
I started working on LoPy a while back and it's been fun so far. Right now, as per my project requirements, I'm supposed to use BLE and LoPy simultaneously. But I'm stuck because I want to send the messages over LoRa at an interval of 30 seconds if there is no BLE beacon around, and send a message as soon as any beacon is detected (This means BLE is always in scanning mode). And I'm not able to use time.sleep() as it stops BLE scanning too. So, I would appreciate some help addressing the issue.
Thanks :)
-
@crumble Thanks for the quick reply.
I had tried a similar thing with Chrono earlier, but it failed because while executing, if that section of code isn't encountered within the stipulated time, then it skips it and the model would lose a message.
This is the sample code I had tried (For testing purpose, I kept the interval of 5 seconds):
#When no beacon nearby else: chrono = Timer.Chrono() chrono.start() if (chrono.start() or 5<chrono.read()<=6): s.send(msg) if (s.send(msg)): print("Message Sent") chrono.reset()
-
The easy way is to remember the time like
lastLoRa = rtc.now()
and check each couple of iterations if 30 seconds are past and set the lastLoRa after you have send a message.The nicer way is to seperate LoRa and Bluetooth into seperate threads, so that the LoRa thread can sleep without blocking the Bluetooth thread