Time synchronising through LAN; Board startup question

Hi All,
I have a mega2560 board with wiznet w5100 shield. I am reading 6 temp sensor values and sending to internet and saving to sd card. 1.
1.
Problem is after a year I have realised there is arround 20 minutes differencies to the real time.
I am using "Rtc_Pcf8563 rtc; " to initiate real time clock.
Can you please help me how can I synchronise the real time? It is on LAN, so maybe NTP protocoll would be ok? Is there a solution fot this? I am not a big coder :slight_smile:
2.
In case of a power failure the board is not starting up...Sketch is not running. I am using DC power supply 9V. But in case i am pulling out the power directly from the board and put back after some minutes, it is starting in a normal way...
What can I do?

Thank you!

#1 - Use the UdpNtpClient sketch on the ethernet shield examples.

#2 - Use a UPS on the power supply, or maybe try the watchdog timer.

Hi Tim,

thanks. I have manage to done the time refreshing. Getting it from an ntp server and then setting these values to rtc like this:
rtc.setTime(hour(), minute(), second());
How can I set the date? I mean my problem is the rtc.seddate looks like:

//day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc.setDate(24, 5, 01, 0, 14);

so the problem is weekday, century, and year...
Can you help how to do this? ( using Rtc_Pcf8563 library)

Anyway it seems that Pcf8563 will handle leap years until year 2100 by the specifications, it would be interesting how to solve this. :slight_smile: