AWS IOT: How to Read Thing Shadow

Home Forum IoT Software Platforms AWS IoT Development Platform AWS IOT: How to Read Thing Shadow

This topic contains 1 reply, has 2 voices, and was last updated by  Jessica 1 year, 5 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #952

    celina
    Participant

    Hello Everyone,
    The aws iot javascript sdk is a bit abstruse. i have a thing shadow, that i just want to read out. no biggie (i thought)

    i don’t know what functions i need to use, to just read out the thing shadow data. The Connection to AWS works fine, but whatever im trying to do, i don’t receive any data.

    heres my code so far:

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

    #972

    Jessica
    Participant

    Hi Celina,
    Fixed it by myself. To readout your current Thing Shadow use this 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));
    });

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.