Raspi2続き
サンデープログラミングとして、Raspi2オンチップの温度センサーを読んでtwitterに書く、というのをやってみた。
温度センサーは /sys/class/thermal/thermal_zone0/temp を読むと100倍した値が返ってくる。
twitterに書くのは Tweeting Babbage | Raspberry Pi Learning Resources にあるとおり、pythonのTwythonモジュールを使うのが手っ取り早い。
from twython import Twython from auth import ( consumer_key, consumer_secret, access_token, access_token_secret ) twitter = Twython( consumer_key, consumer_secret, access_token, access_token_secret ) def main(): f = open("/sys/class/thermal/thermal_zone0/temp", "r") for t in f: message = "my temperature is " + t[:2] + "." + t[2:5] + "C right now" twitter.update_status(status=message) if __name__ == '__main__': main()