IoT Raspberry Pi 传感器标签

IoT Raspberry Pi Sensor Tag

我正在尝试使用 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!');

如果您正在使用 raspberry 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

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