#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "https://sensor1.free.beeceptor.com/my/api/path";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("OK! IP=");
Serial.println(WiFi.localIP());
}
void loop() {
delay(500);
Serial.print("Posting to " + url + "... ");
HTTPClient http;
http.begin(url); //Specify destination for HTTP request
http.addHeader("Content-Type", "application/json"); //Specify content-type header
int httpResponseCode = http.POST("{'temperatureDegC':12}"); //Send the actual POST request
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
}