Update ds1307 rtc-NTP sync tool

Together with Rodrigo Castro an Arduino 1.0 update was made for - Arduino Playground - DS1307OfTheLogshieldByMeansOfNTP -

The code should work under 0.22, 0,23 and 1.0

As always comments and remarks are welcome, in this thread.

Thanks for this.

Should the code be updated to prefer DHCP if the Arduino board supports it?

Also,

robtillaart:
07/01/2011
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291637975#10
shows DST function, to be integrated.

Was this integrated into the 04/01/2012 version? I'm unsure how/if I would need to handle DST for my location/project.

THANKS

no, not integrated, but you are free too.

I prefer to do my logging without DST to prevent gaps/doubles in my data set

robtillaart:
Together with Rodrigo Castro an Arduino 1.0 update was made for - Arduino Playground - DS1307OfTheLogshieldByMeansOfNTP -

The code should work under 0.22, 0,23 and 1.0

As always comments and remarks are welcome, in this thread.

I think there is a typo in the example sketch on the playground.

#if ARDUINO >= 100
#include <EthernetUdp.h>        // New from IDE 1.0
#else
#include <UDP.h>
#endif

UDP.h should be Udp.h
At least on my system:
sketch_apr26a.cpp:31:17: error: UDP.h: No such file or directory
I'm still using version 0023, my gentoo installation and 1.0 don't play nice. I should do something about that and switch to 1.0 :blush:

Oh, and thanks for the sketch and libraries.

updated the example, thanks for the feedback

I am using Arduino IDE 1.0.1 and I can't get UDP , I Know all about IP addressing and gateway etc...
My MAC Address don't even show up on router list....
No Compile errors....

Can this work with on v 1.0.1 ?

I downloaded Arduino IDE V 1.0 and it worked!
The IDE V 1.0.1 Don't Work..... Byte Command Word ? Something changed in the compiler....

@shane
have you checked the release notes of 1.0.1?

As I have limited time now (other prio's) I cannot dive into this and redesign it to support new version. If you have patches please share them here.

Thanks,
Rob

Having originally failed continually with "No UDP available ...", I managed to get UDP working by first reading packet size by using parsePacket, and then modifying the Udp.read to use that packet size

int packetSize = Udp.parsePacket(); //<<<<<<<<<<<<NEW LINE HERE
// send an NTP packet to a time server
sendNTPpacket(timeServer);

...
Udp.read(pb, packetSize);      // New from IDE 1.0 <<<<<<<<<<<<<MODIFIED LINE

And then, if you aren't in Chile, remember to make your own adjustment to UTC in the line which reads
t4 -= (3 * 3600L);
(the notes say this is a 4 hour adjustment, but clearly it is 3 hours)

Thanks John for this improvement!

can you post your complete modified version, then I will update the playground code.

Thanks again,

Hello
I am trying to sinhronize my time clock withe an ntp server but i have some issues. On these site:
http://playground.arduino.cc/Main/DS1307OfTheLogshieldByMeansOfNTP
I found the code wich should work, but it gives mee allways the same message No UDP available ., and i cannot understand why is that ?
Maybe the ntp server is out of date or something, i have tried to find another one and ping its address to find its ip, but i got the same message, I am in Europe so i need an european Server.
So the code is the same as the on on the example

any suggestions :frowning:

  1. check if your router blocks UDP and/or port 123.
  2. check which NTP server your router uses (your internet provider offers) and use that one.
  3. check - WebHome < Servers < Network Time Foundation's NTP Support Wiki - for an alternative NTP server.

Please note that NTP servers block IP addresses that request too often

well when i use the code from this tutorial http://arduino.cc/en/Tutorial/UdpNtpClient
it works, but it is not my timezone, and i dont know how to find the ip of a ntp server I can just find the name of the srever, the ip i ping from cmd and find out, however, even when i put the ip from the tutorial http://arduino.cc/en/Tutorial/UdpNtpClient, in the code from Arduino Playground - DS1307OfTheLogshieldByMeansOfNTP it doesnt work. So that means it is not the problem with the server and i can recive udp with no problem.
I was compairing those two codes and could only find a difference taht the one that works uses Udp.parsePacket() insted of Udp.available(). Bet even if i change that it doesnt work
PS: i would use the one that works, but it gives me only time, I need date also and to synhronise it with the timer

but it is not my timezone,

you must add an offset = 3600L * hours; to get the adjusted the timezone.
Every timeserver responds in universal time == Greenwich mean time zone.

Which IDE version do you use?

OK i managed to get it work, now i want it to use in another code taht i made. But there is a problem, i cannot use
#include <DS1307RTC.h>
and
#include <RTClib.h>
At same time apperalnty, so i deleted #include <RTClib.h>
but now there is a part

RTC.set(DateTime(t4));

It sais DateTime is not declared in that scope :confused:
But i need DateTime so that i can configurate the RTC
Edit:
Decidet do use RTClib.h, then i gotr a lotr of strange errors, a few google searches and i found out that thiss is really importent
the first declared include must be
Wire.h
and after that RTClib.h
So i did it and now doesnt have any error messages