我正在使用Node.js和aws-iot-device-sdk尝试使用我的Raspberry Pi进行AWS IoT.它连接正常,但是.subscribe它没有调用回调函数.并且发布不发布.如果你能指出我正确的方向,请.我还在AWS IoT上创建了一条
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:在策略中接收操作?
http://docs.aws.amazon.com/iot/latest/developerguide/policy-actions.html
iot:Receive
Represents the permission to receive a message from AWS IoT. The iot:Receive permission is checked every time a message is delivered to a client. Because this permission is checked on every delivery, it can be used to revoke permissions to clients that are currently subscribed to a topic.
我遇到的问题与从未调用过订阅回调的问题类似.我的IOT客户端正在发布和订阅相同的主题.发布工作但订阅回调从未执行过.将iot:Receive操作添加到同一主题后,订阅回调现在按预期工作.