Can we enable/disable a data point by REST API?
-
The first version should have worked. Did you get back a Set-Cookie header with the session cookie? You can compare the messages sent from swagger to those in your curl commands if you open the developer tools in your browser (right click, inspect element) and watch the requests on the Network tab.
-
Any chance someone could put together a quick example on how to update an existing data point property (like enabled) via the PUT request using the REST API? I'm just a bit lost..
-
Hi DieselD,
I'm using swagger in these images. Swagger can be enabled by having "swagger.enabled=true" in your env.properties file when Mango boots. You can open up the developer tools for your browser while you are using swagger if you wish to see the exact messages being sent in making the REST calls.
Step 1, get the JSON for the point's model:
You can see the point has enabled = true in the response body. We can confirm that looking at the data point's page:
Step 2, copy the JSON model from that response body into the request body on the PUT /v1/data-points/{xid} endpoint just below it. Change "enabled":true to "enabled":false, supply the XID into the field that asks for it and hit the "Try it out" button. You should get a response code 200 with "enabled":false
It can be confirmed on the data point's edit page:
-
I got that.. I'm looking for how to do it in HTML/JS, so it can be changed via the dashboard.
-
Have you had a look at this page:
http://localhost:8080/dashboards/examples/setting-point-values/set-point
Assuming you are looking to set a points value from a dashboard in HTML you can use our HTML constructs to build a dashboard and do many things such as this easily
If you are looking to alter a data points properties , I don't think we have a component to do that. You would have to write JS but it I believe it could be done using:
http://localhost:8080/dashboards/docs/ma-services/point -
Yeah.. though i don't think that works with setting other things like 'enabled', unless I'm wrong? When I do try it, the Set button gets grayed out.
I figured out how to read it directly just doing something as simple as:<ma-point-list limit="100" ng-model="myPoint2"></ma-point-list> <button type="submit" class="btn btn-default" ng-click="myPoint2.$get()">Submit</button> <pre><code>{{myPoint2.enabled}}</code></pre>
get figure out how to set it though.
-
ok.. im not the best with JS as I'm still figuring out.. I thought I'd ask hoping there would be an easier way then writing up new code to do it.
-
Hi DieselD,
Here's some pure javascript to toggle a point, if that's helpful:
<script>function togglePoint( dataPointXid ) { var getPoint = new XMLHttpRequest(); getPoint.addEventListener('load', function() { //Consider returning if empty response text var point = JSON.parse( this.responseText ); point.enabled = !point.enabled; var putPoint = new XMLHttpRequest(); putPoint.open('PUT', '/rest/v1/data-points/'+point.xid, true); putPoint.setRequestHeader( 'X-XSRF-TOKEN', /XSRF-TOKEN=(.*?);/.exec(document.cookie)[1] ); putPoint.setRequestHeader( 'Accept', 'application/json' ); putPoint.setRequestHeader( 'Content-Type', 'application/json' ); putPoint.send(JSON.stringify(point)); }); getPoint.open('GET', '/rest/v1/data-points/'+dataPointXid, true); getPoint.setRequestHeader( 'X-XSRF-TOKEN', /XSRF-TOKEN=(.*?);/.exec(document.cookie)[1] ); getPoint.setRequestHeader( 'Accept', 'application/json' ); getPoint.send(); }; togglePoint("DP_819223");</script>
This can be used on one of the custom dashboards. If you're going to use it elsewhere, be sure to supply the Cookie header with the value of the cookie you get when you log in, and also to run the regex against that cookie instead of document.cookie
-
Using Phillips method should work but it is a bit tricky to use custom javascript with the new dashboards. We are focusing on providing HTML constructs but don't support updating a point's property from the new UI yet.
What exactly are you trying to accomplish? You use a binary data point and toggle it's value to true/false in combination with a meta data point to accomplish some pretty complex logic.
-
Well I really wasn't trying to use the enable, but it was a good starting point. I want to be able to change the modbus slave id from the dashboard for a set of data points. Essentially I have six identical modbus units that all send identical data points (different values). If one of the units is replaced with another unit with a different slave id, I want to easily change it without having to go into the data points and change them all.
I realize i could also change the id on the unit itself but didn't really want to do that and get them mixed up. -
I may just say screw it at this point! though I usually am too stubborn to give up on dumb things like this
-
You could easily use my example, you would need to be modifying point.pointLocator.slaveId, then just
var modbusPointXids = ["DP_1", "DP_2" ... ]; for(var k = 0; k < modbusPointXids.length; k+=1) { //This function looks a lot like the toggle point function I provided. changePointSlaveId( modbusPointXids[k] ); }
Ultimately I do think that's the wrong idea, though. If you save the point with a different slave ID, then the history for the old slave ID will persist in the points. Perhaps you do desire that?
I would probably solve that problem by exporting the set of points I was interested in or the data source, then doing find and replace on the slaveId and the XID such that you create new points for the new slave. If you construct your XIDs so that they encode information like your slaveID, then you can filter on that or dynamically link the page by changing the slave ID number in the XIDs of the various requests you're making.
-
Thanks.. you make a good point there. I may have to rethink how I'm doing this...
-
In my option it would be best practice to set the Slave ID of a replacement Modbus device the same as the one it's replacing.
Also, it's really easy to change the slave ID of a set of points be either exporting all the points as JSON or csv. Making the change with a find and replace or in Excel and then importing them on the Configuration Import / Export page.