Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
        return True
    except Exception :
        print("Error in readPin, Alarm off")
        alarme.cancel()
        return False
    return False

#Alarme en variable globale
global alarme

#Initialisation Gateway
mylopy = "f00a"
noeud = "effe"
gw = Gateway(mylopy)
gw.addNewNode(noeud, b'NotaSecureKey')
gw.startLoRa()

#Initialisation convertisseur Analogique numérique.
adc = machine.ADC() # create ADC object
#adc.init()
apin = adc.channel(pin='P17', attn=3)

# On vient de tout initialiser.
# On crée une alarme chargée de tout lire puis envoyer sur le LoRa.
args = [apin, gw]
#alarme = Timer.Alarm(readPin, 2.00, arg=args, periodic=True)

while True :
    try :
        val = apin()
        # Rélge de 3 pour avoir une tension