Working on a simple push button that has the agent post a “http post” request. If I copy/paste the following url into a browser, the switch I am trying to control comes on. I would like to do the same with the imp push button.
URL: XXXXXXXXXXXX.noip.me/controller/rest/control/192/on
The pushbutton works, the agent acknowledges the press, but I have no idea on how to “http:post” without all of the json headers/body/etc required. I can use Chrome with the url above and the switch comes on. I can also use Tasker/Android to http:post the url and it works as well.
I tried in the code below to follow this link openremote.org/display/docs/Controller+2.0+HTTP-REST-JSONP and load a control id and command parameter as a body string, but it does not work.
Any ideas on what I’m missing?
Agent Code:
function store(state2) {
server.log(“Button Pressed”);
HttpPostWrapper();
}
device.on(“Pressed on Device”, store);
function HttpPostWrapper() {
local url = "http://XXXXXXXXXX.noip.me/controller/rest/control"
local string = {“control_id”: 192, “command_param”: “on”};
local headers = {“Content-Type”: “application/json”};
local req = http.post(url, headers, http.jsonencode(string));
local response = req.sendsync();
server.log(response);
return response;
}
Device Code:
pb <- hardware.pin1;
function pbpress() {
local state2 = pb.read();
if (state2 == 1) {
//server.log(“Release”);
imp.sleep(0.25);
} else {
//server.log(“Press”);
toggleurl();}}
pb.configure(DIGITAL_IN_PULLUP,pbpress);
function toggleurl() {
agent.send(“Pressed on Device”,0);
}