#include <WiFi.h>
#include <HTTPClient.h>
WiFiClient IOT;
HTTPClient http;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* serverName = "http://ubk.xxx.stream/api/donation/store";
const int serverPort = 80;
const char* url = "/api/endpoint";
String donorName = "ubk-ioT-1";
int donationAmount = 12000;
void setup() {
Serial.begin(115200);
while (!Serial);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// isntall http
http.begin(IOT, serverName);
}
void loop() {
// HTTPClient client;
// Set headers
http.addHeader("Content-Type", "application/json");
// Set body
String body = "{\"donor_name\":\"" + donorName + "\",\"donation_amount\":" + String(donationAmount) + "}";
// POST request
int httpCode = http.POST(body);
// Check response
if (httpCode > 0) {
Serial.print("HTTP ");
Serial.println(httpCode);
// Disconnect
http.end();
}
else {
Serial.print("Error code: ");
Serial.println(httpCode);
Serial.println(":-(");
}
// Disconnect
http.end();
delay(5000);
}