#include <WiFi.h>
#include <HTTPClient.h>
#include "DHTesp.h"
#include <ArduinoJson.h>
DHTesp dht22 ;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String payload;
const String AuthToken = "token_t3hFfzQDbGfkKvlZ";
const String serverT = "http://api.beebotte.com/v1/data/write/mychannel/temperature";
const String serverH = "http://api.beebotte.com/v1/data/write/mychannel/hum";
HTTPClient http;
void setup() {
Serial.begin(115200);
dht22.setup (15, DHTesp ::DHT22);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void postbeebotteT( float data){
http.begin(serverT);
DynamicJsonDocument j(256) ;
j["data"] = data ;
serializeJson (j,payload);
http.addHeader("Content-Type","application/json");
http.addHeader("X-Auth-Token","token_t3hFfzQDbGfkKvlZ");
Serial.println(payload);
int http_response= http.POST(payload) ;
if (http_response > 0 ){
Serial.println(http_response);
if (http_response==200){
Serial.println("Envoie Avec Succes");
}
else {
Serial.println("Error");
}
}
http.end();
}
void postbeebotteH( float data){
String donne ;
http.begin(serverH);
DynamicJsonDocument j(256) ;
j["data"] = data ;
serializeJson (j,donne);
http.addHeader("Content-Type","application/json");
http.addHeader("X-Auth-Token","token_t3hFfzQDbGfkKvlZ");
Serial.println(data);
int http_response= http.POST(donne) ;
if (http_response > 0 ){
Serial.println(http_response);
if (http_response==200){
Serial.println("Envoie Avec Succes");
}
else {
Serial.println("Error");
}
}
http.end();
}
void loop() {
float temp = dht22.getTemperature();
float hum = dht22.getHumidity();
Serial.println(temp);
Serial.println(hum);
postbeebotteT(temp);
postbeebotteH(hum);
delay(10000);
}