Checking LoRa connection after connect it
-
Thinking about my projects I though, what happens if I loose the connection after the lora joining? The answer was, no problem when it tries to send the package it will fail and I can handle it. For example try it 3 times and the fourth reset the device.
def LoRa_events(self, lora, payload): events = self.lora.events() if events & LoRa.TX_FAILED_EVENT: config.TX_Fail_cnt = config.TX_Fail_cnt + 1 if config.TX_Fail_cnt <= 3: self.LoRa_send(payload) else: config.TX_Fail_cnt = 0 machine.reset()
But what about
lora.has_joined()
? Maybe I can use it before sending and iffalse
restart connection process again. Is this idea correct? Now I'm trying this, but it always returnstrue
, therefore I'm not sure if I code it wrong or if my idea is wrong.def LoRa_join(self): try: self.lora.join( activation=LoRa.OTAA, auth=(self.dev_eui, self.app_eui,self.app_key), timeout = 0) # wait until the module has joined the network while not self.lora.has_joined(): time.sleep(2.5) except Exception as e: tracebackError(e) def LoRa_send(self, payload): try: if not self.lora.has_joined(): machine.reset() self.lora_socket.send(payload) except Exception as e: tracebackError(e)
What do you think about it?
Thank you!!
-
@jcaron Wow! I was totally confused with the concept! Thank you very much :)
-
@M-m There is no notion of "connection" in LoRaWAN. A device joins, and after that, it sends packets (which are usually not acknowledged), and hopes they get through. It's a best-effort system.
There's no connection maintenance such as keep-alives.
So you try to join, and once you have joined, you try to send data when you need to, and hope it gets to its destination.
If you need to be certain the packets go through, then you need to use confirmed packets, but remember that in some regions and/or public networks such as TTN, there are very low limits on downlinks, and the ACK counts as one, so you can't send many confirmed packets.
If you need more than that, LoRaWAN is probably not the right choice (though in some regions with your own network you can indeed get more).