前回はNode-REDを使ってCloudMQTTに繋ぎました。 今回はPython3を使って繋いでみました。 オリジナルはここです 。 # Nov/27/2018 # # ------------------------------------------------------------------ import sys from time import sleep import paho.mqtt.client as mqtt # ------------------------------------------------------------------ sys.stderr.write("*** 開始 ***\n") host = 'Server name' port = xxxxx topic = 'topic_1' client = mqtt.Client(protocol=mqtt.MQTTv311) client.username_pw_set('User', 'Password') client.connect(host, port=port, keepalive=60) client.publish(topic, 'Good Afternoon!!') sleep(0.5) client.publish(topic, 'こんにちは') client.disconnect() sys.stderr.write("*** 終了 ***\n") # ------------------------------------------------------------------ ※ host = 'Server name' port = xxxxx client.username_pw_set('User', 'Password') は適宜変更を要します。 以上を実行させると こんな感じに出力されます。 以上