def serialLoop(): lopy = b'f00a' # nom de la lopy node = b'effe' # nom de la node (deuxième lopy ) cle_node = b'$\n\xc4\x00\xef\xfe' #initialisation com = UART(1, 9600) com.init(9600, bits=8, parity=None, stop=1, pins=("P3", "P4")) gw = Gateway(lopy) gw.addNewNode(node, cle_node) gw.startLoRa() global x while True: #Lopy f00a reception port UART, envoie en LORA if (com.any()): lecture = com.readall() print(lecture) if (type(lecture) is bytes): print(lecture.decode()) gw.sendMsg(lecture, node) #Lopy f00a reception LoRa, emission en UART gw.recvMsg() data = gw.popOldestMsg() try: if (data[1] != b''): #print("Connexion etablie : ") x += 1 #print(data[0]+'\t'+data[1]+'\n') com.write(str(data[0])) com.write('\t') com.write(str(data[1]) + '\n') time.sleep(0.020) except IndexError: #print((x)) pass
port=1883) client.settimeout = settimeout client.connect() lopy = b'effe' # nom de la lopy node = b'f00a' # nom de la node (deuxième lopy ) cle_node = b'$\n\xc4\x00\xef\xfe' #initialisation gw = Gateway(lopy) gw.addNewNode(node, cle_node) gw.startLoRa() chaine = "vide" while True: try: if (gw.recvMsg()): data = gw.popOldestMsg() print(data) #chaine = data[0].decode() + " : " + data[1].decode() chaine = data[1] pycom.rgbled(0xffffff) client.publish("/users/quentinthse/test", chaine, qos=0) else: pycom.rgbled(0xff0000) except Exception as e: client.publish("/users/quentinthse/test", "erreur", qos=0) pass pycom.rgbled(0x000000) chaine = "vide"