2017-10-09 178 views
0

aws iot javascript sdk有點深奧。 我有一個東西的影子,我只是想讀出來。沒有biggie(我認爲)AWS IOT:讀取影子

我不知道我需要使用什麼功能,只讀出的東西影子數據。 與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); 
}); 

提前感謝!

回答

0

自己修復。要讀出你目前的事情影使用此代碼:

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)); 
});