我正在嘗試使用IBM Bluemix平臺構建物聯網小應用程序。我發現了一個Ryan J Baxter的視頻,將傳感器標籤連接到物聯網雲基礎上,並帶有Beagle-bone骨架。現在,我正在嘗試使用Raspberry Pi設備而不是Beagle-Bone執行相同的過程,在sensor-tag.js
文件面臨一些問題時,我們無法從config.properties
文件中獲取像cfg type
,cfg org
,cfg id
這樣的cfg參數值。物聯網Raspberry Pi傳感器標籤
我得到了我在註冊設備時給予的mac地址,我給了我的Raspberry Pi mac地址,因爲它連接到我的以太網eth0
。
if(cfg.id != deviceId) {
console.warn('The device MAC address does not match the ID in the configuration file.');
}
//------------- This is where I'm facing a problem --------
var clientId = ['d', cfg.org, cfg.type, cfg.id].join(':');
var client = mqtt.connect("mqtts://" + cfg.org +
'.messaging.internetofthings.ibmcloud.com:8883',
{
"clientId" : clientId,
"keepalive" : 30,
"username" : "use-token-auth",
"password" : cfg['auth-token']
});
client.on('connect', function() {
console.log('MQTT client connected to IBM IoT Cloud.');
});
client.on('error', function(err) {
console.log('client error' + err);
process.exit(1);
});
client.on('close', function() {
console.log('client closed');
process.exit(1);
});
monitorSensorTag(client);
});
});
function monitorSensorTag(client) {
console.log('Make sure the Sensor Tag is on!');
請確保您的代碼中的括號相符。 – Ram