2017-10-09 6 views
0

le aws iot javascript sdk est un peu abstruse. J'ai une ombre de chose, que je veux juste lire. pas de biggie (je pensais)AWS IOT: Lire Thing Shadow

Je ne sais pas quelles fonctions j'ai besoin d'utiliser, pour lire simplement les données d'ombre de chose. La connexion à AWS fonctionne correctement, mais quoi que j'essaie de faire, je ne reçois aucune donnée.

Heres mon code à ce jour:

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

Merci à l'avance!

Répondre

0

Correction par moi-même. Pour lire votre Thing Shadow actuel, utilisez ce code:

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