The Core and Photon support REST both incoming (through the cloud) and outgoing using a library. Node Red is REST compatible. The most basic plan is the have Node Red consuming Core/Photon services when required and Core/Photon consuming Node Red service far more regularly.
Not wanting to over stretch myself I wanted to consume a post service on my Node Red box which hopefully talking Pushover on my phone. I can use a chrome extension (Advanced REST) to do this happily enough so know it works.
I have tried using the HTTPlibary and the RESTlibrary on the Core (soon to be Photons too) and have simply failed miserably. As a developer I am finding this quite annoying as the answer is simply eluding me.
Node Red uses x-www-form-urlencoded natively and this does work (as stated earlier) but I have used both libraries to try and consume the service to no avail.
The Core is simply sending three parameters (title, priority, message) to the web service and it pings my phone.
Any ideas on what I am doing wrong?
Also does anyone know a good way to urlencode stuff parameters on the core/photon?
#include "HttpClient/HttpClient.h"
unsigned int nextTime = 0; // Next time to contact the server
int led2 = D7;
HttpClient http;
http_header_t headers[] = {
{ "Content-Type", "application/x-www-form-urlencoded" },
{ "Accept" , "*/*"},
{ NULL, NULL }
};
http_request_t request;
http_response_t response;
void setup() {
pinMode(led2, OUTPUT);
}
void loop() {
request.hostname = "123.123.123.123";
request.port = 80;
request.path = "/pushmeover";
request.body = "title=spark&priority=2&message=it+may+be+working";
http.post(request, response, headers);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
delay(10000);
}