pub.py import paho.mqtt.client as mqtt from time import sleep import serial ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) if __name__ == '__main__': ### ### 以下、Sango のアカウント情報の定義 ### username = Sango のユーザ名 password = Sango のパスワード host = 'free.mqtt.shiguredo.jp' topic = 'Sango のユーザ名/test_topic' ### ### ### port = 1883 client = mqtt.Client() client.username_pw_set(username, password=password) client.connect(host, port=port, keepalive=60) while 1: # value = random.random() * 100 ser.write('a'); # シリアルへの書き出しコマンド sleep(0.05) value = ser.readline() print '[{}] Sending message to sango.'.format(value) client.publish(topic, '{}'.format(value)) ser.readline() # もしさらに値があれば読み捨て sleep(0.5)