a += 1
        if on:
            l = 1
        else:
            l = 0
        light = {
            "bn": "control",
            "e": [{
                "n": "led",
                "t": time.time(),
                "v": l,
                "u": None
            }]
        }

        Publish.myPublish("/tiot/17/house/control/light", json.dumps(light))
        if on:
            t = "acceso"
        else:
            t = "spento"
        text = {
            "bn": "Control",
            "e": [{
                "n": "screen",
                "t": time.time(),
                "v": t,
                "u": None
            }]
        }
        Publish.myPublish("/tiot/17/house/control/screen", json.dumps(text))
        fan, heat = control()
Ejemplo n.º 2
0
    if U<40:#se umidità nel terreno è minore del 40% accendo la pompa dell'acqua
        pump=True
    elif U>85:# se umidità maggiore dell'85% spengo la pompa
        pump=False
    return pump,light,temp

if __name__ == "__main__":
    sendData()
    broker=requests.get('http://localhost:8080/broker/')
    broker=broker.json()
    s='http://localhost:8080/device/one?ID=serra'
    topic=requests.get(s)
    topic=topic.json()
    sensorSub=Subscriber("sensor",broker,topic['endPoint'], ReceivedData)
    
    Publish = Publisher("pub",broker)
    sensorSub.start()

    Publish.start()
    a = 0
 
    while (a < 100):
        a += 1
        print(dic)
        Publish.myPublish("/tiot/17/serra/control",json.dumps(dic))
        time.sleep(10)
    sensorSub.stop()
    
    Publish.stop()