#include <WiFi.h>
#include <HTTPClient.h>
// ---------- Relay pins (HIGH = ON) ----------
#define RELAY_SIREN 23
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 19800; // India = GMT+5:30 (5*3600 + 1800)
const int daylightOffset_sec = 0;
void setup() {
Serial.begin(115200);
pinMode(RELAY_SIREN, OUTPUT);
digitalWrite(RELAY_SIREN, LOW);
WiFi.begin(ssid, password);
Serial.print("Connecting WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected");
// Configure NTP
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
//struct tm timeinfo;
//timeinfo.tm_year = 2026 - 1900; // Year - 1900
//timeinfo.tm_mon = 1; // Month (0-11) → Feb = 1
// timeinfo.tm_mday = 20;
// timeinfo.tm_hour = 14;
// timeinfo.tm_min = 30;
// timeinfo.tm_sec = 0;
// time_t t = mktime(&timeinfo);
//struct timeval now = { .tv_sec = t };
//settimeofday(&now, NULL);
Serial.println("RTC Set Successfully");
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to get time");
return;
}
int hour = timeinfo.tm_hour;
int minute = timeinfo.tm_min;
Serial.printf("Time: %02d:%02d\n", hour, minute);
// ✅ Alarm condition
if ((hour == 7 && minute == 0) ||
(hour == 8 && minute == 0) ||
(hour == 12 && minute == 0)||
(hour == 13 &&minute == 0) ||
(hour == 14 && minute == 0)||
(hour == 17 && minute == 0)||
(hour == 21 && minute == 0))
{
digitalWrite(RELAY_SIREN, HIGH);
Serial.println("ALARM ON!");
delay(180000);
digitalWrite(RELAY_SIREN, LOW);
Serial.println("ALARM OFF!");
}
delay(10000);
}
SIREN