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¶m=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¶m=switchlight&idx=6&switchcmd=Off HTTP/1.1
Host: 192.168.178.100:8081
- 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();