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

    LoRa Communication between 2 lopys

    Scheduled Pinned Locked Moved LoPy
    7 Posts 3 Posters 2.2k Views 3 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.
    • F Offline
      fb
      last edited by

      Hi all,

      i am trynig to have a comm between 2 lopys using the LoRa.LORA mode.
      I used this code :

      server:

      from network import LoRa
      import socket
      
      lora = LoRa(mode=LoRa.LORA)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      mydata = s.recv(64)
      print(mydata)
      

      client:

      from network import LoRa
      import socket
      
      lora = LoRa(mode=LoRa.LORA)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.send(b'0123456789')
      

      nothing happens...
      I dont see anything transiting.
      What am i doing wrong ?

      Thx
      François

      R 1 Reply Last reply Reply Quote 0
      • G Offline
        gump103
        last edited by

        Hi

        I think its because you only listen once. you need to get the server constantly listening.

        While (true):
        mydata = s.recv(64)
        print(mydata)

        Then send the packet again.

        Also not all packets make it to the server so posibly loop the "send as" as well with a:

        time.sleep(2)

        at the end of the loop.

        James

        1 Reply Last reply Reply Quote 0
        • F Offline
          fb
          last edited by

          Thx for your answer.
          So i did that :

          Client :

          from network import LoRa
          import socket
          import time
          
          lora = LoRa(mode=LoRa.LORA)
          s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
          s.setblocking(False)
          
          while(True):
              s.send(b'0123456789')
              time.sleep(2)
          

          Server :

          from network import LoRa
          import socket
          
          lora = LoRa(mode=LoRa.LORA)
          s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
          s.setblocking(False)
          
          while(True):
              mydata = s.recv(64)
              if (len(mydata)>2):
                  print(mydata)
          

          Stil nothing is printed.
          And my REPL is out because it seems overloaded. Is it normal ?

          François

          1 Reply Last reply Reply Quote 0
          • F Offline
            fb
            last edited by

            My configuration :

            import os; [os.uname().sysname, os.uname().machine, os.uname().release]
            ['LoPy', 'LoPy with ESP32', '0.9.5.b1']
            
            1 Reply Last reply Reply Quote 0
            • R Offline
              Roberto @fb
              last edited by

              Hello @fb

              here is a nice example on how t ouse 2 LoPys to connect them using LoRa.
              https://forum.pycom.io/topic/236/lopy-nano-gateway

              Hope this helps
              Best,
              Roberto

              1 Reply Last reply Reply Quote 0
              • F Offline
                fb
                last edited by

                Thanks !
                I tried this but doesnt work for me !
                Thats why i did something simpler.

                1 Reply Last reply Reply Quote 0
                • F Offline
                  fb
                  last edited by

                  Thanks to Roberto, problem is solved.
                  Seems to be a pbm my boot.py

                  Bad one :

                  import os
                  from machine import UART
                  uart = UART(0, 115200)
                  os.dupterm(uart)
                  

                  Good one :

                  import machine
                  import os
                  import time
                  
                  uart = machine.UART(0, 115200)
                  os.dupterm(uart)
                  
                  1 Reply Last reply Reply Quote 0

                  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