NodeMCU - server NTP Sync

My project, which uses nodeMCU, has some sensors for reading and now I would like to use an NTP server to set the date/time.

The reason for using the NTP server is because I need precision in milliseconds and I need to synchronize the time on all devices. Today I already have a computer synchronized with the NTP server and now the idea is to synchronize nodeMCU so that both have the same time.

I have a question about the timing of the date/time, I know that there is no multiprocess support, but do you think there is any way around this until the timing is correct?

Could you please provide more information? I still try to figure out what you want and whether your idea would work.

Where is the NTP server? Some public service or your own?

What data are the devices collecting and why does the data need to be synchronized?
How far are they apart? Is there a limitation that would stop you from synchronizing them with a wire signal?

What NTP library are you using?
Do you implement the NTP software yourself? Wikipedia says there are algorithm used to mitigate network effects. The simple NTP examples I have seen do not look like they would do that. Maybe Windows, Linux and MAC OS implement this. They have GB of software running on them.

How long do you need the synchronization to be valid? Microcontrollers boards have no special clock generators with temperature compensation or time calibration. Just try to run a simple clock sketch and you will notice the time does not stay accurate for long. The frequency will stay fairly stable, but it will not be the same for all boards.

Thinking about it, I doubt a normal PC clock can be used for millisecond synchronization. Just because we humans think the time displayed looks synchronized it does not mean you can reliably use that. Humans are slow and even humans complain about their PCs being slow (not reacting fast enough not necessarily raw computation power). The issue is the OS with virtual addressing and hundreds of tasks running in the background. That is an issue we do not have to worry about on a microcontroller.

andrekabelim:
I have a question about the timing of the date/time, I know that there is no multiprocess support, but do you think there is any way around this until the timing is correct?

you can check if the Time was set via NTP since startup. by default, the NTP of ESP8266 does it's first time sync after 60 seconds and then every hour.

@Klaus

What NTP library are you using?

you don't need a third party library. Use the build in functions of the ESP. NTP with DST is lit. a one-liner nowadays!

Klaus_K:
Could you please provide more information? I still try to figure out what you want and whether your idea would work.

Where is the NTP server? Some public service or your own?

What data are the devices collecting and why does the data need to be synchronized?
How far are they apart? Is there a limitation that would stop you from synchronizing them with a wire signal?

What NTP library are you using?
Do you implement the NTP software yourself? Wikipedia says there are algorithm used to mitigate network effects. The simple NTP examples I have seen do not look like they would do that. Maybe Windows, Linux and MAC OS implement this. They have GB of software running on them.

How long do you need the synchronization to be valid? Microcontrollers boards have no special clock generators with temperature compensation or time calibration. Just try to run a simple clock sketch and you will notice the time does not stay accurate for long. The frequency will stay fairly stable, but it will not be the same for all boards.

Thinking about it, I doubt a normal PC clock can be used for millisecond synchronization. Just because we humans think the time displayed looks synchronized it does not mean you can reliably use that. Humans are slow and even humans complain about their PCs being slow (not reacting fast enough not necessarily raw computation power). The issue is the OS with virtual addressing and hundreds of tasks running in the background. That is an issue we do not have to worry about on a microcontroller.

The NTP server is within a local network on a linux server. The entire project runs within this local network.

I am thinking of using the available libraries like NTPClient.

The idea is as follows, through a pc I will activate the sensors to take readings. At each reading I will capture the time, that way I would be able to work with just one time because both the pc and nodemcu will be consuming the same NTP server and all devices would be synchronized.
Remembering that the accuracy must be milliseconds.
The maximum distance between the nodemcu and the PC will be approximately 80 meters.

About synchronization, I thought about using a library to simulate a thread and from the moment the device is connected, make the request (in the interval of x second for example) on the server to keep the time synchronized.

You did not say why you need the time to be synchronized? What data are you collecting?

If you want to analyse data collected by your nodeMCU you could simply time stamp the data.

I use n t p all the time, what is your exact issue with it?