Widget - Running Sensors



  • Dashboard Item - List all running sensors. Anyone done anything? (Just a nice table to show a list)


  • ADMIN

    @gouds said:

    Dashboard Item - List all running sensors. Anyone done anything? (Just a nice table to show a list)

    What does mean running sensors?



  • @jkandasa List sensors that are currently 'ON'


  • ADMIN

    @gouds ok, I will the code soon.



  • cheers. It would be a great help.... Thanks


  • ADMIN

    @gouds

    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:

    0_1483983879371_upload-4f120fca-8861-4343-a39f-bd1fd0d74822



  • Thanks very much. This worked a treat. :)


Log in to reply