LoginSignup
6
3

More than 5 years have passed since last update.

GolangからMilkcocoaを使う

Last updated at Posted at 2016-12-05

GolangからMilkcocoaを利用するサンプルを探しても見当たらなかったので作ってみました。

MQTTクライアントを使うことで、C言語など様々な言語でMilkcocoaを利用できるようになりました
http://blog.mlkcca.com/iot/milkcocoa-mqtt/

と書いてあるので記事中で紹介されているPahoのGolangクライアントを使って書いてみました。

完成したものがこちらです。
https://github.com/kunihiko-t/milkcocoa-go-mqtt-example

glide installで必要なパッケージをインストールした後にメッセージの送受信ができます。

$ MILKCOCOA_APP_ID=YOUR_APP_ID go run pub/pub.go

Input text and push enter key.
>milk
{"params":{"text":"milk"}}
>cocoa
{"params":{"text":"cocoa"}}
$ MILKCOCOA_APP_ID=YOUR_APP_ID go run main.go

Topic= catiw22khwl/message/push Payload= {"id":"iw81mznpy6AlQEn","ts":1480698470149,"params":{"text":"milk"}}
Text : milk
Topic= catiw22khwl/message/push Payload= {"id":"iw81n2vgP5lBcZn","ts":1480698474316,"params":{"text":"cocoa"}}
Text : cocoa

公式ブログに書かれている通りパラメータを設定すると案外サクッと動いてくれました。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3