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

    LoPy to LoPy tutorial (via LoRa)

    Scheduled Pinned Locked Moved Getting Started
    lopy lora modelopyloranodes
    5 Posts 2 Posters 3.1k 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.
    • E Offline
      epifanio
      last edited by

      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!

      B 1 Reply Last reply Reply Quote 0
      • B Offline
        bucknall @epifanio
        last edited by

        Hi @epifanio,

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

        Developer Evangelist - Pycom

        E 1 Reply Last reply Reply Quote 0
        • E Offline
          epifanio @bucknall
          last edited by

          @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!

          B 1 Reply Last reply Reply Quote 0
          • B Offline
            bucknall @epifanio
            last edited by bucknall

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

            Developer Evangelist - Pycom

            E 1 Reply Last reply Reply Quote 0
            • E Offline
              epifanio @bucknall
              last edited by epifanio

              @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!

              1 Reply Last reply Reply Quote 1

              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