1

所以我有一堆 AWS IOT 设备更新/报告它们的状态,但不确定如何从我的 javsascript 客户端订阅报告/接受/增量状态。

我查看了 AWS sdk,但没有看到在 iot 对象中订阅事物影子事件的方法。我可以使用 aws-iot 库,但对如何使用 AWS 凭证有点困惑(因为它不是设备事物客户端)。

在这个用例中,我应该使用 AWS sdk 还是 AWS-IOT sdk?两者有什么区别。如果使用 aws sdk 如何订阅 thingshadow 事件?如果使用 AWS-IOT sdk,我如何使用 aws 凭证而不是证书身份验证?我在示例中没有看到它。

4

2 回答 2

0

到目前为止,我已经采用了这种方法。

Device -> Updates Thing Shadow data
Device -> Sends message to a generic topic with "Thing" id

API -> Listens to the generic topic
API -> Parses message that comes in to the generic topic with "Thing" id
API -> Uses AWS SDK  (AWS IOT Data class) to get the specific "Thing" shadow data

这就是我能够通过代码进行循环的方式。当我经历并尝试构建更好的方法时,我欢迎更多更新。

希望这可以帮助。

-kev

于 2016-09-24T03:45:55.820 回答
0

首先,查找此文档,也许它可以帮助您:

https://github.com/aws/aws-iot-device-sdk-js

当您将某些内容发布到 thingShadow 并且状态被接受时,您可以在频道“$aws/things//shadow/get/accepted”中订阅它。

要订阅此频道,您可以使用设备中的 subscribe 方法。

var AWS = require('aws-sdk');

var device = awsIot.device({
    region: AWS.config.region,
    host:AWSConfiguration.host,
    clientId: clientId,
    protocol: 'wss',
    maximumReconnectTimeMs: 8000,
    debug: true,
    acessKeyId: '',
    secretKey: '',
    sessionToken: ''
  });

device.subscribe('$aws/things/<thingName>/shadow/get/accepted');

如果您感到困惑或需要有关凭据的信息,请查看以下示例:

https://github.com/aws/aws-iot-device-sdk-js/blob/fd0807e20a0d79c721cfb3b85622392f0c65e7e1/examples/browser/mqtt-explorer/index.js

配置文件在同一个文档中。

希望能帮助到你。

于 2018-03-16T19:19:43.907 回答