This would be a super simple way of getting the current UTC (EDIT: I mean Unix time) … much easier than setting up all of code to request the time from an NTP server.
I meant to say Unix time earlier… It’s easy enough to convert Unix time to UTC and add in your offset plus daylight savings… The spark server can easily summon up the Unix time and dish it out, simpleness. And if you know your offset already, might as well use your distributed 32-bit 72MHz power to add it locally and spare the spark server a few cycles x 1,000,000 users xD
I wouldn’t mind trying it @timb, it’s for a Core right not the Spark server?
@BDub Correct, it’s a class for the Spark Core that will return the the time, date or both in whatever timezone you specify.
getNetTime(UTC, 24, HHMMSS, “:”);
Three Letter Time Zone Code
24 or 12 Hour Format
Return Time Format: HHMMSS, HMS, HHMM, HM, etc.
Separator Format (Leave Blank for None)
There will also be a getNetEpoch(); and getNetDate(); with similar style arguments for the date.
It’s been a bitch to work on this since TCPClient is so unstable. {Flashes New Code} {Factory Restore} {Register New Core} {Reset Core Several Times, Reload Spark Build} {Flashes New Code} {Rinse} {Lather} {Repeat}
Then I want to calculate the number of seconds until departure. The Spark Core will make some blinking when it's time to leave the house and catch the bus.
Okay, ignore the first question about TimeAPI.org, that was meant for another post and got accidentally pasted in.
So essentially, you just want a notification X minutes before Y time?
What if I had a function called netTime.setAlarm(0, “2014-01-03T10:02:00+0100”, -15) [Argument #1: Alarm Number, #2: Alarm Time, #3: Offset to Trigger On]; there would be a netTime.getAlarm(0) [#1: Alarm Number to Check] that would return a true or false boolean value depending on if the alarm had triggered. Would that suffice?
See, right now there’s no built-in timekeeping functions on the Core. There is a RTC onboard, but the Spark Team doesn’t have it quite implemented yet, though it is on their list! Anyway, since there’s no onboard timekeeping right now, you’d need to check the internet for the current time on every pass of void loop(), which would create a ton of traffic and make things quite slow.
So, I could implement the above alarm functions by pulling time from the internet then using a “Soft RTC” to countdown in the background (I’d recheck the internet time every 10 minutes or so to manage the drift).
I should have my library done by the end of the weekend, but once I get the basics going I can work on the alarm functions and let you start testing things.
Thanks for the input. Just want you all to know that at least some eyes here at Spark saw this request and know how helpful it would be to streamline this for everyone. I’ve added it to my community feedback notes and will make sure it gets brought up during our next Sprint Planning meeting.
@Coffee Hey there man, does that code actually works for you? I’ve tried flashing it (copy/paste) no modifications at all and it doesn’t flash it, although it says it does… The spark core just doesn’t receives it, doesn’t restart or anything at all, if I however change line #27 (“long timestamp = currentTimeMilis();”) to “long timestamp = 0;” it does get flashed. Weird.
Seems like it’s a silent failure with the compiler!
I traced it down to commenting out line 88:
setenv("TZ", "UTC", 1);
But I have no idea why it’s failing to compile.
Lol line 90:
// sy/11.Jan.2014: Not sure if setenv works at all...
EDIT: I also had to change line 115 to: String response = "";//http_get("www.timeapi.org", "/utc/now");
To even get it to the parseDate() function before having other issues with setenv();
Nice work @Coffee! I was using TimeAPI.org in my netTime Library as well, but I just haven’t had time to work on it. I started working on it, then decided I wanted to add some LCD support which had me debugging I2C issues, which in turn got me working on JTAG stuff.
@Dave Is anyone on the team working on adding support for the RTC? I’ve been adding some notes about it as I go through the datasheets.