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

    Handshaking with lopy?

    Scheduled Pinned Locked Moved LoPy
    lopypythonlora
    11 Posts 2 Posters 1.6k 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.
    • robert-hhR Offline
      robert-hh @stefan85e
      last edited by

      @stefan85e Exactly. And since LoRa just defines sending & receiving of packtes, you have to implement that in your scripts. You have to consider, that packets may get lost. So always wait with a timeout, so you have a chance for retrying.

      S 3 Replies Last reply Reply Quote 0
      • S Offline
        stefan85e @robert-hh
        last edited by

        @robert-hh I try understand it so I can figure out how to get it in the code... we want this so we can avoid wating to long time ... Better have this then a delay....Dont see any exempel on it

        1 Reply Last reply Reply Quote 0
        • S Offline
          stefan85e @robert-hh
          last edited by stefan85e

          @robert-hh

          lora = LoRa(mode=LoRa.LORA, tx_power = 14, sf = 7, frequency=863000000)
          s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
          s.setblocking(False) ---> Should this be true or false

          while (True):
          s.setblocking(True)
          s.send(bytes([1])) # = 1 bytes
          data = s.recv(64)

          coord = l76.coordinates()
          f = open('/sd/test1.txt', 'a')
          f.write("{}\n".format(coord))
          #f.write("{}\n".format(gc.mem_free))
          f.write("{}\n".format(rtc.now()))
          f.write("{}\n".format(data))
          
          
          #s.send('GPS: {}'.format(coord)) #Sending coord to the other lopy
          
          print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free()))
          rtc = machine.RTC()
          
          #s.send("Got data from Stefan over LoRa: {}".format(i))
          #s.send(bytes([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33])) # = 32 bytes
          
          print(data)
          print()
          counter_sent+=1
          print('Sent Data: {}'.format(counter_sent))
          if data:
              s.setblocking(False)
              print(data)
              print('Received Data: {}'.format(data))
              counter_received+=1
              print('Received Data: {}'.format(counter_received))
              print('Successful data received: {}%'.format(counter_received/counter_sent))
              pycom.rgbled(0x007f00) # green
              print(' ')
              print(lora.stats())
          else:
              print(' ')
              failed +=1
              print('Got no data: {}'.format(failed))
              print('Unsuccessful data received: {}%'.format(failed/counter_sent))
              pycom.rgbled(0x7f0000)
          #time.sleep(0.4)
          
          1 Reply Last reply Reply Quote 0
          • S Offline
            stefan85e @robert-hh
            last edited by

            @robert-hh can this be a way to do it? Im not sure but I try to figure out what to write.. :)
            data = s.recv(64)

            controll_byte = 1
            if s.recv == len(controll_byte):
                print(Data)
            
            if not s.recv == len(controll_byte):
                print('No Data')
                break
            
            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @stefan85e
              last edited by

              @stefan85e
              That#s strange.- mayby you should better write:

              data = s.recv(64)
              if data is not None:
                  print(data)
              else:
                  print"No Data")
                  break
              
              S 1 Reply Last reply Reply Quote 0
              • S Offline
                stefan85e @robert-hh
                last edited by

                @robert-hh I want to make sure the data is being recv before I send more data...

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  stefan85e @stefan85e
                  last edited by

                  @robert-hh s.setblocking(True) can that be use for that?

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @stefan85e
                    last edited by

                    @stefan85e No. Setblocking will block until sufficient data is received. If a message is lost, it wait forever. You can use that with a timeout. Besides that, the largest message size for LoRa is 256 bytes. So if you write s.recv(256), at least not message will be split. You still have to cope with timeout and lost messages in your code.

                    S 2 Replies Last reply Reply Quote 0
                    • S Offline
                      stefan85e @robert-hh
                      last edited by

                      @robert-hh I want to remove the time.sleep and just focus on checking if the packed is sent before sending more so I can max out the send and recv part...

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        stefan85e @robert-hh
                        last edited by stefan85e

                        This post is deleted!
                        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