How to change "desire" of shadow from the IOT device?

I want to control LED from both the REST API and a button in IOT .
When ever i change the State of the LED, the Cloud send back an “UPDATE DELTA” and then change the LED status back(Which i dont want).

So is there any way to change the “desired” of the shadow from the iot device?

What framework are you using - Mongoose OS, Arduino IDE or ESP-IDF?

Mongoose OS. and i am using NodeMCU ESP8266.

I make a POST request to the Mongoose cloud like this.

HTTP.query({
  url: 'https://mdash.net/api/v2/devices/device2?access_token=xxxxxxxxxxx',
  headers: { 'Content-Type': 'application/json' },
  data: mdata,      // { shadow: { state: { desired: { built_in: boolean}}}}
  cert: 'cert.pem',  // client certificate // just left it if you dont have this file
  key: 'key.pem',  // client key  //just left if you dont has this file
  ca_cert: 'ca.pem',  // ca bundle to verify server with ""
  success: function (body, full_http_msg) { print("body"); },
  error: function (err) { print(err); }
});

“ca.pem” is from https://github.com/mongoose-os-libs/ca-bundle/blob/master/fs/ca.pem

You can use a lower-level dash API:

    mgos_dash_notifyf("Dash.Shadow.Update",
                      "{version: %d, state: {desired: {foo: %d}}}", 0, 123));
1 Like

@lsm
can same be done with JS Api ?
I’ve tried
Shadow.update(0, {“state”: {“desired”: {“foo”: false}}});

Use case is: I want to control a toggle button state both through shadow and through device alarms/timers.

@Martin_Todorov use Dash.notify() instead.

See https://github.com/mongoose-os-libs/dash/blob/master/mjs_fs/api_dash.js