ESP32 Sunset Relay Control Code
Budget / Salary₹1,500–12,500
TypeFreelance project
LocationRemote
Posted3 hours ago
I need a clean, well-commented Arduino sketch for an ESP32 that calls the WeatherAPI service (Indian endpoint) once a day, extracts only the sunset time for my chosen location, and uses that value to energise or de-energise a relay on a GPIO pin at the right moment.
Core flow
• Connect to Wi-Fi with credentials placed in a separate header or clearly marked section.
• Send an HTTP GET to WeatherAPI, using my key and either a city name or lat/long that I can edit easily.
• Parse the returned JSON, pick out the “sunset” field, and convert it to a usable 24-hour time.
• Compare the current RTC time on the ESP32 to the sunset time and switch the relay accordingly—ideally with a five-minute refresh window so the relay doesn’t chatter.
• Fail-safe: if no fresh data arrives, keep the previous day’s schedule and log the error on Serial.
Deliverables
1. Fully working .ino file ready for Arduino IDE / PlatformIO.
2. Brief README explaining required libraries, the expected JSON snippet, and where to enter Wi-Fi, API key, and pin number.
Acceptance criteria
– Sketch compiles for ESP32 DevKit-C without tweaking build flags.
– JSON sunset value correctly parsed for any Indian timezone location provided by WeatherAPI.
– Relay switches on the minute of sunset ±30 s in bench tests (I will simulate time with the RTC).
No additional hardware control or sensor integration is needed—just the API call, parsing, and relay control around sunset.
Core flow
• Connect to Wi-Fi with credentials placed in a separate header or clearly marked section.
• Send an HTTP GET to WeatherAPI, using my key and either a city name or lat/long that I can edit easily.
• Parse the returned JSON, pick out the “sunset” field, and convert it to a usable 24-hour time.
• Compare the current RTC time on the ESP32 to the sunset time and switch the relay accordingly—ideally with a five-minute refresh window so the relay doesn’t chatter.
• Fail-safe: if no fresh data arrives, keep the previous day’s schedule and log the error on Serial.
Deliverables
1. Fully working .ino file ready for Arduino IDE / PlatformIO.
2. Brief README explaining required libraries, the expected JSON snippet, and where to enter Wi-Fi, API key, and pin number.
Acceptance criteria
– Sketch compiles for ESP32 DevKit-C without tweaking build flags.
– JSON sunset value correctly parsed for any Indian timezone location provided by WeatherAPI.
– Relay switches on the minute of sunset ±30 s in bench tests (I will simulate time with the RTC).
No additional hardware control or sensor integration is needed—just the API call, parsing, and relay control around sunset.
Apply on Freelancer →
Project sourced from Freelancer.com. Applications happen directly on the original platform — we never collect your data.