Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »





add interpreter module in pycharm

basic python code

http://www.steves-internet-guide.com/into-mqtt-python-client/

basic mqtt code
import time
import paho.mqtt.client as paho
#broker="broker.hivemq.com"
#broker="iot.eclipse.org"
broker="test.mosquitto.org"
broker_port = 1883
#define callback
def on_message(client, userdata, message):
    time.sleep(1)
    print("received message =",str(message.payload.decode("utf-8")))

client= paho.Client("client-001") #create client object client1.on_publish = on_publish #assign function to callback client1.connect(broker,port) #establish connection client1.publish("house/bulb1","on")
######Bind function to callback
client.on_message=on_message
#####
print("connecting to broker ",broker)
client.connect(broker, 1883)#connect
client.loop_start() #start loop to process received messages
print("subscribing ")
client.subscribe("jlk/test/led1")#subscribe
time.sleep(2)
print("publishing ")
client.publish("jlk/test/led1","on")#publish
time.sleep(4)
client.disconnect() #disconnect
client.loop_stop() #stop loop
test: publish from the script

1- connect and subscribe on the mobile App

2- run the script










  • No labels