【问题标题】:IoT Raspberry Pi Sensor TagIoT Raspberry Pi 传感器标签
【发布时间】: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 typecfg 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


【解决方案1】:

如果您使用的是树莓派,请查看树莓派的配方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 注册了 Raspberry Pi 设备。请使用我通过电子邮件发送给您的正确 ID 注册设备。

【讨论】:

  • 是的。它之前已经完成,但我希望我的传感器标签使用 Raspberry Pi 连接到 IoT Cloud。如果我必须这样做,我必须以注册模式连接我的树莓派,是吗??
  • 您是否将树莓派注册到 IoT 基金会?它要求 mac 地址是小写的,没有冒号。
  • 如果你让我知道你的组织,我会检查 IoT 日志,看看我是否能找到你的连接错误。
  • 我将我的树莓派注册到 IoT Foundation mac 地址是完美的。但它没有连接到物联网云,也没有发布任何数据。
  • 我看到此错误 2015-07-15T12:21:16 令牌验证失败(设备不存在):ClientID='d:rpwtjr:Raspberrypi:您的组织显示注册设备“pi”和具有相同 ID 的“Raspberrypi”。您是不是最近才添加了 Raspberrypi 名称?
猜你喜欢
  • 1970-01-01
  • 2017-02-07
  • 2013-07-15
  • 1970-01-01
  • 1970-01-01
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 2018-02-22
相关资源
最近更新 更多