# Stratum 0 Clock

Author: mngugi.dev
Published: 2025-12-07
Updated: 2025-12-07
URL: https://www.mngugi.dev/posts/2025-12-07-stratum-0-clock/

> Trying to use NMEA for local timing

Progress on this has been okay. Working on it between family and rest. I got some Heltec Wireless Trackers early this year for an IoT project. I later learned of the Meshtastic project and tried it out. It’s pretty neat but I am probably the only node in my entire country.

![Heltec Wireless Tracker](../art/stratum-clock/heltec-wireless.jpeg)

The idea was to have on these on a water tower and get good GPS fixes that would be transmitted to a module connected to a server through USB. Meshtastic allows you to log NMEA packets straight to serial. Thought it’d be way straightforward after this but …I cannot turn of device operations logs from appearing.

Attempts to use them as is have crashed chronyd. Currently working on creating a service to read this, filter the unnecessary fluff and present it as a device. The code is clumsy at best. Still trying to iron it out. Any help would be appreciated. Wrote this piece with the help of GPT but it didn’t quite workout. Will give it a try again later tomorrow.

```nix
# services.nix
  systemd.services.nmea-filter = {
    description = "Filtered NMEA serial from Meshtastic device";
    after = [ "dev-ttyACM0.device" ]; # Wait for the hardware
    bindsTo = [ "dev-ttyACM0.device" ];
    wantedBy = [ "multi-user.target" ];
    serviceConfig = {
      Type = "simple";
      # We use 'sh -c' to ensure the pipe and redirections are handled correctly by a shell
      ExecStart = ''
        ${pkgs.socat}/bin/socat -d -d \
          PTY,link=/dev/ttyNMEA,raw,echo=0,mode=660,group=dialout \
          EXEC:"${pkgs.bash}/bin/sh -c '${pkgs.coreutils}/bin/stdbuf -oL ${pkgs.gnugrep}/bin/grep --line-buffered \"^\\$\" /dev/ttyACM0'"
      '';
      Restart = "always";
      RestartSec = "5s";
    };
  };
```

I still need to figure out how to share these NMEA loads from remote nodes with better visibility over serial to local nodes. It’s probably better to use the simple node here over USB alone but I’m curious of benefits of multiple GPS streams.
