Agent to HTTP:POST a simple url (no JSON headers/body)

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);
}

You should just be able to do:

http.post(format(“http://XXXXXXXXXX.noip.me/controller/rest/control/%d/%s”, 192, “on”), {}, “”).sendsync();

  • you’re just adding to the URL there, so there’s no need to send stuff in the body.

So…first thank you.

Fortunately, the above does work but only if I put the raw IP address in (address:port, XX.XXX.XX.XX:YYYY).

Unfortunately, when I put the DNS address in, it fails (I use DNS addresses to keep the address constant). I can confirm the DNS address works/port is open as the browser turns the switch on.

Is there something I need to do to allow using a DNS address in a http:post?

Thanks for the help.

No, DNS addresses should work fine - very very few people use IP addresses.

Could you send me (by PM if required) the DNS address, your agent ID, and a UTC timestamp of when you saw an issue? I can look in the logs and see what appears to be happening.