#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* pass = "";
const char* postEndpoint = "http://jsonplaceholder.typicode.com/posts";
const char* postPayload = "title=Goalpara Tea Park&body=Tempat Wisata Baru nih hehe&userId=1";
unsigned const long interval = 2000;
unsigned long zero = 0;
const String gateID = "1";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.println(".");
}
Serial.println("WiFi Connected!");
Serial.println(WiFi.localIP());
}
void loop() {
if (millis() - zero > interval) {
// Perform GET request
HTTPClient http;
// http.begin("http://jsonplaceholder.typicode.com/todos/1");
// int httpResponCode = http.GET();
// Serial.println("GET Response Code: " + String(httpResponCode));
// if (httpResponCode > 0) {
// String payload = http.getString();
// Serial.println("GET Response: " + payload);
// } else {
// Serial.println("GET error: " + String(httpResponCode));
// }
// http.end();
// Perform POST request
http.begin("http://jsonplaceholder.typicode.com/todos/1?" + "title=Goalpara Tea Park&body=Tempat Wisata Baru nih hehe&userId=" + gateID);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String postData = "title=Goalpara Tea Park&body=Tempat Wisata Baru nih hehe&userId=" + gateID;
Serial.println(postData);
int httpResponCode = http.POST("");
Serial.println("POST Response Code: " + String(httpResponCode));
if (httpResponCode > 0) {
String payload = http.getString();
Serial.println("POST Response: " + payload);
} else {
Serial.println("POST error: " + String(httpResponCode));
}
http.end();
zero = millis();
}
}