The plan for the Spark team is to set the on-chip real-time clock from the Spark cloud. The core part of that work is done but the cloud part is still underway and will be available in the next few weeks. It is certainly possible to set the clock yourself today either via NTP, as SparkTime does, or from a serial port or web page.
I have been looking at the memory footprint of my time library, since it still has some features that I need like automatic daylight-savings adjustment and some nice formatting. When I make a minimal test program, I see that about 1500 bytes of RAM are used by the SparkTime library and UDP. Of that, about 700 bytes are just UDP and 800 bytes are Sparktime. I hope to reduce this memory footprint. All of the pretty names like “Monday” and “September” end up in flash and don’t consume RAM. I am investigating the Arduino String class since there are not 800 bytes used in my class when I add it up by hand.
markopraakly, I had the same problem! The Spark RTC code works well but does not include cloud synchronization yet. Part of the reason your Spark flashes red is that your code (+ the firmware) is exceeding the (current) 16KB memory boundary since 4KB of the 20KB available is dedicated to buffers and such. To get things working, I had to do a few things:
Clean up my code by removing any unnecessary globals variables
Using local variables where possible in functions so they use stack/heap space instead of RAM
Declaring “const” types for constants so they are stored in flash
NOT using TCPclient and UDP at the same time since I found they are memory hogs. Instead, I use Spark.variable/Spark.publish/Spark.function to get my data out.
I then wrote a getUDPtime() based on bko’s excellent library to get the time in epoch format and use that to do a Time.setTime(udptime). I also set the timezone using Time.zone().
If you think it might help, I can post the getUDPtime() code.
bko, I had removed all the String stuff from my code and still had problems mostly relating (I suspect) to the UDP RAM allocation. I was using both TCP and UDP in my original code and realized that both are memory hogs. So I got rid of TCP stuff and now only use the UDP code. Since Spark Time has been implemented, there is no point in using your library since both use RAM and exceed the limit on my code. So, for now, I wrote the small getUDPtime() (thanks for your help on that!) and exploit the existing Spark code. Eventually as you said, even that will not be necessary.
I have to use TCP Client, because I need to transport some sensitive data to my own target server. So I can see currently one option to get current date from my TCP server and initialize somehow. Does anyone have a example to set time even hardcoded example?
markopraakli, why don’t you time tag at the server instead of the Spark. Except for the transport delay, your server can tag the data received received from the Spark with its own time. At least, it would seem!
Otherwise, I know TCP port 37 provides time service like UDP port 123 put I have not seen any code for it.
I could not tag time at the server, because I could have situations when WIFI is down,far or interrupted any other way, then data with timestamp should be write down to micro sd card. After that internet connection is established then written data should be synced to server with timestamps.