Updating desired state of AWS device shadow from the device

Hi there,

I’m trying to create a device that can be controlled via the internet. I’d like to use the AWS IOT cloud for that. But this device can also be controlled from local inputs. So for the sake of example let’s say there is a lamp and a button connected to this device. When I push the button I need to turn off/on the light. But I also would like to send a command to turn it off/on from the internet. Device shadow could do this, but I wouldn’t like to keep track of the actual device state. So if there is a connection error and the user sends a “turn off” command from a remote location, but later on (while the connection is still interrupted) someone turns on the light locally, I wouldn’t like to turn it off again, once I receive the shadow delta when the device is reconnected.
The AWS documentation (Mongoose OS Documentation) states that I should be able to send message to the desired channel, to update the desired values instead of the reported. So I thought then upon booting and reconnecting I just send an empty object to the “desired” channel, but this didn’t work. Instead it added it to the reported state.
This is the code that I used:

AWS.Shadow.update(0, {desired: {}});

And the resulting device shadow was this:

{
  "state": {
    "desired": {
      "welcome": "aws-iot",
      "test": "1"
    },
    "reported": {
      "welcome": "aws-iot",
      "desired": {}
    },
    "delta": {
      "test": "1"
    }
  }
}

Am I missing something here?
I was also thinking about not using AWS IOT at all, and only subscribing to an MQTT server and sending non-retained messages, but that way I’ll have to deal with device authentication which would be nice to avoid.

Thanks,
Zoltan

update_ext.

Thanks @nliviu , this is exactly what I was trying with no luck. As you can see, I pass in {desired: {}} to the state, but it doesn’t clear the desired object from AWS. (I also tried to overried existing values, but the result is the same, the passed object will be put in the “reported” object)

The function to use is the one I linked din the previous message update_ext.

Awesome, I failed to notice that there are two functions available, thanks for pointing that out.

Also, on a side note, I think you might want to update the documentation accordingly here:
https://mongoose-os.com/docs/mongoose-os/api/cloud/aws.md
This only mentions the simple “update” function, but states that it can also handle updating the desired object.

Thanks, and have a good day!