This is the example code of mqtt.
Last active
April 29, 2018 00:57
-
-
Save naoki-sawada/2781f4d6479a88986853d8afe903fbbb to your computer and use it in GitHub Desktop.
Mqtt demo code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import paho.mqtt.client as mqtt | |
| import time | |
| client = mqtt.Client() | |
| client.connect('localhost', 1883, keepalive=60) | |
| client.loop_start() | |
| while True: | |
| client.publish('/message', 'test') | |
| time.sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import paho.mqtt.client as mqtt | |
| def on_connect(client, userdata, flags, respons_code): | |
| print('connected') | |
| client.subscribe('/message') | |
| def on_message(client, userdata, msg): | |
| print(msg.topic + ' ' + str(msg.payload)) | |
| client = mqtt.Client() | |
| client.on_connect = on_connect | |
| client.on_message = on_message | |
| client.connect('localhost', 1883, keepalive=60) | |
| client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment