2016年7月11日 星期一
0109temp.js
var watson = require('watson-developer-cloud');
var mqtt = require('mqtt');
var clientId = ['d', "49fhje", "vehicle", "mycar"].join(':');
iot_client = mqtt.connect("mqtt://49fhje.messaging.internetofthings.ibmcloud.com:1883",
{
"clientId" : clientId,
"keepalive" : 30,
"username" : "use-token-auth",
"password" : "yz(GjvSahc95RQ2jEo"
});
var temploop=[ 12, 33, 22, 34, 26, 35, 27];
var i=0;
iot_client.on('connect', function() {
console.log('Temp client connected to IBM IoT Cloud.');
var interval = setInterval(function() {
console.log("temp: " + temploop[i%7]);
iot_client.publish('iot-2/evt/temp/fmt/json', '{"d":{"temp": '+ temploop[i%7] +' }}');
i++;
}, 2000);
}
);
iot_client.subscribe('iot-2/cmd/+/fmt/+', function(err, granted){
console.log('subscribed command, granted: '+ JSON.stringify(granted));
});
iot_client.on("message", function(topic,payload){
console.log('received topic:'+topic+', payload:'+payload);});
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言