Beispiel #1
0
inputs = []
outputs = []

# main select loop
while r_socks:
    w_socks = []
    if mqtt_client.want_write():
        w_socks += [mqtt_sock]
    if not esp_write_queue.empty():
        w_socks += [esp_sock]
    inputs, outputs, errors = select.select(r_socks, w_socks, r_socks, 0.01)
    if len(errors) > 0:
        logging.error("Socket error while executing select")

    if mqtt_sock in inputs:
        rc = mqtt_client.loop_read()
        mqtt_lib.read()
        if rc or mqtt_sock is None:
            logging.error("mqtt read error")

    if mqtt_sock in outputs:
        rc = mqtt_client.loop_write()
        if rc or mqtt_sock is None:
            logging.error("mqtt write error")

    if esp_sock in inputs:
        rc = esp_lib.read(esp_sock, esp_write_queue)
        if rc != 0:
            logging.error("esp socket read error")

    # update esp time