#include <WiFi.h>
#include <HTTPClient.h>
#include "DHTesp.h"
#include "ArduinoJson.h"
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* serverB = "http://api.beebotte.com/v1/data/read/Test/temp?limit=1";
const char* serverR = "http://api.beebotte.com/v1/data/read/Test/hum?limit=1";
String payload;
HTTPClient http;
WiFiClient wifi;
DynamicJsonDocument FichierRetour(512);
DynamicJsonDocument FichierRetour2(512);
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Wifi Connected");
}
void loop() {
http.begin(wifi,serverB);
http.addHeader("Content-Type","application/json");
http.addHeader("X-Auth-Token","token_ylttBHEK4Dx6JybB");
int httpResponseCode = http.GET();
// Json to send with HTTP POST
if (httpResponseCode > 0) {
Serial.print("HTTP: ");
Serial.println(httpResponseCode);
String JsonRecu=http.getString();
Serial.println(JsonRecu);
deserializeJson(FichierRetour, JsonRecu);
bool x = FichierRetour[0]["data"];
Serial.println(x);
}
else{
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");}
http.end();
http.begin(wifi,serverR);
http.addHeader("Content-Type","application/json");
http.addHeader("X-Auth-Token","token_ylttBHEK4Dx6JybB");
int httpResponseCode2 = http.GET();
// Json to send with HTTP POST
if (httpResponseCode2 > 0) {
Serial.print("HTTP: ");
Serial.println(httpResponseCode2);
String JsonRecu2=http.getString();
Serial.println(JsonRecu2);
deserializeJson(FichierRetour2, JsonRecu2);
bool y = FichierRetour2[1]["data"];
Serial.println(y);
}
else{
Serial.print("Error code: ");
Serial.println(httpResponseCode2);
Serial.println(":-(");
}
http.end();
delay(1000);
}