Handshaking with lopy?

  • Handshaking:

    Anyone here that can explain how this works? What I understand is that handshaking means that I will wait for packed before sending one more. Ex: Lopy A waits for Lopy B to tell that the bytes Lopy A send has been received before sending another one...?

  • This post is deleted!

  • @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...

  • @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.

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

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

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

    data = s.recv(64)
    if data is not None:
        print"No Data")

  • @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):
    if not s.recv == len(controll_byte):
        print('No Data')

  • @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.send(bytes([1])) # = 1 bytes
    data = s.recv(64)

    coord = l76.coordinates()
    f = open('/sd/test1.txt', 'a')
    #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('Sent Data: {}'.format(counter_sent))
    if data:
        print('Received Data: {}'.format(data))
        print('Received Data: {}'.format(counter_received))
        print('Successful data received: {}%'.format(counter_received/counter_sent))
        pycom.rgbled(0x007f00) # green
        print(' ')
        print(' ')
        failed +=1
        print('Got no data: {}'.format(failed))
        print('Unsuccessful data received: {}%'.format(failed/counter_sent))

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

  • @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.

Log in to reply

Pycom on Twitter