【发布时间】:2015-07-13 11:57:39
【问题描述】:
我正在尝试使用 IBM Bluemix 平台构建一个 IoT 小型应用程序。我找到了一段 Ryan J Baxter 的视频,它使用 Beagle-bone 将传感器标签连接到 IoT Cloud Foundation。现在,我正在尝试使用 Raspberry Pi 设备而不是 Beagle-Bone 执行相同的程序,遇到了 sensor-tag.js 文件的一些问题,我们无法获取 cfg 参数值,例如 cfg type、cfg org、@987654324 @来自config.properties文件。
我得到了我在注册设备时提供的 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!');
【问题讨论】:
-
请确保您的代码中的括号匹配。
标签: javascript ibm-cloud iot