diff options
author | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
---|---|---|
committer | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
commit | 8a89176b2b563ad20c21eea6f31cef01c46582dc (patch) | |
tree | 7e9f0a44e9d52d6ed2e957ca4b524b2fa3b61f6c /mqtt-receiver.py | |
parent | 899ba88b76a2f01b1bab87fbb960c2277435c521 (diff) |
restart
Diffstat (limited to 'mqtt-receiver.py')
-rw-r--r-- | mqtt-receiver.py | 27 |
1 files changed, 0 insertions, 27 deletions
diff --git a/mqtt-receiver.py b/mqtt-receiver.py deleted file mode 100644 index 3d6cd8a..0000000 --- a/mqtt-receiver.py +++ /dev/null @@ -1,27 +0,0 @@ -import json -import paho.mqtt.client as mqtt -import sys - - -def on_connect(client, userdata, flags, rc): - client.subscribe("#") # Subscribe to all topics - sys.stderr.write("Connected with result code {}\n".format(rc)) - sys.stderr.flush() - - -def on_message(client, userdata, msg): - msg_as_str = msg.payload.decode('utf-8') - try: - print("{}\t{}\t{}".format(msg.timestamp, msg.topic, json.loads(msg_as_str))) - sys.stdout.flush() - except Exception as e: - sys.stderr.write("Cannot parse message: '{}'\n".format(msg_as_str)) - sys.stderr.flush() - - -if __name__ == "__main__": - client = mqtt.Client() - client.on_connect = on_connect - client.on_message = on_message - client.connect("localhost", 1883, 60) - client.loop_forever() |