Example #1
0
from machine import UART, Pin

TX_PIN = 16  # Pin(16) = GP16, pin #21. Green wire - Not required
RX_PIN = 17  # Pin(17) = GP17, pin #22. White wire
BAUD_RATE = 9600

uart = UART(0,
            baudrate=BAUD_RATE,
            tx=Pin(TX_PIN),
            rx=Pin(RX_PIN),
            bits=8,
            parity=None,
            stop=1)

keep_looping = True
while keep_looping:
    try:
        # print("Any: {}".format(uart.any()))
        if uart.any():
            ser_data = uart.read(1)  # 1 byte
            print("Read {} ({})".format(ser_data.decode("ascii"),
                                        ord(ser_data)))

    except KeyboardInterrupt:
        keep_looping = False
        break  # Theorically useless
    except Exception as ex:
        print("Oops {}".format(ex))

uart.close()
Example #2
0
    rlay_3 = data['data']['rlay_3']
    rlay_4 = data['data']['rlay_4']
    relay_status = {
        'rlay_4': data['data']['rlay_4'],
        'rlay_3': data['data']['rlay_3'],
        'rlay_2': data['data']['rlay_2'],
        'rlay_1': data['data']['rlay_1']
    }
    json_str = ujson.dumps(relay_status)
    return json_str


#------------------------------------------------------------------------------------

connect = ConnectionWifi(SSID, PASSWORD)
Post_Status_Sensor()

while True:
    accoun_global = accoun_global + 1
    if (accoun_global >= 110):
        accoun_global = 0
        band_server = 0
        read_json_srvr = Post_Modify_Sensor()
        nano_serial.write(read_json_srvr)  # Le envia el comando  por consola
        print(read_json_srvr)

    sleep(0.5)

nano_serial.close()  # Termina la comunicacion serial arduino
a9g_serial.close()  # Termina la comunicacion serial lector de qr