Controlling the home

Finally, using the following diagram, make the connections and upload the following code:

import timeimport paho.mqtt.client as pahoimport RPi.GPIO as GPIOGPIO.setmode(GPIO.BCM)GPIO.setup(14,GPIO.OUT)broker="broker.hivemq.com"sub_topic = light/controlclient = paho.Client()def on_message(client, userdata, message):    print('message is : ')    print(str(message.payload))    data = str(message.payload)    if data == "on":        GPIO.output(3,GPIO.HIGH)    elif data == "off":        GPIO.output(3,GPIO.LOW)def on_connect(client,userdata, flag, rc):    print("connection returned" + str(rc))    client.subscribe(sub_topic)client.connect(broker,port)client.on_connect ...

Get Python Robotics Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.