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 communication issue

    Scheduled Pinned Locked Moved LoPy
    lopylora
    9 Posts 5 Posters 2.5k Views 5 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.
    • IplookyI Offline
      Iplooky
      last edited by Iplooky

      Hello,
      I want to make a basic transmision Lopy-Lopy. After two and a half hours of trying I have no ideea why it's not working.

      The codes are exactly the ones from here https://docs.pycom.io/chapter/tutorials/lopy/lopy-lopy.html (ok maybe with some additional led blinking just to be shure the code is fine)

      I've connected them one at a time, sync the code, put them in the configuration :
      Battery->LoPy1->antena - - - antena <-LoPy2<-usb<-PC
      And waited for the message. (that did not appear in the terminal)
      Are there any steps to do that I am missing ? Do I need to modify in LoPy1 at pymakr.conf the adress as 192.168.0.1 ? When I sync the codes need to be in separate folders ? When I send information, how does Lopy2 know that the message is good to recieve (there may be another 10 Lopy's in the area that send messages that I don't want to see)? Thank you !

      C 1 Reply Last reply Reply Quote 0
      • M Offline
        monersss
        last edited by

        @Iplooky did you sync the code as a main.py file or change the main.py file to execute the file that includes the code?
        If not you need to do that on the lopy which you connect to a battery or connect lopys to 2 different computers and run the codes from atom.

        1 Reply Last reply Reply Quote 0
        • C Offline
          crumble @Iplooky
          last edited by

          @iplooky

          1. test the code with s.setblocking(True)

          2. Identifying your messages is more or less easy. Listen and log all messages in your area. Find a unique string, which no one is sending and place it in front of all your messages. If a message starts with this string you have a high chance that this message is from one of your LoPys.
            If you send your messages uncrypted, someone may capture your messages and send you faulty data. So encrypt your data, if something relays on the data. Controlling your heater may be a bad idea. If you send the message "lplooky: It's hot, stop" much too often, someone may send it for you.

          Maybe you can join the TTN and use their message format.

          1 Reply Last reply Reply Quote 0
          • sebS Offline
            seb
            last edited by

            Hi,

            When I recently attempted to use this example I forgot to update the firmware on one of the two LoPy boards I was using causing very few messages to get through. Can you double check that BOTH LoPy boards are fully updated?

            1 Reply Last reply Reply Quote 0
            • IplookyI Offline
              Iplooky
              last edited by Iplooky

              Hello,
              I've double checked the firmware upgrade, I've synced the code again and I've made progress (but still things are wierd):

              So the basic code says that LoPy_PC sends 'Ping' and IF Lopy_Field recieves it then it will send 'Pong', that didn't work (LoPy_PC didn't recieve any messaje)
              After that I tried that LoPy_Field will send a message without the condition of recieving 'Ping' (so no condition at all). That worked, I mean LoPy_PC recieves that message. Another issue is that the message is recieved 6 of 10 times (it is normal to have that kind of imprecision? They are like half a meter distance one from the other).
              Also tried with data from the Pysense but "object with buffer protocol required".

              Do I need in "lora = LoRa(mode=LoRa.LORA)" to set a particular frequency or to add a bigger sf ? Thanks.

              J C 2 Replies Last reply Reply Quote 0
              • J Offline
                jmarcelino @Iplooky
                last edited by

                @iplooky
                Bigger SF at that distance is not needed.

                Try another frequency, you may have too much interference on the one you’re using.

                Also try to separate both boards more, half a meter at the default transmit power is too close and probably over saturating the receiver

                1 Reply Last reply Reply Quote 0
                • C Offline
                  crumble @Iplooky
                  last edited by

                  @iplooky said in Lopy to Lopy communication issue:

                  So the basic code says that LoPy_PC sends 'Ping' and IF Lopy_Field recieves it then it will send 'Pong', that didn't work (LoPy_PC didn't recieve any messaje)

                  There is no code, which receives the Pong, if you use the example code unchanged. Yes, it would be nice, if pycom uses a more beginner friendly example ;)

                  1 Reply Last reply Reply Quote 0
                  • sebS Offline
                    seb
                    last edited by

                    When I was testing this example I modified the code slightly to make it easier to see what is happening. If you think this is better than the current example let me know and I can update the documentation to include it:

                    Pong.py

                    from network import LoRa
                    import socket
                    import time
                    
                    lora = LoRa(mode=LoRa.LORA, frequency=863000000)
                    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                    s.setblocking(False)
                    
                    while True:
                        rec = s.recv(64)
                        if rec != b'':
                            in_msg = rec.decode()
                            reply = in_msg.replace("Ping", "Pong")
                            s.send(reply)
                            print("Got:{}, Replied:{}".format(in_msg, reply))
                        else:
                            print("NULL")
                        time.sleep(1)
                    

                    Ping.py

                    from network import LoRa
                    import socket
                    import time
                    
                    lora = LoRa(mode=LoRa.LORA, frequency=863000000)
                    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                    s.setblocking(False)
                    
                    x=0
                    while True:
                        out = 'Ping %s' % x
                        s.send(out)
                        rec = s.recv(64)
                        if rec != b'':
                            in_msg = rec.decode()
                            print("Sent:{}, Got Back:{}".format(out, in_msg))
                        else:
                            print("Sent:{}, Got no reply".format(out))
                        time.sleep(1)
                        x=x+1
                    

                    I just tried the above code using two LoPy boards that are spaced about 30cm apart and everything seems to be working.

                    1 Reply Last reply Reply Quote 0
                    • IplookyI Offline
                      Iplooky
                      last edited by

                      @seb I've tried you're code, it is better but in my opinion it's harder than the first one (I don't really know but the sintax " if rec=='Ping' "didn't work so I've tried yours :"if rec !=b' ' " that's just fine)

                      @jmarcelino at a distance of 15 meters I had accuracy of almost 40% ( from 100 messages sent from LoPyPC only 40 came back from the other LoPy )

                      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