#include #include #include Discord_Webhook discord; String DISCORD_WEBHOOK = "https://discord.com/api/webhooks/1229941389236899890/3s2jv8iUzGO2EYiagk7FAjGTJNBah33wFtjo25JaYoKoL0fk1g0bnWGaL60pvhSOMZPT"; const int button_pin = 0; void setup() { Serial.begin(115200); Serial.println("ESP32 Initialized"); discord.begin(DISCORD_WEBHOOK); discord.addWiFi("ssid", "ssid_key"); // modify this discord.connectWiFi(); time_t currentTime = getCurrentTime(); currentTime -= 7 * 3600; // Subtract 7 hours (7 hours * 3600 seconds/hour) char timeStr[20]; strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", localtime(¤tTime)); discord.send("(boot) " + String(timeStr)); } void loop() { if (Serial.available() > 0) { String command = Serial.readStringUntil('\n'); command.trim(); if (command.equals("time send")) { time_t currentTime = getCurrentTime(); currentTime -= 7 * 3600; // currently set to UTC-7 char timeStr[20]; strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", localtime(¤tTime)); discord.send("Current time (UTC-7): " + String(timeStr)); // change this ^^^^^^^ } } pinMode(button_pin, INPUT_PULLUP); if (digitalRead(button_pin) == LOW) { time_t currentTime = getCurrentTime(); currentTime -= 7 * 3600; // currently set to UTC-7 char timeStr[20]; strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", localtime(¤tTime)); discord.send("(button) " + String(timeStr)); } } time_t getCurrentTime() { configTime(0, 0, "pool.ntp.org"); time_t now; now = time(nullptr); while (now < 100000) { delay(1000); now = time(nullptr); } return now; }