Skip to content

Instantly share code, notes, and snippets.

@tily
Last active July 12, 2016 00:07
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 tily/b579f43697f922068b168dffa46c835c to your computer and use it in GitHub Desktop.
Save tily/b579f43697f922068b168dffa46c835c to your computer and use it in GitHub Desktop.
温湿度センサー DHT11 から取得した情報を一定間隔で Twitter へポスト
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