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

    custom widget: send command to node

    Scheduled Pinned Locked Moved Dashboard
    21 Posts 4 Posters 2.8k 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.
    • W Offline
      wanvo
      last edited by wanvo

      @jkandasa Thanx!
      I checked this widget in Chrome and Firefox, it works great.

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

        I'm just testing out various examples to understand how things work, I'm getting

        Failed at: ${sId}  [in template "unknown" at line 1, column 69]
        
        

        which I assume is from the first line of the html template, its not finding the angularjs custom controller ? I did modify app.js.

        I'm pretty sure I've done all of the above to get the slider to appear on dashboard, but I must of missed something. I pasted the angularjs custom controller into the text field in HTML additional headers.

        Any help 🙂 thanks

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

          @RMF69 To myself... the script binding id mistyped {sId:2}... got the camel case wrong. Slider is now visible but I get 400 error... as I don't have the variable set up correctly which will get updated ? I've created a global variable "sVariable" but I don't think this is right. How do I get the value out of the slider when its value changes ?

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

            @RMF69 Ok looking through code, I understand that its updating a sensor.variabel and that this id is passed in via the script binding {sId:31}... 31 is the id of a sensor S_LIGHT_LEVEL![alt text](Screenshot from 2019-12-28 13-05-08.png
            I still get 400 bad requests... and

            ERROR [Acme.Utils.ThreadPool(0)-PooledThread: Acme.Serve.Serve$ServeConnection@1415568e] [org.mycontroller.standalone.api.jaxrs.exception.mappers.ApplicationExceptionMapper:42] ApplicationException,
            org.jboss.resteasy.spi.ApplicationException: java.lang.NullPointerException
            

            I'd love to understand what I've done wrong:)

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

              @RMF69 Can you report your MyController version? and if you modified the script please report your script.

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

                @jkandasa

                Thanks, I've got the latest, Version 1.5.0. And I've not changed anything, just the script binding {sId:31} where 31 is the id of a light dimmer virtual sensor... see picture. I took the ID from the url of that page in the picture below.Screenshot_2020-01-02_18-31-18.png

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

                  @RMF69 Click on the Edit icon on the Level variable and use the id from the URL.

                  in version 1.5, you no need to hardcode rzModule on mycontroller/www/app.js. We have an option on UI to update angular modules.
                  3482e3a0-d2f2-4189-9f3f-2f4ae7750d72-image.png

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

                    @jkandasa Thanks for confirming that in 1.5, the hardcoding of rzModule in mycontroller/www/app.js isn't required. However if I remove rzModule then the slider widget isn't displayed.

                    Still I can't get the example to work...I've got the id from the place you mention, mine is still 31... I've also noticed that the intial value of the sensor->variable isn't populated. I created simple script to update the value

                    var myImports = new JavaImporter(java.lang, java.util, org.mycontroller.standalone.utils.McUtils);
                    
                    with(myImports) {
                        dimSensor = mcApi.uidTag().getByUid("dimSensor").getResource();
                        var v = dimSensor.value; //value2/3 etc
                        dimSensor.setValue(parseInt(v) + 1);
                        mcApi.sensor().sendPayload(dimSensor);
                    }
                    

                    I insert the following code into "AngularJs custom controllers"

                    myControllerModule.controller('myCustomWidgetController', function($scope, SensorsFactory){
                        $scope.sVariable = {
                          id: null,
                          value:null
                        };
                      
                        $scope.loadVariable = function(){
                          SensorsFactory.getVariable({id:$scope.sVariable.id}, function(response){
                            if(response.value != undefined){
                              $scope.sVariable.value = parseInt(response.value);
                            } 
                          });
                        }
                    
                        $scope.slider = {
                          options: {
                            floor: 0,
                            ceil: 100,
                            step: 1,
                            minLimit: 0,
                            maxLimit: 90,
                            onEnd: function() {
                                $scope.sendPayload($scope.sVariable);
                            },
                          }
                      };
                    
                        // send payload
                        $scope.sendPayload = function(sVariable){
                          SensorsFactory.updateVariable(sVariable, function(){
                            //update Success
                          },function(error){
                            displayRestError.display(error);
                          });
                        };
                      });
                    

                    Which is just the original example above, no changes... it seems to me that the pointer/reference to the variable I want to have connected to the slider is correct or working, both when the value is initialized on the loadVariable and when updated. But I just can't see what I've done wrong.

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

                      @RMF69 Do you see any error on the browser console and/or in MyController log file?

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

                        @jkandasa Sorry... I thought I'd edited or deleted that reply saying it didn't work. It now works... I'd taken the sensor ID from the summary page and not the edit page as you pointed me to in your last reply.

                        So its working now... my mistake, thanks for your patience.

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

                        0

                        Online

                        587

                        Users

                        529

                        Topics

                        3.4k

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