Connect LoPy LoRa with Semtech Board



  • Hello,

    I am trying to connect Semtech LoRa development board with LoPy. I am sending 9 bytes of payload from Semtech board each 2 seconds. Format of the packet that is sent from Semtech board is: first 4 bytes are unsigned int (used for packet ID), other 5 bytes are dummy.

    I am able to receive packets on LoPy, but with following problems:

    • Not able to receive each packet, but every second (packet loss is 50%)
    • Able to extract packet ID properly only if reading first two bytes: _LORA_PKG_FORMAT = "H" (unsigned short int, 2 bytes). If I put _LORA_PKG_FORMAT = "I" (unsigned int, 4 bytes), it is decoded as garbage.

    Code that I used for reception is given below:

    import pycom
    import socket
    import time
    import struct
    from network import LoRa
    pycom.heartbeat(False)
    pycom.rgbled(0xffffff)
    _LORA_PKG_FORMAT = "I"
    lora = LoRa(mode=LoRa.LORA,
    frequency=868000000,
    power_mode=LoRa.ALWAYS_ON,
    tx_power=14,
    bandwidth=LoRa.BW_125KHZ,
    sf=10,
    preamble=8,
    coding_rate=LoRa.CODING_4_6,
    tx_iq=False,
    rx_iq=False,
    public=False)

    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    while True:
    rxBuf = s.recv(9)
    if (len(rxBuf) > 0)
    rxData = struct.unpack(_LORA_PKG_FORMAT, rxBuf)
    print(rxData)

    Does anyone have an idea what should be done to receive each packet and to properly decode all four bytes?

    Cheers, Nikola



Pycom on Twitter