Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created October 17, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laclefyoshi/13934655b006ffdde42d to your computer and use it in GitHub Desktop.
Save laclefyoshi/13934655b006ffdde42d to your computer and use it in GitHub Desktop.
MQTTブローカからのメッセージを表示
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt_client
topic = "MESHBLU_ACTION_UUID"
def on_connect(client, userdata, flags, rc):
print("connected with result code" + str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received message: " + str(msg.payload) + " from " + msg.topic)
client = mqtt_client.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set("MESHBLU_ACTION_UUID", "MESHBLU_ACTION_PASS")
client.connect("MESHBLU", 1883, 60)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment