Last active
July 12, 2016 00:07
-
-
Save tily/b579f43697f922068b168dffa46c835c to your computer and use it in GitHub Desktop.
温湿度センサー DHT11 から取得した情報を一定間隔で Twitter へポスト
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
package main | |
import ( | |
"github.com/d2r2/go-dht" | |
"github.com/ChimeraCoder/anaconda" | |
"fmt" | |
"time" | |
) | |
func main() { | |
anaconda.SetConsumerKey("your consumer key") | |
anaconda.SetConsumerSecret("your consumer secret") | |
api := anaconda.NewTwitterApi("your access token", "your access token secret") | |
for true { | |
temperature, humidity, retried, _ := dht.ReadDHTxxWithRetry(dht.DHT11, 4, true, 10) | |
tweet := fmt.Sprintf("Temperature = %v*C, Humidity = %v%% (retried %d times) %s\n", temperature, humidity, retried, time.Now()) | |
api.PostTweet(tweet, nil) | |
time.Sleep(time.Second * 60 * 30) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment