• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Http sender 3th party

    How-To
    4
    12
    3.6k
    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.
    • phildunlapP
      phildunlap
      last edited by

      Hi Mark,

      I think you'll run into trouble trying to use the HTTP sender for this, since you need total control of the parameter names and values.

      I see two possible solutions,
      1.
      You could definitely send those messages out of a TCP/IP data source, though. What I would do is create a TCP/IP data source like this,

      host: 192.168.178.100
      port: 8081
      delimiter:
      configuration in hex: false
      

      and a data point like,

      data type: Alphanumeric
      queryable: false
      read command:
      settable: true
      write command: GET /json.htm?%VALUE% HTTP/1.1\nHost: 192.168.178.100:8081\n\n
      

      You may need to add some more headers into the HTTP GET in the write command. You'll have to figure that out testing against the other device, but it sounds like you can get a working set of headers by checking the GET sent by your browser when you put it in the URL.

      Next we'll set up a virtual alphanumeric point to set values to, and for simplicity let's say that point is set with values like, "6-On". Since this data source will only be used for user input, let's disable polling on its virtual data source.

      And finally we'll create a point link from the virtual point to the TCP/IP point, which should have an update event of "Update" have a script like,

      var info = /(\d+)-(On|Off)/.exec(source.value);
      if(info === null)
        return UNCHANGED; //Complain about bad input?
      return "type=command&param=switchlight&idx=" + info[1] + "&switchcmd=" + info[2];
      

      And now if i set the virtual point to '6-On' I see this in my test device:

      GET json.htm?type=command&param=switchlight&idx=6&switchcmd=Off HTTP/1.1
      Host: 192.168.178.100:8081
      
      
      1. Solution 2

      Create a virtual point to set values to, and for simplicity let's say that point is set with values like, "6-On"

      Now create a meta point that updates on context for that point. In the body of the Meta point, we'll use the HttpBuilder script utility to send the get. This will have the advantage of letting us report the status of the write however way want (as opposed to events on the TCP/IP data source and point) and the value we store in the Meta point can indicate it was successful. So our meta point script might look like,

      var info = /(\d+)-(On|Off)/.exec(p123.value);
      if(info === null)
        return UNCHANGED; //Complain about bad input?
      var headers = {"Host":"192.168.178.100:8081"};
      var parameters = {
        "type":"command",
        "param":"switchlight",
        "idx": info[1],
        "switchcmd": info[2]
      }
      HttpBuilder.get("http://192.168.178.100:8081/json.htm", headers, parameters).resp(function(statusCode, headers, content) { 
        // handle the response, maybe return "Success!" or whatever
      }).err(function(statusCode, headers, content) {
       // handle error responses
      }).execute();
      
      1 Reply Last reply Reply Quote 0
      • M
        Mark
        last edited by

        Dear Phil,

        Thank you very much! The 2nd option works fine for me. It is now very easy to switch multiple points in domoticz.

        Thanks again!

        1 Reply Last reply Reply Quote 0
        • M
          Mark
          last edited by

          Here is an update of the above script. I have set the ID number of the lighting fixed.
          0_1523291097260_c2f0095c-5cb9-4205-a10f-d1e3299315ad-image.png

          I have slightly modified the script so that it can also be used to dim lighting.
          0_1523291028712_7b69447d-3025-42e4-aa59-033bae0d0aa7-image.png

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            Awesome! Glad you were able to do what you needed to!

            M 1 Reply Last reply Reply Quote 0
            • C
              cor
              last edited by

              Dear Phil and Mark,
              Dont know if you're still folowing this, trying to use your solution, and in the process maybe skipping a step, but i dont know yava script.

              I am using solution 2, the point i am referencing has state 1 or 2., trying to ad an extra variable. This is wat i got; is this a posibylity?

              var pointinfo = /(1|2)/.exec(p20.value);
              var info = "off"
              if (pointinfo = 1)
              var info = "on"
              if (pointinfo = 2)
              {
              var headers = {"Host":"192.168.178.12:8080"};
              var parameters = {
              "type":"command",
              "param":"switchlight",
              "idx":"7",
              "switchcmd": info
              };
              HttpBuilder.get("http://192.168.178.12:8080/json.htm", headers, parameters).resp(function(statusCode, headers, content) {
              // handle the response, maybe return "Success!" or whatever
              }).err(function(statusCode, headers, content) {
              // handle error responses
              }).execute();

              Hope to hear from you

              1 Reply Last reply Reply Quote 0
              • phildunlapP
                phildunlap
                last edited by

                Hi cor, welcome to the forum!

                It looks as though the first few lines of your script could be touched up. A single = is the assignment operator, where == is a comparison operator. Also I realize you are taking the regex from the previous examples, but if you just need to see if the value is 0 or 1 you can simply compare upon the value itself, like,

                var info = p20.value == 1 ? "off" : "on"; //set the value off only if p20.value is 1
                

                or if you don't want anything but a 1 to mean 'on' you could do,

                var info;
                if(p20.value == 1)
                  info = "off";
                else if(p20.value == 2)
                  info = "on";
                else
                  throw "Unusable value in p20: " + p20.value; //cause a script error since bad input
                

                Everything else seems like it'd be the same as in Mark's usage.

                1 Reply Last reply Reply Quote 0
                • C
                  cor
                  last edited by

                  thank you! wil play with it some more!

                  1 Reply Last reply Reply Quote 0
                  • M
                    Mark @phildunlap
                    last edited by

                    @phildunlap 2 years ago I received a script from you for switching lighting. I now want to use this for another command. I would like to execute the following command:

                    • http://192.168.178.66/relay/1?turn=on
                    • http://192.168.178.66/relay/1?turn=off

                    Can you help me with the right script?

                    1 Reply Last reply Reply Quote 0
                    • MattFoxM
                      MattFox
                      last edited by

                      I may be able to be of some assistance here...
                      Alter your url to be

                      http://192.168.178.66/relay/1
                      

                      And amend your parameters to have the 'turn' parameter

                      var parameters = {
                        "turn": relay.value==1?'on':'off'
                      }
                      

                      I'm not quite sure if you're using the exact same configuration as before with a virtual datasource point but in a nutshell, calling the query like that will give you your toggle command.
                      If however you want to keep the code consistent, just have 100 for on and 0 for off, this way you can recycle the old code and just amend your URL.

                      Fox

                      Do not follow where the path may lead; go instead where there is no path.
                      And leave a trail - Muriel Strode

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        Mark @MattFox
                        last edited by

                        @mattfox said in Http sender 3th party:

                        var parameters = {
                        "turn": relay.value==1?'on':'off'

                        I have just tried the following script but unfortunately this does not work.

                        0_1581337538394_50387a64-d6fc-441a-9c43-29106808e16d-image.png

                        1 Reply Last reply Reply Quote 0
                        • MattFoxM
                          MattFox
                          last edited by MattFox

                          The url is inside the get call. Not the host part of the header.
                          You want to 'get' calll the page, you're calling the 192.168... at the root level of the server, not the relay page.

                          Secondly, your context point var is not used to correlate to being on or off. Since the point is an alphanumeric and not a numeric/binary, your parameters should be:

                          var parameters = {
                            "turn": info
                          }
                          

                          You're calling a script but I think you are unaware of how everything works. I take it it has been a long time since you've done this.

                          Do not follow where the path may lead; go instead where there is no path.
                          And leave a trail - Muriel Strode

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