Init commit for python scripts
This commit is contained in:
38
mqtt-print-weather.py
Executable file
38
mqtt-print-weather.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import paho.mqtt.client as mqtt #import the client1
|
||||
import time
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
print("message received " ,str(message.payload.decode("utf-8")))
|
||||
print("message topic=",message.topic)
|
||||
print("message qos=",message.qos)
|
||||
print("message retain flag=",message.retain)
|
||||
|
||||
client.publish("home/scroller","ZVONI");
|
||||
|
||||
|
||||
def print_time(format='%H:%M'):
|
||||
t = time.strftime(format)
|
||||
print("format time = ",format," ",t)
|
||||
client.publish("home/scroller",t);
|
||||
|
||||
broker_address="172.16.1.254"
|
||||
#broker_address="iot.eclipse.org"
|
||||
print("creating new instance")
|
||||
client = mqtt.Client("NUC-client-home") #create new instance
|
||||
print("connecting to broker")
|
||||
client.connect(broker_address) #connect to broker
|
||||
print("Subscribing to topic","home/bell/ring")
|
||||
client.subscribe("home/bell/ring")
|
||||
|
||||
client.on_message=on_message
|
||||
client.loop_start()
|
||||
|
||||
print_time()
|
||||
|
||||
client.loop_stop()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user