javascript – IoT Raspberry Pi传感器标签

我正在尝试使用IBM Bluemix平台构建一个IoT小应用程序.我发现了一个关于Ryan J Baxter的视频,它将传感器标签与Beagle-bone连接到IoT Cloud Foundation.现在我尝试使用Raspberry Pi设备而不是Beagle-Bone进行相同的过程,面对sensor-tag.js文件的一些问题,我们无法获得cfg参数值,如cfg type,cfg org,cfg id来自config.properties文件.

我得到了我在注册设备时给出的mac地址,因为它连接到我的以太网eth0,我给了我的Raspberry Pi mac地址.

    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!');

最佳答案 如果您正在使用覆盆子pi,请查看raspberry pi
https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/的配方

在GitHub上还有raspberry pi的源代码,这可能会有所帮助:https://github.com/ibm-messaging/iot-raspberrypi/

使用配方,您可以将设备信息存储在device.cfg文件中,并在连接时由IoT服务使用.
/etc/iotsample-raspberrypi/device.cfg

编辑添加:查看日志,我看到您使用与您使用的ID不同的ID注册了Raspberry Pi设备.请使用我通过电子邮件发送给您的正确ID注册设备.

点赞