The code for this module is in IoTPy/examples/timing/ You can download it by clicking here.

This module consists of functions that use ntp (the Network Time Protocol) to improve the accuracy of streams of timestamps or time offsets from local clocks. This module is also helpful in synchronizing clocks on multiple computers of a distributed system.

The key point of this module is that you develop these applications in the following steps:

  1. Write terminating functions that call ntp and that return a time offset from the local computer clock.

  2. Wrap these functions using the source_func_to_stream wrapper to get a source agent that generates a stream of offsets or corrected times.

  3. Make processes using these sources by using the wrapper: single_process_single_source which makes a single process consisting of:

    (a) the single source agent executing in its own thread and

    (b) a computational network of agents executing in its own thread. In the tests, this computational network has a sink agent that prints a stream.

This module has four parts:

  1. Classes for computing parameters such as the estimated time offset or the estimated mean and standard deviation for a Wiener process model of the offset. Helper functions such as print_stream.

  2. Agents that generate streams of offsets or absolute times. These agents are created in two steps:

    (a) Create terminating functions that call one or more ntp services and obtain time offsets between the time read by the local system clock and the ntp services. The different functions use multiple ntp services in different ways, e.g., use the max or the median value.

    (b) Wrap these terminating functions using the source_func_to_stream wrapper to create agents that execute in their own threads.

  3. A process made using the wrapper single_process_single_source and then test the processes.

  4. Tests of the processes.