Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################### pub.py
- import time
- import paho.mqtt.client as mqtt
- from sense_emu import SenseHat
- #Publikant wysyla wiadomosc do sieci
- localhost = '127.0.0.1'
- port = 8888
- timeout = 60
- topic_c = "sense/cisnienie"
- topic_t = "sense/temperatura"
- topic_w = "sense/wilgotnosc"
- Qos = 0
- message_payload = "Wiadomosc testowa"
- sense = SenseHat()
- temp = sense.temp
- wilg = sense.humidity
- ci = sense.pressure
- temp_str = str(temp)
- wilg_str = str(wilg)
- ci_str = str(ci)
- def on_connect(client, userdata, flags, rc):
- print("Polaczona; Result code: "+str(rc))
- client = mqtt.Client()
- client.on_connect = on_connect
- client.connect(localhost, port, timeout)
- client.publish(topic_c,ci_str.encode('utf-8'),0)
- client.publish(topic_t,temp_str.encode('utf-8'),0)
- client.publish(topic_w,wilg_str.encode('utf-8'),0)
- #temp_str.encode('utf-8')
- time.sleep(4)
- #client.disconnect()
- #######
- #######
- ############## sub_cis.py
- import paho.mqtt.client as mqtt
- # Sybskrybent nasluchuje wiadomosci o okreslonym temacie
- localhost = '127.0.0.1'
- port = 8888
- timeout = 60
- topic = "sense/cisnienie"
- def on_connect(client, userdata, flags, rc):
- print("Polaczona; Result code: "+str(rc))
- client.subscribe(topic)
- def on_message(client, userdata, msg):
- print(msg.topic+": "+str(msg.payload))
- client = mqtt.Client()
- client.connect(localhost, port, timeout)
- client.on_connect = on_connect
- client.on_message = on_message
- client.loop_forever()
- ####
- ####
- ####
- #### sub_temp.py
- import paho.mqtt.client as mqtt
- # Sybskrybent nasluchuje wiadomosci o okreslonym temacie
- localhost = '127.0.0.1'
- port = 8888
- timeout = 60
- topic = "sense/temperatura"
- def on_connect(client, userdata, flags, rc):
- print("Polaczona; Result code: "+str(rc))
- client.subscribe(topic)
- def on_message(client, userdata, msg):
- print(msg.topic+": "+str(msg.payload))
- client = mqtt.Client()
- client.connect(localhost, port, timeout)
- client.on_connect = on_connect
- client.on_message = on_message
- client.loop_forever()
- ####
- ####
- ###
- ### sub_wilgot.py
- import paho.mqtt.client as mqtt
- # Sybskrybent nasluchuje wiadomosci o okreslonym temacie
- localhost = '127.0.0.1'
- port = 8888
- timeout = 60
- topic = "sense/wilgotnosc"
- def on_connect(client, userdata, flags, rc):
- print("Polaczona; Result code: "+str(rc))
- client.subscribe(topic)
- def on_message(client, userdata, msg):
- print(msg.topic+": "+str(msg.payload))
- client = mqtt.Client()
- client.connect(localhost, port, timeout)
- client.on_connect = on_connect
- client.on_message = on_message
- client.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement