// You have to change before upload: Your WiFi Name, Password, and unique_key #include #include #include #include const char* ssid = "name"; // change wifi name const char* password = "password"; // change password const char* apiUrl = "https://smart.gupchupwala.com/api.php?unique_key=XXXXXXXXXXX"; // Change your unique_key void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\n✅ WiFi Connected!"); } void loop() { if (WiFi.status() == WL_CONNECTED) { WiFiClientSecure client; client.setInsecure(); // SSL check disable (self-signed allowed) HTTPClient https; if (https.begin(client, apiUrl)) { int httpCode = https.GET(); if (httpCode == HTTP_CODE_OK) { String payload = https.getString(); Serial.println("📩 API Response:"); Serial.println(payload); // ✅ बड़ा buffer रखा ताकि crash न हो DynamicJsonDocument doc(4096); DeserializationError error = deserializeJson(doc, payload); if (error) { Serial.print("❌ JSON Parse Error: "); Serial.println(error.c_str()); https.end(); delay(5000); return; } // अगर devices array है और empty नहीं है if (doc["devices"].size() > 0) { for (JsonObject dev : doc["devices"].as()) { const char* name = dev["name"] | "Unknown"; const char* state = dev["state"] | "OFF"; int pin = dev["pin"] | -1; if (pin >= 0) { pinMode(pin, OUTPUT); if (strcmp(state, "ON") == 0) { digitalWrite(pin, LOW); } else { digitalWrite(pin, HIGH); } Serial.printf("💡 Device: %s | Pin: %d | State: %s\n", name, pin, state); } } } else { Serial.println("⚠️ No devices found in response."); } } else { Serial.printf("❌ HTTP Error: %d\n", httpCode); } https.end(); } else { Serial.println("❌ HTTPS Connection Failed!"); } } else { Serial.println("⚠️ WiFi Disconnected! Reconnecting..."); WiFi.begin(ssid, password); } delay(10000); // हर 10 सेकंड में API call करेगा }