• header.categories
    • header.recent
    • header.tags
    • header.popular
    • register
    • login

    Widget - Running Sensors

    scheduled pinned locked moved General Discussion
    14 posts 3 posters 4.7k views 2 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • jkandasaJ offline
      jkandasa @gouds
      global:last-edited-by,

      @gouds ok, I will the code soon.

      one-reply-to-this-post last-reply-time reply quote 0
      • G offline
        gouds
        global:last-edited-by,

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

        jkandasaJ one-reply-to-this-post last-reply-time reply quote 0
        • jkandasaJ offline
          jkandasa @gouds
          global: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

          one-reply-to-this-post last-reply-time reply quote 0
          • G offline
            gouds
            global:last-edited-by,

            Thanks very much. This worked a treat. 🙂

            one-reply-to-this-post last-reply-time reply quote 1
            • R offline
              RMF69
              global: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 one-reply-to-this-post last-reply-time reply quote 0
              • jkandasaJ offline
                jkandasa @RMF69
                global: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 one-reply-to-this-post last-reply-time reply quote 0
                • R offline
                  RMF69 @jkandasa
                  global: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 one-reply-to-this-post last-reply-time reply quote 0
                  • jkandasaJ offline
                    jkandasa @RMF69
                    global:last-edited-by, jkandasa

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

                    one-reply-to-this-post last-reply-time reply quote 0
                    • R offline
                      RMF69
                      global: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 one-reply-to-this-post last-reply-time reply quote 0
                      • jkandasaJ offline
                        jkandasa @RMF69
                        global:last-edited-by,

                        @rmf69 Also you have another filter,

                          options.put("value", "1");
                        
                        R one-reply-to-this-post last-reply-time reply quote 0
                        • R offline
                          RMF69 @jkandasa
                          global:last-edited-by,

                          @jkandasa Thanks for that, missed it.

                          one-reply-to-this-post last-reply-time reply quote 0
                          • first-post
                            last-post

                          0

                          online

                          644

                          users

                          532

                          topics

                          3.4k

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