Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Checking LoRa connection after connect it

    Scheduled Pinned Locked Moved LoPy
    lopylopy4lora
    3 Posts 2 Posters 68 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      M m
      last edited by

      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 if false restart connection process again. Is this idea correct? Now I'm trying this, but it always returns true, 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!!

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @M m
        last edited by

        @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).

        M 1 Reply Last reply Reply Quote 2
        • M Offline
          M m @jcaron
          last edited by

          @jcaron Wow! I was totally confused with the concept! Thank you very much :)

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom