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()
Ejemplo n.º 3
0
print("Connected to Wifi\n")
client = MQTTClient(client_id="6073",
                    server="mqtt.opensensors.io",
                    user="******",
                    password="******",
                    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)