after googling, I can see that there is a ntp library called ntpclient
and that seems strait forward but then how do I work with the time afterwards?
the example sketch
#include <NTPClient.h>
// By default 'time.nist.gov' is used with 60 seconds update interval and
// no offset
NTPClient timeClient(ntpUDP);
// You can specify the time server pool and the offset, (in seconds)
// additionaly you can specify the update interval (in milliseconds).
// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
void setup(){
Serial.begin(115200);
}
timeClient.begin();
}
void loop() {
timeClient.update();
Serial.println(timeClient.getFormattedTime());
delay(1000);
}
You’re only looking for a single trigger, right?
If you wanted to turn on a light, you would put this instead
BLYNK_WRITE(V0){
if(param.asInt()){
// turn on light because timer widget is HIGH or 1
Serial.println("Timer is active");
} else {
// turn off light because timer widget is LOW or 0
Serial.println("Timer is in-active");
}
}
The timer simply sends a 1 or 0, because you dont need to know which is being sent, you can ignore the check.
You can then set your timer to turn on at 00:00:00 (midnight) and off at 00:00:01.
This way you kwh coutner will be reset at 00:00:01 each day.
You must first check the time is actually correct and not showing Jan 1 1970 (which is does do often within the first 5min of boot).
You can update quicker by adding setSyncInterval(60); right after rtc.brgin(); … this will mean that your time is resync’d every minute instead of 5min
Check the time too by outputting to serial or terminal. Or add it to a virtual port.