javascript - AWS 物联网 : Read Thing Shadow

标签 javascript node.js amazon-web-services aws-iot

aws iot javascript sdk 有点深奥。 我有一个影子,我只想读出来。没什么大不了的(我认为)

我不知道我需要使用什么功能,只是读取事物影子数据。 与 AWS 的连接工作正常,但无论我尝试做什么,我都没有收到任何数据。

到目前为止,这是我的代码:

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

var name = 'Testthing';

var shadow = awsIot.thingShadow({
   keyPath: 'cert/privkey.pem', 
  certPath: 'cert/cert.pem',
    caPath: 'cert/rootCA.crt',
  clientId: "testapp",
      host: "xxx"
});


shadow.on('connect', function() {
  shadow.register('Testthing'); 
});

shadow.get(name, data) { // something like this..
  console.log(data);
});

提前致谢!

最佳答案

自己修好了。要读出您当前的 Thing Shadow,请使用此代码:

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

var thingShadows = awsIot.thingShadow({
   keyPath: 'cert/privkey.pem', 
  certPath: 'cert/cert.pem',
    caPath: 'cert/rootCA.crt',
  clientId: "YourAppName",
      host: "YourHostLink"
});



thingShadows.on('connect', function() {
    thingShadows.register(name, {}, function() {
       thingShadows.get(name);
    });
});

thingShadows.on('status',  function(name, stat, clientToken, stateObject) {
  console.log('received '+stat+' on '+name+': '+JSON.stringify(stateObject));
});

关于javascript - AWS 物联网 : Read Thing Shadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46643293/

相关文章:

node.js - 在 Node js : Zapier 中解析 XML

web-services - 大型组织是否使用亚马逊网络服务?

amazon-web-services - 执行 Terraform apply 并承担 AWS 角色

javascript - 每次调用时在 sinon 中插入一个函数以返回不同的值

javascript - Typescript 通用 通用

node.js - MongoDB 中集合级别的数据库池?

amazon-web-services - 在 amazon ec2 linux 2 上安装 php-imap

javascript - 如何构造一个js对象并用js_of_ocaml调用它的方法?

javascript - 转换不适用于使用 CSS 和 JS 提交的输入类型

javascript - 如何在专用服务器上配置我的 Node.js 应用程序以使其上线?