#include <WiFi.h>
#include <time.h>
#include "RelayControl.h"
// Wi-Fi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// NTP server settings
const char* ntpServer = "pool.ntp.org";
const long gmtOffsetSec = 7 * 3600; // Example: GMT+7
const int daylightOffsetSec = 0;
// Create a RelayControl instance: relay pin 27, button pin 17, debounce 50ms, auto-off 2000ms, schedule 2024-12-18 at 14:55 (2:55 PM)
RelayControl relay2(27, 17, 50, 2000, 2024, 12, 18, 15, 5);
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi connected!");
// Initialize NTP
configTime(gmtOffsetSec, daylightOffsetSec, ntpServer);
Serial.println("Waiting for time synchronization...");
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
delay(1000);
Serial.print(".");
}
Serial.println("\nTime synchronized!");
}
void loop() {
relay2.update();
delay(100); // Small delay to avoid excessive polling
}