• Categories
    • Recent
    • Tags
    • Popular
    • Register
    • Login

    Widget - Running Sensors

    Scheduled Pinned Locked Moved General Discussion
    14 Posts 3 Posters 4.0k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      gouds @jkandasa
      last edited by

      @jkandasa List sensors that are currently 'ON'

      jkandasaJ 1 Reply Last reply Reply Quote 0
      • jkandasaJ Offline
        jkandasa @gouds
        last edited by

        @gouds ok, I will the code soon.

        1 Reply Last reply Reply Quote 0
        • G Offline
          gouds
          last edited by

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

          jkandasaJ 1 Reply Last reply Reply Quote 0
          • jkandasaJ Offline
            jkandasa @gouds
            last edited by

            @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

            1 Reply Last reply Reply Quote 0
            • G Offline
              gouds
              last edited by

              Thanks very much. This worked a treat. 🙂

              1 Reply Last reply Reply Quote 1
              • R Offline
                RMF69
                last edited by RMF69

                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

                jkandasaJ 1 Reply Last reply Reply Quote 0
                • jkandasaJ Offline
                  jkandasa @RMF69
                  last edited by

                  @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?

                  R 1 Reply Last reply Reply Quote 0
                  • R Offline
                    RMF69 @jkandasa
                    last edited by

                    @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 ?

                    jkandasaJ 1 Reply Last reply Reply Quote 0
                    • jkandasaJ Offline
                      jkandasa @RMF69
                      last edited by jkandasa

                      @rmf69 Can you post your script and template page? Also this widget edit screen?

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        RMF69
                        last edited by RMF69

                        [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
                        (0_1519807954237_scriptedit.png
                        (0_1519807964086_templateedit.png
                        (0_1519807973680_customwidget.png
                        (0_1519807987336_customerwidgetoutput.png
                        (0_1519807997880_topology.png

                        Thanks again for any help

                        jkandasaJ 1 Reply Last reply Reply Quote 0
                        • jkandasaJ Offline
                          jkandasa @RMF69
                          last edited by

                          @rmf69 Also you have another filter,

                            options.put("value", "1");
                          
                          R 1 Reply Last reply Reply Quote 0
                          • R Offline
                            RMF69 @jkandasa
                            last edited by

                            @jkandasa Thanks for that, missed it.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post

                            0

                            Online

                            586

                            Users

                            529

                            Topics

                            3.4k

                            Posts
                            Copyright © 2015-2025 MyController.org | Contributors | Localization