aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

thingShadow.on status not showig updates #273

Closed borch84 closed 5 years ago

borch84 commented 5 years ago

Hi, I am running an example with thingShadow, so far I can connect to my thingShadow and get deltas updates but when there is an update to the shadow document I don't see any data coming into my console. This is the code I've been using:

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

var esp32reeswitchShadow = awsIot.thingShadow({
   keyPath: './esp32reedswitch-certs/private.pem.key',
  certPath: './esp32reedswitch-certs/certificate.pem.crt',
    caPath: './esp32reedswitch-certs/aws-root-ca.pem',
  clientId: 'nodejsclient',
      host: 'a3s8lktlbmjbgn-ats.iot.us-east-1.amazonaws.com'
});

esp32reeswitchShadow.on('connect', function() {
  console.log('nodejsclient conectado!')
  esp32reeswitchShadow.register('esp32reedswitch',{},function() {
    console.log('Registrado al shadow de: esp32reedswitch');
  })
}); 

    esp32reeswitchShadow.on('status', 
      function(thingName,stat,clientToken,stateObject) {
        console.log('received '+stat+' on '+thingName+': '+
                       JSON.stringify(stateObject))

      });

esp32reeswitchShadow.on('delta', 
  function(thingName, stateObject) {
     console.log('received delta on '+thingName+': '+
                 JSON.stringify(stateObject));
  });

When I run this node js script I can only see deltas messages, but if I update the shadow document from the console I don't get update status messages.

This is the only output from the console:

$ node webpush-server2.js 
nodejsclient conectado!
Registrado al shadow de: esp32reedswitch
received delta on esp32reedswitch: {"version":23202,"timestamp":1558658015,"state":{"windowOpen":true},"metadata":{"windowOpen":{"timestamp":1558658015}}}
justinboswell commented 5 years ago

This is expected behavior, if a bit unintuitive. When you subscribe to the delta event, you will only get the delta section of the shadow document. If you want the entire document, you will need to use GetThingShadow.

As for the web interface, it will only show the delta section of the document if the last command produced a delta, so for instance if you were to do an update then you would see the delta section in the web interface until another publish which changes the shadow state is delivered.