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/