SparkCore NTP Server

My project is a stratum-1 ntp server to feed the time to a network that is not internet connected. I’ve got one successfully running using a raspberry pi (running linux and paired with a GPS receiver), which was pretty trivial (being linux), but I think it’d be a tremendous feat to get an arduino device actually doing it. I’m no code genius, so I’m muddling my way around here. Most of my arduino projects up to this point have been relatively simple.

I’ve got a GPS receiver wired up to my SparkCore and am able to read the data over TTL using nearly the same code I used on an arduino pro. The next step is the code to act as an SNTP server, and I have a couple of questions to present to the community before I jump in headfirst and confuse myself to death.

So, here are my questions:

  • Theoretically, would the storage available even be big enough for a simple server application such as this PLUS 100-so lines of code to grab GPS data? I’ve done some google-diving and haven’t come up with a lot of examples for comparison, and don’t truly know where to being, yet.
  • Is there any way to determine the current storage total used?

Absolutely welcome any feedback, critical or otherwise. I’ve had a number of people tell me this is no role suitable for a microcontroller, but I’m yet to convince myself otherwise!

The number of lines in a program don’t really translate to the amount of code it will take. Data structures and code efficiency can impact its size considerably. The other side of the coin is how much RAM will it take. There is approximately 108KB of user “code” space available and roughly 6KB of RAM (though that may well improve in the coming weeks).

The only way to know is to get it to compile on the Spark and look at the final linker report that indicates the flash and (pre-allocated) RAM size. This only applies to locally compiled code as the web IDE does not give this detail yet.

If you post your code, myself or someone in the community could help you to get it compiling and working for your application. :smile:

1 Like

Hi @asiago

I wrote a cheap and dirty NTP client for the core so I would say that a server would be not that much more difficult, depending on the accuracy you want to achieve. There are some things that will be different from a rasp-pi linux implementation and you won’t have all the niceties you are used to.

I assume you want to read the serial GPS data and interrupt on the PPS output to get better timing, which should be fine. I think realistically you may not achieve the same kind of accuracy you could get in kernel mode on an rasp-pi without turning off the cloud services on Spark core, but control over the cloud is available now. With the cloud turned off, you should do quite well. The UDP network part which happens inside the TI CC3000 has unknown latency so you really can’t balance that out in the NTP packets–maybe you could measure some typical values and just use that.

1 Like

Thanks so much for the replies!

@peekay123: I’ll get my code posted here on this thread in the next few days. All I have so far is the code I grabbed from the arduino playground and whittled down to remove the unneeded bits and added some stuff to blink the LEDs as a status display of sorts so I’m sure it’s mostly working.

@bko: very nice, thanks for sharing your code! I’ll see if I can adapt this to what I need, I don’t think a client versus server is all that different as far as NTP goes.

High precision time, as far as my own project goes, is not a critical need (at least not yet) - the immediate goal is to be able to restore the proper time to devices that have lost power, without manual intervention. Max 4-5 devices.