Skip to content

Instantly share code, notes, and snippets.

@orejuelajd
Last active June 26, 2022 14:10
Show Gist options
  • Save orejuelajd/a489c4e0dd24a3b23f61d430d24611e3 to your computer and use it in GitHub Desktop.
Save orejuelajd/a489c4e0dd24a3b23f61d430d24611e3 to your computer and use it in GitHub Desktop.
#arduino #arduinoyun #yun #post #httpclient
#include <Bridge.h>
#include <HttpClient.h>
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
Serial.begin(9600);
while (!Serial);
}
void loop() {
String var = "";
String value1 = "value1";
String value2 = "2";
String value3 = "3";
var = "{\"value1\":" + value1 + ",\"value2\":" + value2 + ",\"value3\":\"" + value3 + "\"}";
Serial.println(var);
HttpClient client;
client.setHeader("Content-Type: application/json");
String httpBody = var;
String httpDestination = "http://SERVER_IP/route/path/"; //URL Sever
client.post(httpDestination, httpBody);
if (client.read() == 123) {
Serial.println("OK");
} else {
Serial.println("Error");
}
Serial.flush();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment