Disable Things from DSL

In my installation I have 2 sets of modbus devices, set A and set B.

Set A power is backed up by an UPS. Set B isn’t.

When power is cut off (due to storms, for example), the requests for set B start to pile up and make a delay on the requests of set A also.

To overcome this, when power is lost, I’d like to disable all the things related to set B.

My first thought would be using the REST API to disable the things:

  1. Get the list of all the things
  2. Filter the ones from set B
  3. Disable them

My doubts:

  • Is there some way from DSL to disable/enable things?
  • Can I iterate a json object from DSL?

Thanks for the help.

To disable a thing from DSL use this

sendHttpPutRequest("http://IPADDRESS:8080/rest/things/THING:THING/enable", "application/json", 'false', 5000)

Well, this is not usable if you have authentication enabled. Or better to say it is, but you need to add the authentication header with valid token, which is changing quite often.

  var headers = new java.util.HashMap();
  headers.put("Authorization", "Bearer " + token);
  sendHttpPutRequest("http://IPADRESS:8080/rest/things/THING:THING/enable", "text/plain", 'false', headers, 5000);

Any idea how to get a valid token in a dsl script to not be forced to update it daily?

Did you create a token?

Nope, that’s a very good point. I was using the token captured from headers used by browser, but as said before, it changes every 24 hours or so. Thanks for the link!

Create a token and it will last until you delete it

1 Like