Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paho.mqtt.client as mqtt
- server = "xxxxxxxxx.com"
- port = 1883
- username = "xx"
- password = "xxxxxxxxxxxxxxxxxxxx"
- topic = "temp/f/xxxx"
- client = mqtt.Client(client_id="", clean_session=True, userdata=None, protocol="MQTTv31")
- client.username_pw_set(username, password)
- client.connect(server, port, keepalive=120, bind_address="")
- def read_temperature(device_id):
- "Read float temperature value from 1wire device DS18B20."
- with open('/sys/bus/w1/devices/%s/w1_slave' % device_id) as f:
- text = f.read().strip()
- fragments = text.split()
- return float(fragments[-1][2:]) / 1000.
- time.sleep(10)
- while True:
- client.publish(topic, read_temperature('28-00000531cfff'), qos=1, retain=False)
- print round(read_temperature('28-00000531cfff'),1)
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement