LoPy to LoPy tutorial (via LoRa)



  • Hi,

    sorrry if this topic has been already discussed, I got lost in the tons of messages .. so I decided to start a new one.

    I'm new to micropython.
    I have 2 LoPy with latest firmware (US)

    I'm following this guide:

    https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/lopy-to-lopy.html

    Using atom+pymaker plugin I can connect to the 2 LoPy via wifi
    I used 2 computer,

    • Comp. A connected to LoPy 1
    • Comp. B connected to LoPy 2

    I run the code of the example using the shell in atom (for both computers) with frequency: 915000000

    Once I run the 2 while loops, in both shell I can see the loop running ... it prints an integer: 4 in both shell ... but the series of "ping - pong" is never printed, like the 2 LoPy are not able to see each oher.

    The 2 device are sitting on my desk, so it is not a distance issue ...
    how can I debug this problem?
    thanks for any help!



  • @bucknall Thank you so much for your help!

    I'm ashamed but It was all my fault.
    The LoRa antenna on one of the devices was not correctly wired, I'm using an extension cable ...

    I modified the script so to have pong sending back some info:

    Node A:

    from network import LoRa
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, frequency=915000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    
    while True:
        rec = [s.recv(64).decode()]
        if "Ping" in rec[0].split(" "):
            print(rec[0])
            s.send('Pong %s' % rec[0].split(" ")[-1])
        time.sleep(5)
    

    Node B

    from network import LoRa
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, frequency=915000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    x=0
    while True:
        s.send('Ping %s' % x)
        time.sleep(5)
        x=x+1
        print(s.recv(64).decode())
    

    I can send the code via wifi on the LoPy with no needs of microsd card on the device.
    If the wifi connection drop or I close it, the LoRa communication keeps goig :)
    when I reconnect with wifi in the atom shell I can actually see the ping number growing.

    More post coming soon, but I'll make sure to check the wiring first ... I'm really excited!
    Thanks!


  • administrators

    @epifanio Hmm ok - can I suggest that you add some print statements to your loops to just check that they are running correctly? There is a difference between running your code in the REPL vs in a script. In order to print out values in a script you need to wrap your variable in a print() statement, e.g. print(1+1). In the REPL you can simple just type '1+1' and get an output.

    e.g.

    Device A

    while True:
        print('checking for message')
        if s.recv(64) == b'Ping':
            print("Ping)
            s.send('Pong')
            time.sleep(5)
    

    Device B

    while True:
        print('Sending Ping')
        s.send('Ping')
        time.sleep(5)


  • @bucknall

    I used the exact same code posted in the link. I copied it "line by line" and executed in the atom shell.

    • device A:
    from network import LoRa
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, frequency=915000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    while True:
        if s.recv(64) == b'Ping':
            s.send('Pong')
        time.sleep(5)
    
    • device B

      from network import LoRa
      import socket
      import time
      
      lora = LoRa(mode=LoRa.LORA, frequency=915000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      
      while True:
          s.send('Ping')
          time.sleep(5)
      

    The only exception is the frequency, when I upgraded the firmware I selected United States at the location prompt.

    I tested if the LoPy devices are receiving instruction from the atom shell (by running the code to change the color of the rgb led) and it works fine.

    Thanks for helping me!


  • administrators

    Hi @epifanio,

    Could you please share the code that you are using for both device A and B please? Thanks!



Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.