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

    Receiving Payload string from the gateway to the LoPy

    Scheduled Pinned Locked Moved LoPy
    lopy lorawanlopy lora 868lopy connectiongateway
    8 Posts 2 Posters 2.6k 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.
    • N Offline
      neilh93
      last edited by

      Does anyone know if its possible to receive data on the LoPy from the gateway?

      I'm hoping to send a string to my LoPy from the gateway and then print it on the screen.

      using the standard piece of code with s.send() commented out.

      from network import LoRa
      import socket
      import binascii
      import struct
      
      # create an OTAA authentication parameters
      app_eui = binascii.unhexlify('AD A4 DA E3 AC 12 67 6B'.replace(' ',''))
      app_key = binascii.unhexlify('11 B0 28 2A 18 9B 75 B0 B4 D2 D8 C7 FA 38 54 8B'.replace(' ',''))
      
      # join a network using OTAA (Over the Air Activation)
      lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
      
      # wait until the module has joined the network
      while not lora.has_joined():
          time.sleep(2.5)
          print('Not yet joined...')
      
      # Initialize LoRa in LORAWAN mode.
      lora = LoRa(mode=LoRa.LORAWAN, adr=False, public=True)
      
      lora.add_channel(0, frequency=868000000, dr_min=0, dr_max=5)
      
      # join a network using OTAA
      lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key))
      
      # create a LoRa socket
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      
      # set the LoRaWAN data rate
      s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
      
      # make the socket non-blocking
      s.setblocking(False)
      
      # send some data
      # commented out to receive come from network-server.
      # s.send(bytes([0x01, 0x02, 0x03]))
      
      # get any data received...
      data = s.recv(512)
      print(data)
      
      

      Then I'm sending a [msg.payload]: string, containing "Hello08152017"

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @neilh93
        last edited by

        @neilh93
        In LoRaWAN Class A you have to send something first before you are able to receive.

        N 1 Reply Last reply Reply Quote 0
        • N Offline
          neilh93 @jmarcelino
          last edited by

          @jmarcelino okay do If I set up send from the device to the gateway then send my string it should be able to be received that way?

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            jmarcelino @neilh93
            last edited by

            @neilh93
            Yes, if you have something queued for downlink from your network server you should get it when you do an uplink (send). But your post is short on details. what does your gateway connect to?

            N 1 Reply Last reply Reply Quote 0
            • N Offline
              neilh93 @jmarcelino
              last edited by

              @jmarcelino sorry for the long wait to reply. I'm trying to update the keys on the device so i would like to make use of the bidirectional communication to send a new key to the device by way of a message from field gateway.

              J 1 Reply Last reply Reply Quote 0
              • J Offline
                jmarcelino @neilh93
                last edited by

                @neilh93
                Sorry you'll have to explain a bit more. What keys are you trying to update, the LoRaWAN App Key ?

                I wonder if you really need to use LoRaWAN (with a network server etc) or can use "raw" LoRa with point-to-point connections?

                If you do need LoRaWAN you'll usually - unless you're operating a power hungry LoRaWAN Class C network - need to send a message first (can be anything) from the node in order to receive.

                That is how the bidirectionally works in Class A, the sent packet provides the initial timing reference for when the node will be listening.

                N 1 Reply Last reply Reply Quote 0
                • N Offline
                  neilh93 @jmarcelino
                  last edited by

                  @jmarcelino okay sorry for that. The App Key and the App Eui are the "keys" i'm looking to update.

                  Currently, thanks to your help, I have it working where i can send an up-link to the gateway and receive the desired down-link with my new App Key. I need to use a LoRaWAN Class A network and not "raw" LoRa.

                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    jmarcelino @neilh93
                    last edited by

                    @neilh93
                    Great.

                    Yes I use a similar thing for my commercial product. But remember that nodes may miss (due to RF issues, power) the "key change" message and still use the old one.

                    What I did was to clone the existing device on the server backend but with the new keys. Then when a transmission arrives on the new device (which means the node has updated the keys) the old device is deleted.

                    If the next transmission still arrives on the old device it means the node has not picked it up so a new key change message is scheduled for retransmission - this is repeated until it's finally picked up.

                    1 Reply Last reply Reply Quote 1

                    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