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

    Buffer too small problem LoRa Lopy 4

    Scheduled Pinned Locked Moved LoPy
    6 Posts 2 Posters 536 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.
    • F Offline
      ferfersan6
      last edited by

      Hey all. Maybe it is a very simple question, but I am very newbie with Python and Pycom. I am trying to send a simple doube with LoRa, from one Lopy 4 to other Lopy 4. I try to unpack the message on the receiving Lopy with struct.unpack('d',recpaquete), but it says the buffer is too small. I put the code:

      from network import LoRa
      import socket
      import time
      import struct
      
      lora = LoRa(mode=LoRa.LORA, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      
      while True:
          recpaquete = s.recv(64)
          numero = struct.unpack('d',recpaquete)
          time.sleep(5)
      

      I have tried with several numbers (512, 1024, 2048...) but doesn't work. This Lopy just receive dates.
      The code from the other lopy is:

      from network import LoRa
      import socket
      import time
      
      lora = LoRa(mode=LoRa.LORA, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      
      while True:
          paquete = struct.pack('d',57.3)
          s.send(paquete)
          time.sleep(5)
      

      Hope you can help me. Thanks in advance!!

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @ferfersan6
        last edited by robert-hh

        @ferfersan6 said in Buffer too small problem LoRa Lopy 4:
        How long is the message you actually receive? Tell it by
        print(len(recpaquete))
        It should be 8 bytes.

        F 1 Reply Last reply Reply Quote 0
        • F Offline
          ferfersan6
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • F Offline
            ferfersan6 @robert-hh
            last edited by

            @robert-hh I can't even receive a message, can't run or upload it on the Lopy. The error is in the title: "Buffer too small"

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @ferfersan6
              last edited by robert-hh

              @ferfersan6 The socket is set non noblocking. So s.recv() returns immediately if nothing was received. The return value is b"", with a buffer size of 0. Since the unpack requires at least 8 bytes, you get an error. So you have to add something like:

              from network import LoRa
              import socket
              import time
              import struct
              
              lora = LoRa(mode=LoRa.LORA, frequency=863000000)
              s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
              s.setblocking(False)
              
              while True:
                  recpaquete = s.recv(64)
                  if len(recpaquete) >= 8:
                      numero = struct.unpack('d',recpaquete)
                  time.sleep(5)
              
              F 1 Reply Last reply Reply Quote 1
              • F Offline
                ferfersan6 @robert-hh
                last edited by

                @robert-hh Wow, it works!!!! Thank you man, you are my hero!!. Seriously, I am so grateful.

                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