GPS & Real Time Clock Stratum 1 Time Server




Some History(1)

UTC – The World's Time Standard
Coordinated Universal Time (UTC) is the basis for civil time today. This 24-hour time standard is kept using highly precise atomic clocks combined with the Earth's rotation.

A Standard, Not a Time Zone

UTC is the time standard commonly used across the world. The world's timing centers have agreed to keep their time scales closely synchronized - or coordinated - therefore the name Coordinated Universal Time.

Atomic and Solar Time

Two components are used to determine UTC:

International Atomic Time (TAI):

A time scale that combines the output of some 400 highly precise atomic clocks worldwide, and provides the exact speed for our clocks to tick.

Universal Time (UT1):

Also known as astronomical time or solar time, it refers to the Earth's rotation. It is used to compare the pace provided by TAI with the actual length of a day on Earth.UT Started in 1884

Universal Time (UT) was created at the International Meridian Conference in 1884. This is the basis for the 24-hour time zone system we know today.

At the time, Greenwich Mean Time (GMT) was chosen as the world’s time standard. The reference line or starting point, the Prime Meridian, was determined to be the transit circle at the Royal Observatory in Greenwich, London. The transit circle is a part of the telescope's mechanics and it is still cited as the prime meridian's original reference (0° longitude).

From GMT to UTC

In 1960, the International Radio Consultative Committee formalized the concept of UTC, and it was put into practice the year after. The name Coordinated Universal Time was officially adopted in 1967.

Why UTC – not CUT or TUC?

UTC was adjusted several times until 1972, when leap seconds were introduced to keep UTC in line with the Earth's rotation, which is not entirely even, and less exact than atomic clocks.

GMT is now a Time Zone

Until 1972, Greenwich Mean Time (also known as Zulu time) was the same as Universal Time (UT).

The difference between GMT and UTC

Since then, GMT is no longer a time standard. Today, Greenwich Mean Time (GMT) is only the name of a time zone that is used by a few countries in Africa and Western Europe, including the UK during winter and all year in Iceland.

References and Credits

(1) -

Step 1: Problem Statements

Since I have discovered the well-known ESP8266-01 WiFi modules, I have created several IoT devices. Two such devices can be found here:

Up to date, I now have 12 ESP-01 or similar devices connected to my home network.

Problem Statement 1:

Living in what is called a "third world country", or as the Americans call it "#$%&-hole Country", we experience constant power failures know locally as "load shedding". Mostly not due to constraints on our electricity grid, but due to the failures and incompetence of the local ANC authorities.

Problem Statement 2:

Internet connectivity is obviously severely impacted by all the power failures. Even with ADSL connectivity, there is a constant failure of internet services. Even at the local exchange, internet connectivity can not be guaranteed.

Each time the power goes out in my town (Vanderbijlpark), the largest internet service provider (Telkom) fails miserably. They loose connectivity to the "outside world", and although the ADSL routers connect, the "Telkom" DNS servers fail. The most obvious cause is that due to "constant affirmative-action-shopping", back-up batteries are a trusty source of income for our locals.Thus, no back-up batteries, no internet connectivity.

Problem Statement 3:

Ageing telecommunication networks, still relying on copper wires, are no longer maintained. It in not too uncommon to loose internet connectivity for 8 hours a day. This is basically my BIGGEST PROBLEM with my IoT devices. The only solution for me will be to replace the underground cables running from my house to the local termination points to my service provider "Telkom", at my own cost.

Problem Statement 4:

All my own IoT devices relies on an NTP Time Server to keep time. After a power failure, my IoT devices will reboot, and try to connect to a NTP time server to get the current time. With the time not set, most of my devices will stay in a "disabled" mode, as they all rely on time to switch On/Off outputs.

With no internet, these IoT devices does not work.

Problem Statement 5:

The largest, and most reliable mobile network in my area (Vodacom" can provide me with a reliable internet connection at a very high cost. However, who still wants to connect to the internet using "EDGE"? Yes, you are reading correct...... "EDGE".

Problem Statement 6:

To run my IoT devices reliably, a reliable connection to a reliable time server is needed. This time server must be able to provide the following:

- Be able to function without any internet connectivity

- Be able to function reliably with constant power failures

- Low power

- Must be accurate to within one minute

Problem Statement 7:

Due to the corruption and effects of strikes at our country's postal system (SAPO), we no longer have the privilege of purchasing ANYTHING of eBay. Tracking numbers shows that parcels still arrive in South Africa, but always disappears mysteriously at Customs, or at the local post office.

Step 2: Where to Get the Time

To be able to broadcast time, there is ONE, and only ONE requirement. We need TIME......

So where can we find the time, without a reliable power supply, or a reliable internet connection?

Here are some options:

Radio Signals: (1)

A radio clock or radio-controlled clock (RCC) is a clock that is automatically synchronized by a time code transmitted by a radio transmitter connected to a time standard such as an atomic clock. Such a clock may be synchronized to the time sent by a single transmitter, such as many national or regional time transmitters

Such systems may be used to automatically set clocks or for any purpose where accurate time is needed. One common style of radio-controlled clock uses time signals transmitted by dedicated terrestrial longwave radio transmitters, which emit a time code that can be demodulated and displayed by the radio controlled clock. The radio controlled clock will contain an accurate time base oscillator to maintain timekeeping if the radio signal is momentarily unavailable. Other radio controlled clocks use the time signals transmitted by dedicated transmitters in the shortwave bands. Systems using dedicated time signal stations can achieve accuracy of a few tens of milliseconds.

Unfortunately, this option is NOT available in South Africa.

GPS Time: (2)

Using any low-cost GPS receiver, accurate time information can be retrieved from the GPS. Depending on the GPS receiver, time can be updated at least once every second, depending on the type of GPS receiver used.

An excellent option is a cheap and widely available uBlox GPS receiver.

Real Time Clock: (3)

There are many different real time clock chips available, DS1307, DS3231 etc. These chips can be easily connected to a microchip to get relatively accurate time. Accuracy is dependent on factors such as battery back-up, temperature or oscillator frequency drifts.

A good option is the DS3231 RTC as used by thousands of Raspberry Pi users.

For the purpose of this Instructable, I will only concentrate on GPS and Real Time Clock time.

References and Credits

(1) -

(2) -

(3) -

Step 3: GPS Time

Almost all GPS receives available to the hobbyist, have a serial port. This can be used to "read" the location and time information as received by the GPS receiver.

Thousands of examples and options are available on Google for the Arduino or Raspberry Pi user.


  • Reading the serial data from a GPS receiver with a micro controller, the time can be obtained quit easily.
  • No user actions are required to get accurate time.
  • Relatively cheap.
  • No user interface required to set the time.
  • Time is not affected by power failures.
  • No battery back-up is required.
  • Time accuracy normally within one second.


  • GPS receivers depends on receiving very weak signals from more than one satellite.
  • Data reception on a GPS receiver can depend on the current weather conditions.
  • In some cases, external antennas are required to receive the GPS signals for indoor use.
  • After a power failure, a GPS receiver can take up to 5 minutes to lock on to enough satellites to receive accurate time.

The GPS I will be using, transmits data every second at a baud rate of 9600. Although the GPS has Serial Rx and Tx pins, I will only use the Serial Tx pin to read data from, requiring only one I/O pin on the D1 Mini. However, using the build-in serial port of the D1 Mini, both the Rx and Tx pins on the D1 Mini will be used for serial communications.


Should your GPS use a different baud rate, the baud rate should be adjusted accordingly in the final sketch.

Alternatively, if you will be using a uBlox GPS, the following software can be used to adjust the baud rate to 9600 baud.

Step 4: Real Time Clock Time

In the world of Arduino, Raspberry Pi, Microchip etc., there are numerous variations and options available to get your hands on may different types and formats of real time clocks.

From stand-alone chips, to numerous break-out boards to suite ever hobbyist needs, the options are endless.


  • A real time clock does not depend on any external signals or devices to keep relative accurate time.
  • Cheap and widely available.
  • Accurate to a few minutes per year.


  • Depending on the real time clock chip used, time keeping can be influenced by temperature and humidity.
  • Needs some sort of user intervention to set the time initially.
  • Some sort of user interface with buttons and a display is needed to set the time.
  • Requires a battery back-up to keep track of time in case of a power failure.
  • Time needs to be updated at least once a month, or year, depending on the real time clock chip used.

The Real Time Clock that I will be using, is the DS3231 RTC for Raspberry PI. This is a very small module, which already includes a back-up battery for the RTC. Communication is done using the I2C protocol, thus only requiring two I/O's on the D1 Mini.

Step 5: Network Connectivity

OK, so my initial statement under Step 3 was wrong....

To be able to broadcast time, there are actually TWO requirements......

  • We need the TIME
  • We need a means to broadcast the TIME

Once we have obtained an accurate time, we still need to share this time with the devices that actually requires the time.

In my case, the items that requires the time, are all IoT devices. This means that all of the devices are already connected to my home network. Either via a WiFi connection, or via a RJ45 network cable. Thus, I only need to be able to broadcast the time on my home network.

This leaves us with two options:

Arduino with Network Shield:

Due to the size and cost of an Arduino Genuino/Uno as well as a WS5100 network shield, this option was not considered.

ESP8266 WiFi Module:

With so many ESP modules available, I decided to base my design on the Wemos D1 Mini and/or NodeMCU.

Due to the changes and associated problems of the new flash memory chips on the latest ESP8266-01S modules, I did not consider this module as an option (1).

References and Credits

(1) -

Step 6: Time Protocol

UDP Time Protocol

To keep the format consistent with standard internet NTP servers (1), the time server will send and receive timestamps using the User Datagram Protocol (UDP) on port number 123 (2)

This protocol uses a timestamp consisting of 48 bytes, which contains a 64-bit timestamp with the current time in bytes 41 - 48. However, one must note that this timestamp does not contain the actual time, but shows the number of seconds from 1 January 1900.

Bytes 41 to 43 contains a 32-bit value of the seconds since 1 January 1900.

Bytes 44 - 48 contains a 32-bit value of the hundreds of seconds.

1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1


| Seconds |


| Seconds Fraction (0-padded) |


References and Credits

(1) -

(2) -

Step 7: Concept Design

Obtaining the Time

Looking at the advantages and disadvantages using a GPS or Real Time Clock as a time source, I decided to make use of both time sources.

Main Time Source

Use a GPS as the main source to obtain the time.

Use the time obtained from the GPS to synchronize the Real Time Clock once every minute with the time from the GPS.

For this build, i will be using an old uBlox 6 GPS from an ArduPilot Flight Control System. This GPS works well on 3.3V, thus no level converters are needed to interface with the 3.3V ESP module.

Alternative Time Source

Should the GPS signal fall away due to weather, or during the boot-up time of the unit, accurate time is obtained from a Real Time Clock.

For this build, I will make use of the Raspberry Pi DS3231 Real Time Clock module. This module works on 3.3V via I2C, and does not require any level converters to operate on 3.3V.

User Interface

With the time set by the GPS, the unit will not require any sort of interface for adjusting the time.

A single LED can be used to indicate the status of the unit.

Additional information or settings can be made available on an internal web page.

Power Supply

As some of my IoT devices are battery powered, the system must be able to work even in the event of a power failure. For this reason, the power supply to the unit will be 12V DC.

The NodeMCU and Wemos D1 Mini operates on 5V, with an on-board 3.3V voltage regulator for the ESP chip. Therefore, for the unit to operate from 12V, the an extra voltage regulator will be required. I will be using a small and reliable dc/dc converter for this.

As I already have a battery back-up system connected to my main network router as well as network switch, 12V DC is always available.

Refer to this Instructable:

WiFi Module

For this project, i will make use of a Wemos D1 Mini.

Step 8: Circuit Diagram

The circuit consist of only a few items.

Power Supply

  • This consist of a DC power jack, reverse polarity protection diode, power switch, and a small 5V DC/DC converter.
  • Note that the DC/DC converter output must be adjusted to 5V before connecting to the D1 Mini.
  • This converter can be replaced with a standard 7805 if required.


  • The D1 Mini is supplied with 5V from the DC/DC converter.
  • The D1 Mini has a on-board 3.3V regulator, which is used to power the Real Time Clock as well as the GPS.


  • The GPS power is obtained from the 3.3V supply of the D1 Mini.
  • The transmit (TX) line of the GPS is connected to the D1 Mini receive (RX).
  • The GPS receive (RX) is not used, and left unconnected.

Real Time Clock

  • The DS3231 RTC is an I2C device, requiring only two I/O pins.
  • The RTC is connected to the D1 Mini I2C ports on pins D1 and D2.
  • `The I2C bus requires a 4K7 pull-up resistor on each of the lines. The DS3231 module used, already have these resistors fitted to the module, thus the pull-up resistors are not needed.

WiFi Config Button

  • This button is connected to D3.
  • No pull-up resistor is needed, as the software configures the internal pull-up resistor of D3.

Status LED

  • A status LED is connected to D4.
  • Resistor R1 limits the current through the LED

Step 9: Building the Circuit Board

With only three modules and one resistor, I opted to build the circuit on Veroboard or Stripboard.

  • Make sure to cut all the tracks where indicated.
  • The Real Time Clock plugs into 5 header pins.
  • The D1 Mini plugs into a set of 8 header sockets.
  • The small DC/DC converter is soldered directly onto the board.
  • Finally, a 3-pin header will be used to connect the GPS receiver to the board.

Note that the two 10K resistors connected to pins 3 & 4 of the Real Time Clock pins are not required. These resistors are already fitted on the Real Time Clock module.

Step 10: The Enclosure

Assembly of the unit should not present any problems.

Mounting of the components

Mount the following to the back of the enclosure:

  • 2.1mm DC Socket
  • Power switch
  • Push button

Mount the LED to the front of the enclosure, using a LED holder.

As I have mentioned earlier in the Instructable, I am using an old GPS receiver from one of my old drones. This means that the GPS was already mounted inside a GPS holder, and came with the raised mounting stand.

Mount the GPS receiver to the top of the enclosure. Remember to drill an additional hole for the GPS wiring

Wiring of the components

Wire up the components as per diagram. This will leave you with only four wires that needs to be connected to the circuit board:

  • +12V DC
  • Anode of the indication LED
  • Push button
  • 0V

Step 11: Assembly and Testing

Solder the four wires from the enclosure to the circuit board as indicated.

  • Do NOT insert the D1 Mini yet.
  • Do NOT insert the Real Time Clock yet.
  • Do NOT connect the GPS receiver yet.

Tests and Measurements

  • Power up the unit via the DC socket. Ensure that the polarity in the circuit board is correct.
  • Measure the output of the DC/DC converter.
  • Using a small screwdriver, adjust the output of the DC/DC converter to 5.0V.
  • Measure that there is 5V available on pins 1 & 2 of the D1 Mini headers.
  • Switch off the unit.
  • Measure the resistance between pins 2 & 4 of the D1 Mini headers. Resistance should be very high, or infinity.
  • Press the push button, and measure again between pins 2 & 4 of the D1 Mini headers. Resistance should be very low (less than 10 ohm).
  • Switch on the unit, and insert a jumper wire between pins 1 & 3 of the D1 Mini headers. The front LED should come on.
  • Switch off the unit, and insert ONLY the D1 Mini.
  • Switch power back on, and confirm that there is 3.3V output from the D1 Mini on pin 16.
  • Measure across pins 1 & 5 of the Real Time Clock headers. You should measure 3.3V.
  • Measure across pins 1 & 3 of the GPS headers. You should measure 3.3V.
  • Switch of the unit, and insert the Real Time Clock.
  • Switch power back on, and confirm that there is still 3.3V output from the D1 Mini on pin 16.
  • Switch of the unit, and connect the GPS receiver.
  • Switch power back on, and confirm that there is still 3.3V output from the D1 Mini on pin 16.
  • Switch of the unit, and disconnect the GPS receiver.

Your circuit is now ready to be programmed.

Step 12: Uploading the Code

! ! ! N O T E ! ! ! ! ! ! N O T E ! ! !

The GPS has to be disconnected while programming the D1 Mini.

! ! ! N O T E ! ! ! ! ! ! N O T E ! ! !

During programming, the D1 Mini will be powered by the USB cable. Do not connect the external 12V power supply to the unit.

As we are using the D1 Mini, no programmer is required. The code is uploaded using the standard USB cable supplied with the D1 Mini.

Connect the USB cable to the D1 Mini, and plug the USB cable into your computer.

  • Open the Arduino IDE, and load the sketch.
  • Compile the sketch, and make sure there are no errors.
  • If the sketch fails to compile, you might be missing a library. The ZIP file should includes most of the libraries that I used during the development.
  • Select NodeMCU 1.0 (ESP12E).
  • Leave all settings as is.
  • Select the correct serial port.
  • Upload the sketch.

When the sketch upload is successful, the LED should start to flash rapidly for 10 seconds.

If all goes well, the Serial Monitor will respond with several lines of feedback.

Unplug the USB cable, and connect the GPS to the unit,.

References and Credits

  • Credit goes to Absolutelyautomation for the initial code that I used in this project.
  • Although I could not get his code to compile, I have used his UDP code in my sketch.
  • Please visit his Instructable here:

Step 13: Network Setup

The unit now have to be connected to your local network via WiFi. As different systems need to connect to the NTP Server, it will be best to assign a fixed IP Address to the NTP Server.

Determining your Network Settings

This can be done on a Windows PC using the command prompt:

  • Open up Command Prompt, and type ipconfig.
  • This will present you with some network information that you will need to set up your NTP Server.
  • You will see your computer IP Address (in the example,
  • You will see the Subnet Mask (in the example
  • You will see your Default Gateway (in the example

Finding a Fixed IP Address

  • On most Routers or DHCP Servers, IP addresses from 1 to 50 is reserved for fixed IP use.
  • Routers are normally set to the first IP address in the range (in the example,
  • When more than one router is installed, the IP addresses will increase accordingly.
  • To obtain your fixed IP address, use numbers from 10 - 50 to find an unused IP Address.
  • For example, try
  • Open Command Prompt, and type in the following:
  • ping
  • If you get a valid reply, it means that the IP address is already in use.
  • Try the next IP Address
  • ping
  • If there is no reply, this IP Address in not in use, and you can use this as your NTP Server fixed IP Address

We now have tall the information available to connect our NTP Server to our local network:

  • Fixed IP Address:
  • Subnet Mask:
  • Default Gateway:

Step 14: Connecting to Your WiFi Network

Connecting the NTP Server to your local WiFi Network

  • Power up the NTP Server.
  • While the LED is still flashing fast (less than 10 seconds from power-up), press the button at the back of the unit.
  • The LED will now stay on.
  • On any computer or smartphone, view the WiFi Connections.
  • Within a few seconds, you should see a new Open network, called 'IoT NTP Server'.
  • Connect to this WiFi network. No password is required.
  • Once connected, go to any internet browser.
  • Type in This is the default IP Address of your NTP Server.
  • The WiFiManager page will open up.
  • Select Configure WiFi
  • A list of available WiFi connections will be displayed.
  • Select the WiFi network you wish to connect the NTP Server to.
  • Enter the network password
  • In the box below the password, enter your fixed IP Address that you want to assign to the NTP Server (in this example,
  • In the next box, enter the Default Gateway (in this example,
  • In the last box, enter the Subnet Mask (in this example,
  • When done, press the Save button.
  • The web page should indicate that the new credentials were saved.
  • At this stage, the NTP Server will switch off the 'IoT NTP Server'.

At this stage, the Status LED can indicate the following:

  • Flashing fast - Real Time Clock does not contain valid time and date information.
  • Flashing once every 2 seconds - Real Time Clock contains valid time and date information.

Step 15: NTP Server Interface

Web Interface

Using your web browser, type in the IP Address of your NTP Server.

You will be greeted with a Status page.

  • After power-up of the circuit, the web interface will indicate the status of the GPS and Real Time Clock.
  • Initially, it can take up to five minutes or more for the GPS to lock onto enough satellites.
  • During this period, time will be obtained from the Real Time Clock.
  • Once the GPS is operational, time will be obtained from the GPS.

Status LED

  • Flashing once every second - Time is obtained from the GPS
  • Flashing once every two seconds - Time is obtained from the Real Time Clock
  • Flashing twice per second - Real Time Clock time invalid, and no GPS time available.


Apart from initial set-up of the WiFi connection, the button serves no further purpose during operation.

Your NTP Time Server is now ready for use.

Step 16: Conclusion

By using only three widely available modules, I was able to create a stable and reliable wifi connected NTP Time Server.

  • Time is accurate to 1 second when using the GPS.
  • Although the time obtained from the GPS is much more accurate, the update rate of the GPS is only once/second.
  • Time will be accurate to within a minute when the GPS signal is not available.

I hope you enjoyed this Instructable.





    • Fandom Contest

      Fandom Contest
    • Frozen Treats Challenge

      Frozen Treats Challenge
    • Classroom Science Contest

      Classroom Science Contest

    2 Discussions


    6 months ago

    I enjoyed your logical analysis of the problem and the thought processes you used to solve it. I have avoided IoT devices until now due to the unreliable nature of internet connections. I shall have to revisit that assessment now that your instructable has given us a means of keeping our local networks alive when the web is down. Very well done instructable!
    Oh, and for the record, not all Americans think third world countries are "#$%&-hole Countries". Many of us are trying to preserve American ideals despite the ravings of some poorly chosen souls in Washington.


    6 months ago

    Very nice Instructable Eric. I especially liked the historical information you included along with the excellent technical descriptions you used.
    My old Garmin GPS-II can now serve a useful function as the primary time server for my network.
    Good job!