Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

  • Hi Tech Supporter,

    Could you please help on this?

    Could we disable/enable a data point by REST API? We checked http://help.infiniteautomation.com/support/solutions/articles/14000027309-explore-the-api and saw there is API to add/delete a data point but we want to enable/disable a point by API.

    Thanks

    Mebius


  • Hi Mebius,

    Of course! A data point has the "enabled" property in its JSON, so you can use the update data point endpoint (The PUT request) to enable or disable a point.

    0_1481563490433_putEndpoint.png


  • @phildunlap thank you very much!


  • @phildunlap said in Can we enable/disable a data point by REST API?:

    Hi Mebius,

    Of course! A data point has the "enabled" property in its JSON, so you can use the update data point endpoint (The PUT request) to enable or disable a point.

    0_1481563490433_putEndpoint.png

    @phildunlap

    We tried according to http://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication , and it worked well on browser but we were not able to authenticate to MA with other web-tools like "curl" at step-1:

    1, GET /login/admin with the header password=admin

    Is the step like this?
    GET /login/admin?password=admin HTTP/1.1

    Thanks

    Mebius


  • 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:
    0_1482510729297_getPoint.png

    You can see the point has enabled = true in the response body. We can confirm that looking at the data point's page:
    0_1482510786434_pointsEnabled.png

    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
    0_1482511210793_putPoint.png

    It can be confirmed on the data point's edit page:
    0_1482511230646_pointDisabled.png


  • 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.