我正在尝试使用 IBM Bluemix 平台构建一个 IoT 小型应用程序。我找到了 Ryan J Baxter 的一段视频,介绍如何使用 Beagle-bone 将传感器标签连接到 IoT Cloud Foundation。现在,我正在使用 Raspberry Pi 设备而不是 Beagle-Bone 尝试相同的过程,但遇到了 sensor-tag.js
的一些问题。文件我们无法获得类似 cfg type
的 cfg 参数值, cfg org
, cfg id
来自 config.properties
文件。
我得到了我在注册设备时提供的 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!');
最佳答案
如果您使用的是树莓派,请查看树莓派的配方 https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/
GitHub 上还有树莓派的源代码,可能会有帮助:https://github.com/ibm-messaging/iot-raspberrypi/
使用配方,您将设备信息存储在 device.cfg 文件中,并在您连接时由 IoT 服务使用。 /etc/iotsample-raspberrypi/device.cfg
编辑添加:查看日志,我看到您使用与您使用的 ID 不同的 ID 注册了 Raspberry Pi 设备。请使用我通过电子邮件发送给您的正确 ID 注册设备。
关于javascript - IoT Raspberry Pi 传感器标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31382760/