If you ever had a project that had a need for a real time clock and had no internet connection you probably made it with a RTC module like this one, and while this can work great; I had a GPS module that I decided to use to make a offline network time server.
The parts needed are:
- GPS module that works over a serial connection, I used one similar to this GPS Module
- ESP8266 board
- Functional MQTT broker on your network.
- Functional Arduino IDE ESP8266 device setup
- Code: VBranimir Github
- Upload code to esp8266, I used the following libraries: tinyGPS for decoding NMEA codes, GPS time from Arduino time library and pubsubclient for MQTT client setup.
- Connect your gps module to esp, look in the datasheet for voltage if needed, mine runs on 3.3V, so connect 3.3V, GND and the TX pin from the GPS to the hardware RX pin on the ESP. It is crucial that the TX pin is not connected during the upload process.
- Place the module in a window or somewhere on a open area with no obstructions for the satellite signals.
- Subscribe to the broker IP address and “/time” topic on other devices. Pubsubclient works great on Arduino/ESP and Mosquito works for both broker and client applications on GNU/Linux devices. So you’ll need mosquitto for broker and mosquitto-clients for clients, and than you can subscribe from any device in the network with:
mosquitto_sub -t TOPIC -h IP_ADDR -p 1883
- Give your GPS module some time to sync with the satelites.