Widget - Running Sensors
-
@gouds ok, I will the code soon.
-
cheers. It would be a great help.... Thanks
-
I have introduced this feature on latest SNAPSHOT.
Use the following script and template to show only ON switches. You modify filter-options on the script. When you click on HTML table, it will take you to actual sensor page. Where you can control your switch easily.
JavaScript:
var myImports = new JavaImporter(java.io, java.lang, java.util, org.mycontroller.standalone.message.McMessageUtils.MESSAGE_TYPE_SET_REQ); with(myImports) { var options = new HashMap(); //Sort by timestamp. options.put("orderBy", "timestamp"); options.put("pageLimit", new Long(-1)); //Order by descending options.put("order", "desc"); //Update sensor variable type options.put("variableType", MESSAGE_TYPE_SET_REQ.V_STATUS); //Update value options.put("value", "1"); //Get sensors data var sensorVariables = mcApi.sensor().getVariables(options); }
HTML template:
<table class="table table-hover table-bordered table-striped mc-table"> <thead> <th>{{ 'NAME' | translate }}</th> <th>{{ 'LAST_SEEN' | translate }}</th> </thead> <tbody> <#list sensorVariables.data as item> <tr ui-sref="sensorsDetail({id: ${item.sensorId} })"> <td ng-bind-html="'${(item.resourceName)!}' | mcResourceRepresentation"></td> <td><span uib-tooltip="{{ ${(item.timestamp?c)!"Never"} | date:mchelper.cfg.dateFormat:mchelper.cfg.timezone}}" tooltip-placement="left" am-time-ago="${(item.timestamp?c)!"Never"}"></span></td> </tr> </#list> </tbody> </table>
Final result:
-
Thanks very much. This worked a treat.
-
Has something change on the 1,2,0.Final ? This example worked with the previous, but now I get
angular.js:10661 GET https://localhost:8443/mc/rest/templates/getHtml?script=operations%2Flast-seen-nodes.js&scriptBindings=%7B%7D&template=last-seen-nodes.html 400 (Bad request)
I don't have mc in side www... I'm sure I don't understand whats going on or should be
Thanks
-
@rmf69 mc not inside www dir. It is path will be addressed by MyController REST API.
Can you check the template and script available on your MyControlle server? -
@jkandasa sure, if I knew or had a better idea of what I was looking for, the script and template, the ones I've inserted exist... but where do I need to look for rest api ?
-
@rmf69 Can you post your script and template page? Also this widget edit screen?
-
[EDIT] I've answered myself... in the .js there was a filter restriction on
// options.put("variableType", MESSAGE_TYPE_SET_REQ.V_STATUS);
no wonder no sensors where show
[/edit]
Hi I had to re copy the examples at top again, as I'd modified the origional, not a good idea i know if I wanted to fix something.I've re inserted the example js and html template above, and no longer get the error I'd posted however still no sensor variables show.
Here are some screen shots
(
(
(
(
(Thanks again for any help
-
@rmf69 Also you have another filter,
options.put("value", "1");
-
@jkandasa Thanks for that, missed it.