【问题标题】:AWS IOT JS device SDK not connecting and keep on reconnecting again and againAWS IOT JS 设备 SDK 未连接并不断重新连接
【发布时间】:2018-03-16 21:20:14
【问题描述】:
var awsIot = require('aws-iot-device-sdk');
var uuid = require('uuid');
var device = awsIot.device({
    keyPath: "<path>-private.pem.key",
    certPath: "<path>-certificate.pem.crt",
    caPath: "<path>-root-CA.key",
    clientId: uuid.v4(),
    debug:true,
    host: <hostId>,
    will:{
        topic:"blahblahblah",
        payload:"disconnecting",
        qos:0,
        retain:false
    }
});

device
    .on('connect', function() {
        console.log('connect');
        device.subscribe('cgw/devices/register');
    });

device.on('message', (topic, payload, message) => {
    console.log(topic);
    console.log(payload);
    console.log(message);
});

   device
      .on('close', function() {
         console.log('close');
      });
   device
      .on('reconnect', function() {
         console.log('reconnect');
      });
   device
      .on('offline', function() {
         console.log('offline');
      });
   device
      .on('error', function(error) {
         console.log('error', error);
      });

我正在尝试运行上面的示例代码,但设备未连接。我也试过通过

保留参数为假

根据https://github.com/aws/aws-iot-device-sdk-js/issues/61

但程序仍然没有运行并显示

离线 关闭 重新连接 关闭 重新连接 关闭 重新连接 关闭 重新连接

【问题讨论】:

  • 伙计们,我找到了答案。附加到证书的策略 ARN 应包含“Action”:[“iot:Publish”、“iot:Subscribe”、“iot:Connect”],

标签: javascript node.js aws-iot


【解决方案1】:

分配给身份/设备的策略似乎没有提供对 AWS IoT 代理的正确访问。因此,为了连接、发布、订阅和接收来自 AWS 代理的数据,相应的策略应包含以下语句:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": [
        "PUT YOU CLIENT RESOURCE HERE"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "iot:Publish",
      "Resource": [
        "PUT YOUR TOPIC RESOURCE HERE"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "iot:Subscribe",
      "Resource": [
        "PUT YOUR TOPIC/FILTER RESOURCE HERE"
      ]
    },
    {
      "Effect": "Allow",
      "Action": "iot:Receive",
      "Resource": [
        "PUT YOUR TOPIC RESOURCE HERE"
      ]
    }
  ]
}

【讨论】:

    猜你喜欢
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多