def runServer():
    caldera_test.checkCaldera()

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 80))
    s.listen(5)

    while True:
        print('Esperando conexiones')
        conn, addr = s.accept()
        try:
            print(myDateTime.getLocalTimeHumanFormat() +
                  ' Conexion desde %s' % str(addr))
            conn.settimeout(5)
            request = conn.recv(1024)
            request = str(request)
            # print('Contenido = %s' % request)
            rele_on = request.find('/?rele=on')
            rele_off = request.find('/?rele=off')
            if rele_on == 6:
                caldera_test.enciendeCaldera()
            if rele_off == 6:
                caldera_test.apagaCaldera()
            print('Caldera ', caldera_test.checkCaldera())
            response = web_page()
            conn.send('HTTP/1.1 200 OK\n')
            conn.send('Content-Type: text/html\n')
            conn.send('Connection: close\n\n')
            conn.sendall(response)
            conn.close()
            print('Close socket')
        except:
            print('Timeout!!')
        print(helpFiles.free())
Ejemplo n.º 2
0
def sub_CheckTopics(topic, msg):
    print((topic, msg))
    if topic == topic_subLed:  # Check for Led Topic
        if msg == b'On':
            print('Led:On')
            led.off()
        else:
            print('Led:Off')
            led.on()
    elif topic == topic_subFree:  ## Check for free memory
        freeMem = helpFiles.free()
        client.publish(topic_subMem, str(freeMem))
Ejemplo n.º 3
0
def sub_CheckTopics(topic, msg):
    print((topic, msg))
    if topic == topic_subLed:     # Check for Led Topic
        if msg == b'On':
            print('Led:On')
            led.off()
        else:
            print('Led:Off')
            led.on()
    elif topic == topic_subLedRGB:      ## Check for RGB Topic
        ledRGB[0]=NeoPixelTHO.colorByName(msg)
        ledRGB.write()
    elif topic == topic_subFree:        ## Check for free memory
        freeMem = helpFiles.free()
        client.publish(topic_subMem, str(freeMem))
Ejemplo n.º 4
0
def sub_CheckTopics(topic, msg):
    global client
    try:
        myLog("MQTT < " + str(topic.decode("utf-8")) + ':' +
              str(msg.decode("utf-8")))
        if topic == topic_subCaldera:  # Check for Led Topic
            if msg == b'On':
                caldera_test.enciendeCaldera()
            else:
                caldera_test.apagaCaldera()
            showSetCalderaStatus()
        elif topic == topic_subFree:  ## Check for free memory
            freeMem = helpFiles.free()
            publicaMQTT(topic_subMem, str(freeMem))
    except KeyboardInterrupt:
        pass
    except Exception as e:
        myLog('Error checking topics>' + str(e))