Hello community, this is my first topic, I'm new to Arduino and I'm trying to send using HTTP Posts and eventually read using HTTP get, let me explain my setup;
I have a home automation controller with web connection that accepts HTTP requests, I have tested these using my cellphone (NFC tags), IFTTT and even through the web browser. I want to create a new interface for sensors which are not supported by this home automation controller and send/receive data using HTTP request but all my attempts have been unsuccesful.
As I mentioned I'm new to Arduino, I did some testing with RFID transmitter/receiver and I2C LED display succesfully but I cannot make the HTTP post to work. This is the POST command I need to send;
URL = https://my.zipato.com/zipato-web/remoting/attribute/set?serial=MYSERIAL&apiKey=MYAPIKEY&value15=150
No need of headers or Body, for obvious reasons I have swaped MYSERIAL and MYAPIKEY, I have found many examples for HTTP post using YUN but most of them use complicated functions to assemble the HTTP request, also I understand there are different ways of doing it. I picked up the most simple one I could find and I modified it so it looks like this.
#include <Bridge.h>
#include <Process.h>
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
Bridge.begin();
Serial.begin(9600);
while (!Serial); // wait for Network Serial to open
Serial.println("Zipato Post");
digitalWrite(3, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
delay(5000); // wait for a second
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
postToZipato();
delay(5000);
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
}
void postToZipato() {
Process pZbox;
pZbox.begin("curl");
//pZbox.addParameter("-k"); // allow insecure (not https)
pZbox.addParameter("-X"); // use POST instead of default GET
pZbox.addParameter("POST");
pZbox.addParameter("-H"); // Any headers go after -H
pZbox.addParameter("Content-Type:application/x-www-form-encoded");
pZbox.addParameter("-d");
pZbox.addParameter("150");
pZbox.addParameter("https://my.zipato.com/zipato-web/remoting/attribute/set?serial=MYSERIAL&apiKey=MYAPIKEY&value15=150");
pZbox.runAsynchronously();
Serial.println("https://my.zipato.com/zipato-web/remoting/attribute/set?serial=MYSERIAL&apiKey=MYAPIKEY&value15=150");
}