Buffer too small problem LoRa Lopy 4



  • 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-hh Wow, it works!!!! Thank you man, you are my hero!!. Seriously, I am so grateful.



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


  • @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"



  • This post is deleted!


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


Log in to reply
 

Pycom on Twitter