#include <WiFi.h> // For ESP32/ESP8266 WiFi functions
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "Wokwi-GUEST";
const char* password = ""; // No password for Wokwi-GUEST
void registerDevice() {
HTTPClient http;
String url = "http://103.136.236.17/functions/v1/esp32-register";
http.begin(url);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImdteGR1cnB2YndqenB3Z3BwZmduIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTk4NzEzNjYsImV4cCI6MjA3NTQ0NzM2Nn0.B8YE9Zn1t4Ql_Dz-O5rGwpkW57_jE3JqfIsxcC6W2zo");
StaticJsonDocument<512> doc;
doc["device_id"] = "WP01-D005";
doc["project_id"] = "WP01";
doc["role"] = "regular";
doc["auto_update"] = true;
doc["tank_shape"] = "cylinder";
doc["height_cm"] = 200;
doc["width_cm"] = 100;
doc["max_flow_in"] = 10.0;
doc["max_flow_out"] = 5.0;
doc["pump_lower_threshold"] = 15.0;
doc["pump_upper_threshold"] = 95.0;
String payload;
serializeJson(doc, payload);
int httpCode = http.POST(payload);
if (httpCode > 0) {
String response = http.getString();
Serial.println(response);
} else {
Serial.println(httpCode);
}
http.end();
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
delay(100);
// Connect to WiFi
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWiFi connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
delay(1000);
}
void loop() {
// Delay for readability
delay(1000);
registerDevice();
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1