$£#! .. just wrote the reply and pressed some button to make all of the post disappear, so this is second attempt:
It turns out it's pretty simple to do this, I made an example sketch which you can see in the git repo:
After you have added all the necessary code to your sketch you can use it this way to fetch time:
/**
* This sketch illustrates how to get time from ntp-server.
* @author Dimitry Kireyenkov
*/
void
setup
()
{
String
server
=
"0.uk.pool.ntp.org"
;
//String server = "time.euro.apple.com";
NtpMessage
msg
=
getTimeOrNull
(
server
);
if
(
msg
==
null
){
println
(
"There was an error getting ntp time from server: "
+
server
);
}
else
{
println
(
"Time received: "
+
msg
.
toString
());
}
}
void
draw
()
{
}
.
And you will get a response similar to this (it's pretty easy to extract specific info you want from there):
.
In order for this to work with YOUR sketch, you need to do the following:
- paste code from timeUtils.pde anywhere in your sketch (recommended to paste it into separate tab in your sketch)
- paste code from NtpMessage.java into separate tab in your sketch and you MUST (yeah.. that ain't a recommendation anymore) name this tab exactly NtpMessage.java (with all letters correctly CapitaLized and having .java in the end)
Now you should be able to query time with
getTimeOrNull() method from anywhere in your sketch. Read commentary to the function to figure out it's behaviour.
ps. that ain't gonna work in JavaScript mode. And it won't work in Android either (but for android there may be a quick fix).