Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save almcarvalho/9dda36f6c8299ef5edbc926a4fb552fc to your computer and use it in GitHub Desktop.
Save almcarvalho/9dda36f6c8299ef5edbc926a4fb552fc to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "SERVER NAME";
const char* password = "SERVER PASSWORD";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("Connecting...");
}
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http; //Object of class HTTPClient
http.begin("http://jsonplaceholder.typicode.com/users/1");
int httpCode = http.GET();
if (httpCode > 0)
{
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.parseObject(http.getString());
int id = root["id"];
const char* name = root["name"];
const char* username = root["username"];
const char* email = root["email"];
Serial.print("Name:");
Serial.println(name);
Serial.print("Username:");
Serial.println(username);
Serial.print("Email:");
Serial.println(email);
}
http.end(); //Close connection
}
delay(60000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment