#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// domain name
const char* serverName = "https://ist-api-endpoint.vercel.app/api/upload-image";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
bool uploadImage() {
// check wifi status
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure(); // Disable SSL certificate verification (for testing only)
HTTPClient http;
http.begin(client, serverName);
http.addHeader("Content-Type", "application/json");
String jsonPayload = "{\"image\":\"wompwomp\"}";
int httpResponseCode = http.POST(jsonPayload);
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.print("Response: ");
Serial.println(response);
return true;
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
return false;
}
http.end();
} else {
Serial.println("WiFi not connected");
}
}
void loop() {
if (uploadImage()) {
Serial.println("success");
}
else {
Serial.println("failure");
}
}