我正在使用Node.js和aws-iot-device-sdk在Raspberry Pi上试用AWS IoT。它连接正常,但是在.subscribe上,它没有调用回调函数。并且发布不发布。请给我指出正确的方向。我还在AWS IoT上创建了一条规则,其中所有来自topic3的数据都重新发布到topic2

var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
    "host": "A3SXXXXXXXXXXX.iot.us-west-2.amazonaws.com",
    "port": 8883,
    "clientId": "MyClientId",
    "thingName": "MyThingName",
    "caCert": "./certs/root-CA.crt",
    "clientCert": "./certs/certificate.pem.crt",
    "privateKey": "./certs/private.pem.key"
});
device
  .on('connect', function() {
    console.log('connected');
    device.subscribe({'topic3':0}, function(error, result) {
	  console.log(error);
      console.log(result);
    });
    device.publish('topic2', JSON.stringify({ test_data: 2}));
  });

最佳答案

您是否在策略中指定了iot:Receive操作?
http://docs.aws.amazon.com/iot/latest/developerguide/policy-actions.html



我遇到了与您从未遇到过的调用回调类似的问题。我的IOT客户端正在发布和订阅同一主题。发布工作正常,但订阅回调从未执行。在将iot:Receive操作添加到同一主题之后,subscribe回调现在可以按预期工作。

关于node.js - 设备订阅AWS IoT上的主题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36915164/

10-12 00:59