LoPy Ping-Pong Example



  • Greetings,

    I have a question regarding the LoPy to LoPy Ping-Pong example code which uses raw lora to communicate. I am currently using this code for my receiving node.

    from network import LoRa
    import socket
    import time
    import pycom
    
    
    #NODE A
    
    # Please pick the region that matches where you are using the device:
    # Asia = LoRa.AS923
    # Australia = LoRa.AU915
    # Europe = LoRa.EU868
    # United States = LoRa.US915
    lora = LoRa(mode=LoRa.LORA, region=LoRa.US915, tx_power = 10)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    pycom.heartbeat(False)
    pycom.rgbled(0x007f00) # green
    
    #TX_power is the value that is set on this chip not received.
    while True:
        if s.recv(64) == b'Ping':
            print("Sending pong")
            data = lora.stats()
            print("Stats %s" % data)
            pycom.rgbled(0x0000ff) # blue
            time.sleep(.5)
            pycom.rgbled(0x00ff00) # green
    

    and then this for my sending...

    from network import LoRa
    import socket
    import time
    import pycom
    #NODE B
    
    # Please pick the region that matches where you are using the device:
    # Asia = LoRa.AS923
    # Australia = LoRa.AU915
    # Europe = LoRa.EU868
    # United States = LoRa.US915
    lora = LoRa(mode=LoRa.LORA, region=LoRa.US915)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    pycom.heartbeat(False)
    pycom.rgbled(0x007f00) # green
    
    while True:
        s.send('Ping')
        time.sleep(5)
        pycom.rgbled(0x0000ff) # blue
        time.sleep(1)
        pycom.rgbled(0x00ff00) # green
    

    I use an antenna for both LoPys, I get messages and data received just fine when they're right next to each other and when there up to 5m away. However, randomly my receiving drops out, it stops getting messages. If I restart the sending lopy then it works again, if I restart the receiving it does not. At close distance (right next to one another) I'm getting around -30dBm for the RSSI, which seems bad due to their proximity. Any suggestions? I've had it work for over 3 hours and stop and I've had it stop after 3 minutes.



  • @burgeh As said, I did not investigate the ping-pong example further. I just used it to check, whether the devices work at all. Using the TTN gateway software was more reliable. At least messages form the node to the gateway arrive all the time. You may have a look at the non-TTN gateway example https://github.com/pycom/pycom-libraries/tree/master/examples/loraNanoGateway
    That one is a litte bit more elaborate and may be a better starting point. I tried it too, and it worked. The code of interest is in the respective main.py files.



  • @robert-hh Besides improve the antenna and perhaps making an enclosure to ensure components don't move, what would you suggest to help boost robustness? Sending the same data multiple times? Increasing SF?



  • @burgeh The ping pong sample code is just for demonstration and not very robust. In my test I always had to start lopy_b fist to get it running.
    As of receiving levels: In my desktop test (~1m apart) I had levels about -20db. Besides that, it heavily depends on antenna cables and antennas. The u.fl is not made for frequent plugs and is sensitive to moving. Even for testing you attach xxpy and the antenna to a case or a piece of metal sheet, such that the pigtail cable with the u.fl plug does not move or is further bent.



Pycom on Twitter