Watson IoT Platform - MQTT - Node-REDからpub/subする

初めてWatson IoT Platformを使ってみよう、というかたのためのガイドです。
[Watson IoT Platformを使ってみる](http://qiita.com/egplnt/items/af867711a7191923b2ff)でIoTアプリを準備しました。
[MessageSightを動かす](http://qiita.com/egplnt/items/246205f6574cde268712)でMQTTブローカーとしてMessageSightを準備しました。
[Node-REDをローカル環境で稼働させる](http://qiita.com/egplnt/items/39f4794504fc27823bb4)

#Node-REDからpublish/subscribeしてみます
- [Node-REDのフローをコピーする方法](http://qiita.com/egplnt/items/84b244a50d8bdaced324)を参照して以下のフローをコピペします。


```lang:Node-REDからpub/subする
[{"id":"fac58d0f.dee3e8","type":"mqtt-broker","z":"d5a876a5.e9ace8","broker":"172.16.100.100","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"b1ec1387.cd7e8","type":"inject","z":"d5a876a5.e9ace8","name":"","topic":"","payload":"こんにちは","payloadType":"str","repeat":"","crontab":"","once":false,"x":120,"y":80,"wires":[["f65fa076.4979b8"]]},{"id":"11098816.20d498","type":"debug","z":"d5a876a5.e9ace8","name":"","active":true,"console":"false","complete":"false","x":670,"y":80,"wires":[]},{"id":"3ca78e60.54be5a","type":"mqtt in","z":"d5a876a5.e9ace8","name":"","topic":"/topic/test","broker":"fac58d0f.dee3e8","x":500,"y":80,"wires":[["11098816.20d498"]]},{"id":"f65fa076.4979b8","type":"mqtt out","z":"d5a876a5.e9ace8","name":"","topic":"/topic/test","qos":"","retain":"","broker":"fac58d0f.dee3e8","x":310,"y":80,"wires":[]}]

```

- MQTTノードを開き、ローカルのMessageSightのアドレスを指定します。
![スクリーンショット 2016-05-26 11.38.44.png](https://qiita-image-store.s3.amazonaws.com/0/125842/59d394ca-10f1-b4ca-db81-f2dff7e18464.png)

- Node-REDからpublish/subscribeできるようになりました。
![スクリーンショット 2016-05-26 10.57.28.png](https://qiita-image-store.s3.amazonaws.com/0/125842/93c31177-ef92-166c-105d-0ae276da73c2.png)

# Quickstartへpublishする

- 下記のフローでQuickstartへpublishします

```lang:Quickstartへpub
[{"id":"25299f9e.3b6c58","type":"ibmiot in","z":"36890dfe.1ec31a","authentication":"quickstart","apiKey":"","inputType":"evt","deviceId":"001122334455","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT","service":"quickstart","allDevices":"","allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":"","x":250,"y":280,"wires":[["ee533a9b.228c48"]]},{"id":"ee533a9b.228c48","type":"debug","z":"36890dfe.1ec31a","name":"","active":true,"console":"false","complete":"false","x":410,"y":280,"wires":[]},{"id":"9a1895de.b51ed8","type":"mqtt out","z":"36890dfe.1ec31a","name":"","topic":"iot-2/evt/status/fmt/json","qos":"","retain":"","broker":"9ce74b4e.cb3c5","x":450,"y":220,"wires":[]},{"id":"f00fc92.52b2438","type":"inject","z":"36890dfe.1ec31a","name":"","topic":"","payload":"{  \"temp\" : \"25\", \"humidity\" : \"50\"}","payloadType":"str","repeat":"","crontab":"","once":false,"x":250,"y":220,"wires":[["9a1895de.b51ed8"]]},{"id":"9ce74b4e.cb3c5","type":"mqtt-broker","z":"36890dfe.1ec31a","broker":"quickstart.messaging.internetofthings.ibmcloud.com","port":"1883","tls":null,"clientid":"d:quickstart:myThing:001122334455","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""}]

```
 
![スクリーンショット 2016-10-07 18.10.01.png](https://qiita-image-store.s3.amazonaws.com/0/125842/fedcde65-5012-956c-8f7d-e37edf54345a.png)