#include #include // -- Configuration Parms -------------------------------------------- const char* ssid = "YOUR WIFI SSID"; const char* password = "YOUR WIFI PASSWORD"; const char* SERVER_URL = "YOUR REPOSITORY" //"http://192.168.1.81:5000/doors"; IPAddress local_IP(192, 168, 1, 225); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); const long SLEEP_SECONDS = 60; // 1 minute interval check //-- const int DOOR_GPIO = 4; // any GPIO pin will do const int BATTERY_GPIO = 3; // any GPIO pin will do float battery = 0; RTC_DATA_ATTR bool doorClosedPrevious = false; bool doorClosed = false; void report() { analogSetAttenuation(ADC_11db); analogReadResolution(12); battery = analogRead(BATTERY_GPIO) * (3.3f / 4095.0f) * 3.068; const char* doorState = doorClosed ? "close" : "open"; // Connect to WiFi with static IP WiFi.config(local_IP, gateway, subnet); WiFi.begin(ssid, password); int attempts = 0; while (WiFi.status() != WL_CONNECTED && attempts < 20) { delay(500); attempts++; } if (WiFi.status() == WL_CONNECTED) { HTTPClient http; String url = String(SERVER_URL) + "?garageIn=" + doorState + "&battery=" + String(battery, 2); http.begin(url); int httpCode = http.GET(); http.end(); } WiFi.disconnect(true); WiFi.mode(WIFI_OFF); } void setup() { pinMode(BATTERY_GPIO, INPUT); // Blue LED on when powered, off before sleep, replaces Rec always on pinMode(8, OUTPUT); digitalWrite(8, LOW); // HIGH = on for most C3 Super Mini boards, flash once pinMode(DOOR_GPIO, INPUT_PULLUP); delay(10); // settle time digitalWrite(8, HIGH); // turn off before sleeping doorClosed = (digitalRead(DOOR_GPIO) == LOW); if ( doorClosed != doorClosedPrevious) { doorClosedPrevious = doorClosed; report(); } esp_sleep_enable_timer_wakeup((uint64_t)SLEEP_SECONDS * 1000000ULL); esp_deep_sleep_start(); } void loop() { )