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
#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
        val = val * 3.16/4096 # (4096 = 2**12 -1 ==> Pas)
        print(gw.sendMsg("Potentiomètre : " + str(val) + " V", noeud));
        
    except Exception :
        print("Error in readPin, Alarm off")
        alarme.cancel()
    time.sleep(1)

# typedef enum {
#     ADC_ATTEN_0DB = 0,
#     ADC_ATTEN_3DB, // 1
#     ADC_ATTEN_6DB, // 2
#     ADC_ATTEN_12DB, // 3
#     ADC_ATTEN_MAX, // 4
# } adc_atten_t;