Tag Archives: Raspberry Pi

PiNAP – converting my QNAP TS-41x to run Open Media Vault on a Raspberry Pi 5

I have several QNAP storage arrays at home. I store my Photos, Videos, MP3 collection and DVDs, etc, on them. I usually have two running at any one time and they usually mirror each other, so I have two copies of all my data at home at any time. I also backup to cloud storage and try and follow the “3-2-1 backup policy” – 3 total copies of your data, stored on 2 different types of media, with 1 copy kept off-site – to provide good resilience in the event of a major incident or failure.

However, recently I’ve been using them for other things, specifically storing my security camera footage, and other less important things, and the two live units I currently have are nearing capacity.

While rummaging through the loft a few weeks ago, I noticed that my old, retired QNAPs are still in the loft, powered down and collecting dust. I have three old 4-bay units (2 x TS-412 & 1 x TS-410), which are long since out of support, and no longer get updates or patches. The TS-412 was released in 2009, and served me well, I probably got 15+ years of life out of them. They finally went End Of Life on 31 December 2020, and I replaced them with two TS-431KX. I’ve had these for a few years now too, and even they are classed as “legacy”, so I expect them to go EOL soon.

The motherboards in the TS-410 & TS-412 look identical. The specification on the QNAP Site (TS-410 & TS-412) suggest the only difference is a slightly faster SoC in the TS-412. 1.2 GHz in the TS-412 verses 800Mhz in the TS-410. I suspect the same motherboard is used in other models, but I dont have access to any. Feel free to contact me if you find other QNAP models that use the same motherboard, that this conversation will also work with.

PiNAP – QNAP TS-412
PiNAP – TS-412 Motherboard

So, I had the brilliant idea to upcycle my old TS-412 devices to see if I could migrate them to use open-source software so I could squeeze more life out of them, than the manufacturer wants to support. It seems wasteful to replace them every 5 or 10 years, just because the software is no longer supported. The form factor is perfect. They are small and quiet and hold four full sized hard disks. I even have the old 3TB Seagate drives in them, so if I manage to upcycle them I could resurrect 18-24TB of storage!

Initially, I planned to try and get Linux to run natively on the existing hardware. I took one apart to get all the hardware specs and investigate the internals. The motherboard is based around a Marvell 6281 1.2GHz Arm CPU, with 256MB DDR2 RAM, 2 x Gigabit ethernet ports, and 4 x USB 2.0 ports. I could probably get Linux to run on this hardware, but its not particularly performant and shows the age of the 15 year old hardware. 256MB of RAM will be a challenge, even for Linux, and it does not have a standard bootloader.

However, I noticed that the SATA backplane connects to the old motherboard with what looks like a PCI connector. Once I had the backplane card out completely, I traced the pins and pads and compared it to the PCIe standard, and it looked similar, in fact I was confident it was a valid PCIe connection. The SATA Controller IC on the backplane is a Marvell 88SX7042 PCIe 4ch SATA-II bridge.

PiNAP - SATA Backplane
PiNAP – SATA Backplane

This got me thinking. The new Raspberry Pi 5 has a PCIe connector on it. I could potentially plug this backplane directly in to the Raspberry Pi 5 and run free open-source NAS software, rejuvenating my QNAPs to run up to date software, on modern hardware, economically, and undo their EOL status. I could continue to upgrade them in the future with new Raspberry Pi hardware, new software, giving them potentially decades more life. Very environmentally friendly, reducing e-waste and giving me handy additional storage, and a cool hardware project to tinker with at the weekends.

I called the project PiNAP, a portmanteau of “Pi” and “QNAP” 😊

PCIe Adapters

I searched for PCIe card slot adapters for the Raspberry Pi 5 and found a popular version on the PiHut website. I bought a SupTronics X1010 PCIe adapter. I also checked the Debian releases to see if they included the Marvell 88SX7042 drivers in the main kernel. I didn’t really want to have to compile a custom kernel. Lucky they are supported natively. So, this should be a simple plug and play project. (ominous foreshadowing)

When the adapter arrived, I was excited to try it out. I first tried it with no external power, booted the Pi5 and ran “lspci” and was disappointed to see no Marvel SATA adapter listed in the output. Thus began three weeks of tinkering and tearing my hair out trying to work out why the Pi5 wouldn’t recognise the PCIe SATA adapter. I will condense three weeks into two lines, but I tried every combination of dtparam in the boot.conf file, every variation of power to the card and drives, every variation of disks, with HDD and SSD and lots of Googling.

During this time, I was venting with my geeky friends on our WhatsApp group. My long time friend and Jedi level tinkerer Oli, also had a TS-412, and thought he’d try it our too. Within a single day his was working :-O. It would seem not all PCIe adapters are born equally. He bought a PCIe adapter made by 52PI (The Pi Hut – PCIe Slot for Raspberry Pi 5 (P02)) and it basically worked out of the box, with no disks or external power.

So, I bought one too, and behold, I had a working prototype (Thanks Oli)

$ lspci
0001:00:00.0 PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
--> 0001:01:00.0 SCSI storage controller: Marvell Technology Group Ltd. 88SX7042 PCIe 4-port SATA-II controller (rev 02)
0002:00:00.0 PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
0002:01:00.0 Ethernet controller: Raspberry Pi Ltd RP1 PCIe 2.0 South Bridge

I was slightly disappointed that I could not fit the Pi5 and PCIe adapter directly on to the backplane in place of the old motherboard. This would have been perfect. But the PCIe adapter is round the wrong way to fit on the card, without hitting the case. I briefly considered designing my own motherboard that took a Raspberry Pi 5 compute module and had a PCIe connector in the right place, so the new board would fit directly on to the old mounting holes, but although I’ve designed and built many PCBs in my time, I’ve never made one with PCIe traces. That requires controlled impedance and more complex routing. Maybe if there is demand I’ll consider that in phase two.

The QNAP case has a lot of spare room inside and there is ample space at the top to mount the Pi5 and adapter card, and I can run a PCI extension cable down to the backplane card. I also needed a high current 5v supply to power the hard disks and the Pi. The original QNAP power adapter is 120W 12v/10A which is enough to power everything, and I can reuse the existing power supply. I just need to add a reasonably large step-down converter to provide the 5v at 6-8A from the 12v supply to power the hard disks.

A typical 3.5” disk needs less than 1A for both 12v and 5v supplies. So, all four disks shouldn’t consumer more than 5v/4A and 12v/4A peak load.

The cooling fan is a PWM fan 4-pin fan, so the speed can be controlled with a PWM signal. I also added a temperature sensor in my design so I can speed up the fan if the interior of the case gets hot and slow it down as it cools to reduce noise.

Front Panel LED control

It would also be nice to get the original power switch and LEDs working on the front panel too, so the entire unit is more user friendly and functional. I traced the IO ribbon cable to reverse engineer the LED and switch board.

PiNAP - Front Panel LED Board
PiNAP – Front Panel LED Board

This LED Board has a very peculiar circuit and seems to mix 5v and 3.3v logic to power the LEDs. I’m sure this has something to do with reusing it on other QNAP models and in fact the motherboard has various ICs and regions unpopulated. I guess most of the hardware gets reused in lots of different models with a slightly different configuration, to reduce hardware designed time and variations.

PiNAP - Front Panel LED Board Schematic
Front Panel LED Board Schematic

The Green hard disk LEDs are powered via 5v and the Red hard disk LEDs is powered by 3.3v, both are controlled by a single MOSFET, operated by the same GPIO signal, but they have different power sources.

The LAN and eSATA LEDs are powered from 3.3v and the Status and USB LEDs are powered by 5v. They are each controller via a MOSFET using the Pi5 GPIO.

Seeing as I needed an external power circuit, fan connector and complex GPIO control of the LEDs, I designed a custom PCB mounting board to hold the Pi, PCIe connector board and provide the logic circuits and power connector. This would allow me to mount everything in one place, with tidy cable management and reuse of most of the internal cables and front panel. I added a piezo buzzer and amplifier, so the device could beep like the old QNAP on startup and shutdown and if there are errors. I managed to find all the right connectors on Digikey so I can reuse the original hard disk power cable, the front panel ribbon cable, and the power supply. I had these manufactured by JLCPCB and they arrive quickly.

PiNAP Conversion Card PCB
PiNAP - PCB Schematic v1.3
PiNAP Conversion PCB Schematic

LED Triggers

Connecting everything was relatively straight forward and the LEDs seem to work with the right combination of GPIOs enabled.

I can control the LEDs using a kernel Device Tree Overlay. However, only certain activities are supported in the stock Raspberry Pi kernel to trigger the LEDs.

You can list the available trigger modules by catting the trigger file:

$ sudo cat /sys/class/leds/disk1\:activity/trigger
[none] default rc-feedback kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 default-on input panic actpwr mmc1 mmc0 netdev rfkill-any rfkill-none rfkill0 rfkill1

I used the stock “heartbeat” trigger to flash the Status LED and the “netdev” trigger to flash the LAN LED to show ethernet activity.

However, there is no “sda”, “sdb”, etc, triggers in the stock kernel, so it’s not possible to automatically trigger the hard disk LEDs on disk activity. I wrote a small python daemon to monitor each hard disks activity and flash the hard disk LEDs accordingly, rather than compiling a custom kernel. This has a tiny overhead (less than 1% CPU) so even though it’s not ideal, it won’t impact performance.

The python daemon also monitors for USB button presses, and monitors the temperature sensor and adjusts the PWM fan speed accordingly.

Hardware Requirements

To convert your QNAP TS-412 to Raspberry Pi and Open Media Vault you will need the following hardware:

  • Raspberry Pi 5 (I am using the version with 8GB RAM, but 2GB or 4GB will probably work perfectly well too)
  • PCIe Slot for Raspberry Pi 5 (P02)
  • PCIe extension cable
    • PCIe 4.0 X1 90 Degree Extension Cable (30CM)
    • Not all cables work correctly. This one specifically has the right angles in the correct orientation, however you will need to sand off 5 mm of the edge of the PCB to get it to fit. This doesn’t affect its functionality as long as the modification is clean.
  • A PiNAP conversion kit (available from Tindie)
    • This includes;
    • the fully populated conversion PCB with 5v buck convertor.
    • the power socket and bolts
    • nylon PCB standoffs
  • You will reuse your QNAP case, power supply and internal cables.
  • You will need appropriate 3.5″ or 2.5″ hard disks.
  • You will also need a Dremel to cut out a hole in the back of the case and drill and 2mm drill bit to mount the power socket.
  • A soldering iron and steady hand to modify and solder a tiny wire on the SATA backplane to enable the SAT3 & SATA4 power.

PCIe extension cable

The PCIe backplane connector is very close to the bottom of the case. I struggled to find a PCIe extension cable that would fit, so I ended up modifying one. I sanded the edge of the PCB down to make it fit. Although this isn’t a recommended option, I couldn’t find an alternative, and double checked for short circuits before plugging it in.

PiNAP - PCIe Extension Modification Before
The PCIe Extension cable before modification hits the bottom of the case and doesn’t fit
PiNAP - PCIe Extension Modification
Modified PCIe cable. The edge is sanded down.
PiNAP - PCIe Extension Modification After
The modified PCIe cable now fits perfectly.
PiNAP - PCIe Extension Cable

Case Modification

The only big modification was to cut a hole in the back of the QNAP case to get access to the Pi5 network and USB ports. Maybe one day I’ll design a 3D printed panel, but for now, I just cut a large square hole with a Dremel!

I also drilled two small 2mm holes to mount the power connector in its original hole as there is no longer a motherboard behind it.

PiNAP - Modified Case
PiNAP – Modified Case

SATA Backplane Power

There is also another minor issue with the SATA backplane card. It uses two unused or reserved pins on the PCIe connector to control the power to the third and fourth hard disk connectors. I assume this is to limit the start up current and prevent all four hard drives spinning up at the same time. The custom motherboard uses these PCIe pins to stagger disks 3 and 4 to power up after a delay.

I couldn’t do this with the Pi5, without a custom motherboard. So, I opted to cut the traces on the backplane card that go to the PCIe connector and tie them permanently high to 3.3v. This would force all the drives to power up simultaneously, and generate large initial power draw, but we’ll see how it goes. In the future I could add a jumper wire, and perhaps route the power enable signals to a GPIO pin on the Pi5 if I do get issues with power surges, but if I use a big enough power supply it should be fine.

SATA3 power enable is on the outside pins of R492 & R495

PiNAP – SATA3 Power Enable

SATA4 power enable is on the outside pins of R493 & R494

PiNAP – SATA4 Power Enable

Both traces run down the PCB to the PCIe connector, where I cut them, soldered a small wire to them and tied them to a 3.3v. I found a 3.3v source at the bottom of the card on the positive pin of “EC9”

PiNAP – SATA Power Enable
PiNAP – SATA Power Enable
PiNAP – SATA Power Enable

Power Switch

The front panel power switch is terminated on the conversation board with a two pin header. This can be connected to the Pi5 power switch header, to enable the Pi5 to be controlled by the front panel power switch. You will need to solder a two pin header on to the Raspberry Pi 5, then connect the jumper wire.

PiNAP – Power Switch Connector
PiNAP – Power Switch Connector

USB socket and switch

Currently I don’t have a need for the front panel USB socket or switch. The socket can be connected to one of the spare USB ports on the Pi5 with an extension cable. The front panel USB switch is connected to a GPIO, but current doesn’t do anything other than flash the USB LED when pressed (just to show its working). This could be configured at a later stage to trigger a copy script on the Pi5 to copy the contents of the USB disks to a folder in OMV. You can buy a USB lead with a 4 pin JST-PH connector, and route the cable out of the back of the case though one of the holes and plug it into the Pi 5.

PiNAP – USB Cable

Software Installation

Raspberry Pi OS Installation

Create a USB flash disk with the latest Raspberry Pi OS 64 bit Lite image using the Raspberry Pi Imager software. Open Media Vault only works on the Lite version of the OS.

The Raspberry Pi 5 will not initially boot when installed in the PiNAP board because it cannot measure the power supply and refuses to boot from USB. You need to make a change to the /boot/firmware/config.txt. There are two options to achieve this:

Option 1 – Boot the Pi5 initially with USB-C Power

Before installing the Pi5 in the PiNAP board you can boot the Pi5 independently, install the Raspberry Pi OS and make some changes to the /boot/firmware/config.txt. Boot the Pi 5 from the USB flash disk with a compatible 5v USB-C supply and once it has booted, edit the /boot/firmware/config.txt file. Add the following lines to the end of the file:

usb_max_current_enable=1
dtparam=pciex1
dtoverlay=pwm,pin=12,func=4
dtoverlay=w1-gpio,gpiopin=14

Save and shutdown.

You can now install the Pi5 in the PiNAP convertor PCB and connect all the connectors in the case and continue the installation process.

Connect the Pi 5 to the network and ensure everything is up to date:

sudo apt update
sudo apt upgrade

Reboot the Pi 5

Option 2 – Edit the config.txt file on the USB flash disk before installing

When you have created the USB flash disk with the latest Raspberry Pi OS 64 bit Lite image using the Raspberry Pi Imager software, insert the flash disk into a suitable laptop or computer. In the “bootfs” partition you should find the file /config.txt. Add the following lines to the end of the file:

usb_max_current_enable=1
dtparam=pciex1
dtoverlay=pwm,pin=12,func=4
dtoverlay=w1-gpio,gpiopin=14

Save the file and eject the USB flash drive.

You can now install the Pi5 in the PiNAP convertor PCB and connect all the connectors in the case and continue the installation process.

Connect the Pi 5 to the network and ensure everything is up to date:

sudo apt update
sudo apt upgrade

Reboot the Pi 5

Verify PCIe SATA Backplane is recognised

$ lspci
0001:00:00.0 PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
--> 0001:01:00.0 SCSI storage controller: Marvell Technology Group Ltd. 88SX7042 PCIe 4-port SATA-II controller (rev 02)
0002:00:00.0 PCI bridge: Broadcom Inc. and subsidiaries BCM2712 PCIe Bridge (rev 21)
0002:01:00.0 Ethernet controller: Raspberry Pi Ltd RP1 PCIe 2.0 South Bridge

Open Media Vault Installation

I installed Open Media Vault (OMV) first and get that running, then install the Device Tree Overlay and daemon. OMV configured the ethernet port as “end0” not the default “eth0” so the device tree needs to reflect that.

The Open Media Vault install was very straight forward. The instructions are easy to follow. Follow the instructions for Raspberry Pi: https://github.com/OpenMediaVault-Plugin-Developers/installScript

wget -O - https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install | sudo bash

This should install Open Media Vault, you can then access the web interface using a browser.

Ensure everything is up to date:

sudo apt update
sudo apt upgrade

You can now setup Open Media Vault, install the various plugins you need, configure the disks and RAID Arrays and create a filing system and shares.

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 1 28.7G 0 disk
├─sda1 8:1 1 512M 0 part /boot/firmware
└─sda2 8:2 1 28.2G 0 part /
sdb 8:16 0 2.7T 0 disk
└─md0 9:0 0 8.2T 0 raid5 /export/data
/srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123
sdc 8:32 0 2.7T 0 disk
└─md0 9:0 0 8.2T 0 raid5 /export/data
/srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123
sdd 8:48 0 2.7T 0 disk
└─md0 9:0 0 8.2T 0 raid5 /export/data
/srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123
sde 8:64 0 2.7T 0 disk
└─md0 9:0 0 8.2T 0 raid5 /export/data
/srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123

Reboot the Pi 5

PiNAP Software Installation

cd ~
git clone https://github.com/JonRussell00/PiNAP.git
cd PiNAP
sudo cp pinap-leds.dts /boot/firmware/overlays/pinap-leds.dts
sudo cp pinap-daemon.py /usr/local/bin/pinap-daemon.py
sudo cp pinap-daemon.service /etc/systemd/system/pinap-daemon.service
sudo cp pinap-lan-led-trigger.service /etc/systemd/system/pinap-lan-led-trigger.service
sudo chmod +x /usr/local/bin/pinap-daemon.py

Configure OneWire for the Temperature Sensor

lsmod | grep w1

You should see w1_gpio and w1_therm listed. If not, load them:

sudo modprobe w1_gpio
sudo modprobe w1_therm

Reboot the Pi 5

You should now be able to see the onboard OneWire temperature sensor:

$ sudo ls -la /sys/bus/w1/devices/
lrwxrwxrwx 1 root root 0 Jun 18 01:39 28-00000xxxxxxx -> ../../../devices/w1_bus_master1/28-00000xxxxxxx
lrwxrwxrwx 1 root root 0 Jun 18 17:12 w1_bus_master1 -> ../../../devices/w1_bus_master1

Make a note of the number of your temperature sensors unique number starting “28-“

Test the sensor reads the correct temperature substituting your unique ID in the following command:

$ sudo cat /sys/bus/w1/devices/28-000000000000/temperature | awk '{printf "%.2f\n", $1/1000}'
28.75

Edit the daemon Python file /usr/local/bin/pinap-daemon.py and add your unique ID. Edit the TEMP_SENSOR_ID variable here:

# ---------------------------------------------------------------------------
# Temperature sensor configuration (1-wire DS18B20 on GPIO 14)
# ---------------------------------------------------------------------------
# 1-wire device ID for the temperature sensor
# ## UPDATE FOR YOUR SENSOR ID ##
TEMP_SENSOR_ID = '28-000000000000'
# Path to the sensor's temperature attribute (value is in milli-degrees C)
TEMP_SENSOR_PATH = Path(f'/sys/bus/w1/devices/{TEMP_SENSOR_ID}/temperature')

Device Tree Overlay

Build the device tree overlay:

sudo dtc -@ -I dts -O dtb -o /boot/firmware/overlays/pinap-leds.dtbo /boot/firmware/overlays/pinap-leds.dts

Edit the /boot/firmware/config.txt file. Add the following lines to the end of the file:

dtoverlay=pinap-leds

Enable the netdev LED trigger

sudo modprobe ledtrig-netdev
echo "ledtrig-netdev" | sudo tee -a /etc/modules

Double check your ethernet port is labelled “end0”.

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: end0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether d8:3a:dd:ff:ff:ff brd ff:ff:ff:ff:ff:ff
altname enxd83addffffff

if its still “eth0” you will need to change it to “end0” with:

sudo omv-firstaid

The LAN LED Trigger service assumes “end0”

Enable the Python Daemon

sudo systemctl daemon-reload
sudo systemctl enable pinap-daemon.service
sudo systemctl start pinap-daemon.service

Enable LAN LED Trigger Service

sudo systemctl daemon-reload
sudo systemctl enable pinap-lan-led-trigger.service
sudo systemctl start pinap-lan-led-trigger.service

Testing

At the end of the install process you should have the following lines at the end of your /boot/firmware/config.txt

usb_max_current_enable=1
dtparam=pciex1
dtoverlay=pinap-leds
dtoverlay=w1-gpio,gpiopin=14
dtoverlay=pwm,pin=12,func=4

Reboot the Pi 5

All the features should now be functional:

  • The Green Status LED on the front panel should make a heartbeat flashing pattern
  • The Amber LAN LED should flash in time with network activity
  • The four Green HDD LEDs should flash in time with disk activity
  • If you press the USB button on the front panel, the Blue USB LED should light and the PiNAP should beep. I currently don’t use the USB button, USB LED or eSATA LED for anything. They are there for future expansion and compatibility. There’s no reason why you can trigger a script when the USB button is pressed to copy files from the USB to the RAID Array if you need that functionality.
  • When you shutdown or startup the PiNAP should beep, in a similar fashion to the QNAP functionality.

⚠️ Important Safety Notes

  • Always disconnect power before working with hardware.
  • The SATA backplane modification requires precision soldering. Ensure you know what you are doing to avoid damaging the Raspberry Pi.
  • Test all connections before closing the case.

Troubleshooting

  • Pi won’t boot from PiNAP power: Ensure usb_max_current_enable=1 is set in config.txt
  • LAN LED not working: Verify ethernet interface is named “end0” using ip link show
  • Temperature sensor not detected: Check w1_gpio and w1_therm modules are loaded

Performance

I tested the disk performance using iperf3 on the PiNAP. I did a test from one PiNAP to the other, on a gigabit wired network, configuring the server end to store data on the raid array. I can swamp my gigabit network connection during the transfer, which is good enough for me.

pi@pinap01:~ $ iperf3 -s -F /srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123/data/iperffile
-----------------------------------------------------------
Server listening on 5201 (test #1)
-----------------------------------------------------------
Accepted connection from 10.1.0.182, port 38638
[ 5] local 10.1.0.181 port 5201 connected to 10.1.0.182 port 38650
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 111 MBytes 931 Mbits/sec
[ 5] 1.00-2.00 sec 111 MBytes 934 Mbits/sec
[ 5] 2.00-3.00 sec 111 MBytes 932 Mbits/sec
[ 5] 3.00-4.00 sec 111 MBytes 934 Mbits/sec
[ 5] 4.00-5.00 sec 109 MBytes 912 Mbits/sec
[ 5] 5.00-6.00 sec 110 MBytes 927 Mbits/sec
[ 5] 6.00-7.00 sec 111 MBytes 932 Mbits/sec
[ 5] 7.00-8.00 sec 111 MBytes 934 Mbits/sec
[ 5] 8.00-9.00 sec 111 MBytes 932 Mbits/sec
[ 5] 9.00-10.00 sec 109 MBytes 918 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
Sent 1.08 GByte / 1.08 GByte (100%) of /srv/dev-disk-by-uuid-abcdef12-39fd-456a-abcd-123456789123/data/iperffile
[ 5] 0.00-10.00 sec 1.08 GBytes 929 Mbits/sec receiver
pi@pinap02:~ $ iperf3 -c pinap01.woodside
Connecting to host pinap01.woodside, port 5201
[ 5] local 10.1.0.182 port 38650 connected to 10.1.0.181 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 115 MBytes 963 Mbits/sec 0 761 KBytes
[ 5] 1.00-2.00 sec 111 MBytes 929 Mbits/sec 0 1.04 MBytes
[ 5] 2.00-3.00 sec 111 MBytes 929 Mbits/sec 143 872 KBytes
[ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec 143 727 KBytes
[ 5] 4.00-5.00 sec 108 MBytes 906 Mbits/sec 0 834 KBytes
[ 5] 5.00-6.00 sec 111 MBytes 934 Mbits/sec 0 836 KBytes
[ 5] 6.00-7.00 sec 111 MBytes 931 Mbits/sec 0 837 KBytes
[ 5] 7.00-8.00 sec 111 MBytes 929 Mbits/sec 0 898 KBytes
[ 5] 8.00-9.00 sec 111 MBytes 931 Mbits/sec 143 725 KBytes
[ 5] 9.00-10.00 sec 109 MBytes 917 Mbits/sec 0 834 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 1.08 GBytes 931 Mbits/sec 429 sender
[ 5] 0.00-10.00 sec 1.08 GBytes 929 Mbits/sec receiver
iperf Done.

Summary

I have had my PiNAP conversations running for over a month now, without any issues. One has 4 x 3TB disks, giving about 8 TB RAID5 filesystem, the second has 4 x 4TB disks, giving about 11TB RAID5 filesystem.

PiNAP – Populated PiNAP Board
PiNAP – Populated PiNAP Board
PiNAP – Fully Assembled
PiNAP – Fully Assembled
PiNAP Back
Open Media Vault Dashboard
Open Media Vault Dashboard

They are fast, quiet and run the latest open source software. This is a great way to squeeze some extra life out of my old QNAPs and provide reliable RAID Storage for years to come.

If there is demand for the conversion kits on Tindie, and I sell more than 20 or 30, it might motivate me to design and build a customer PCB that fits in the exact space the old QNAP motherboard did, removing the need for any major alterations, soldering, or dremelling of the QNAP.

I sell on Tindie

Message me if you would buy a drop in conversation PCB for your QNAP, running a Raspberry Pi 5 compute module. If there is enough demand, maybe I’ll run a Kick Starter.

Hot water tank monitoring

I have electrically heated hot water in my house, and it takes ages to heat a whole tank. It heats up overnight on low cost electricity and we use it during the day. One constant frustration I have is there is no way of knowing how much hot water is left in the tank. I have to canvas my family and interrogate them on who’s had a shower or bath and how much washing up has been done. It would be so much better if I had a web page that showed the remaining hot water level in the tank !?

So, I attached temperature sensors up the side of the hot water tank and monitored them with a Raspberry Pi, of course ! 🙂

I have always wanted to use 1-wire devices in a project, and this was the perfect project. 1-wire devices make the cabling of many sensors easy as they all sit on a shared bus. You can get away with just 2 wires, a signal and a ground, as the devices can consume parasitic power from the signal line before communicating. However, to avoid any power issues and as I didn’t have a problem running more wires, I opted for three wires, power, signal and ground.

I am using the MAX31820 1-wire temperature sensors. They have a simple 3 pin transistor style package (TO-92) and there are lots of existing libraries and support for them. They’re also cheap. I decided to connect them using a ribbon cable, so I made little PCBs for them with a 4 pin header, to make the ribbon cable connection easy. I ended up using 6 way ribbon cable with 6 pin sockets, as it turns out 4 pin IDC sockets are a very difficult to find, where as 6 pin sockets are cheap as chips.

MAX31820 1-wire temperature sensor mounting PCB

MAX31820 1-wire temperature sensor mounting PCB

MAX31820 1-wire temperature sensors on small PCBs

MAX31820 1-wire temperature sensors on small PCBs

Example MAX31820 1-wire temperature sensors on small PCB attached to a ribbon cable

Example MAX31820 1-wire temperature sensors on small PCB attached to a ribbon cable

I already had a USB Adapter for 1-wire, which conveniently is supported by most of the 1-wire Raspberry Pi libraries. However, there are lots of ways of connecting 1-wire devices to a Raspberry Pi. The USB adapter is DS9490R. It takes an RJ11 plug to connect to the 1-wire bus, which also conveniently attaches to my ribbon cable. So, the solution is surprisingly neat.

The tank is pretty standard. Its covered in a insulated foam. I arbitrarily decided that 10 sensors was probably enough resolution. I marked the tank and made 10 equally spaced holes in the insulation with a pencil, then cleaned out the foam with the eraser end of the pencil, until I could see the shiny copper. I dabbed a blob of thermal paste in each hole, to assist with heat transfer from the copper tank to the temperature sensor, as I wouldn’t get direct mechanical contact. The boards and sensors just friction fitted in to the holes, and are kept in by the resistance of the foam on the boards. They are pretty snug and don’t fall out.

The cabling is simple, just attaching IDC connectors at the same regular intervals and then connecting the string of sensors to the Raspberry Pi.

Hot water tank

Hot water tank

Hot water tank with holes for temperature sensors marked

Hot water tank with holes for temperature sensors marked

Hole in the foam insulation showing the shiny copper tank

Hole in the foam insulation showing the shiny copper tank

Temperature sensor on mounting board inserted in the foam insulation

Temperature sensor on mounting board inserted in the foam insulation

Temperature sensors wired together with ribbon cable

Temperature sensors wired together with ribbon cable

Raspberry Pi connected via USB 1-wire adapter to string of sensors

Raspberry Pi connected via USB 1-wire adapter to string of sensors

Raspberry Pi connected via USB 1-wire adapter to string of sensors

Raspberry Pi connected via USB 1-wire adapter to string of sensors

Once the sensors were mounted and connected I installed OWFS (One Wire Filing System) on the Raspberry Pi which is a really easy way to read 1-wire sensors. It maps all the sensors found on the bus to a file system, so by reading the files you can read all the data and configure of all the connected sensors. Again there are loads of ways to access 1-wire devices. Using OWFS just made it easy for me. You could use Python or C, or any other myriad of languages, which all have 1-wire libraries.

Here are some instructions to install OWFS on a Raspberry Pi.

The OWFS maps the devices to a mount point. If you list the contents you get something like this :

root@raspberrypi:# cd /mnt/1wire/
root@raspberrypi:/mnt/1wire# ls -la
total 4
drwxr-xr-x 1 root root 4096 Nov  4 16:17 .
drwxr-xr-x 3 root root 4096 Mar  3  2015 ..
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.0BA759050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.168F59050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.229659050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.33A559050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.49B159050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.849459050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.AAB059050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.BBA459050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.C8AA59050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 28.E6B059050000
drwxrwxrwx 1 root root 4096 Mar 20 19:46 81.E1E324000000
drwxr-xr-x 1 root root 4096 Nov  4 16:17 alarm
drwxr-xr-x 1 root root 4096 Nov  4 16:17 bus.0
drwxr-xr-x 1 root root 4096 Nov  4 16:17 settings
drwxrwxrwx 1 root root 4096 Mar 20 19:46 simultaneous
drwxr-xr-x 1 root root 4096 Nov  4 16:17 statistics
drwxr-xr-x 1 root root 4096 Nov  4 16:17 structure
drwxr-xr-x 1 root root 4096 Nov  4 16:17 system
drwxr-xr-x 1 root root 4096 Nov  4 16:17 uncached

In each directory you can read either the cached or uncached version of the data, plus other details about the device.

root@raspberrypi:/mnt/1wire/28.0BA759050000# ls -la
total 0
drwxrwxrwx 1 root root 4096 Mar 20 19:46 .
drwxr-xr-x 1 root root 4096 Nov  4 16:17 ..
-r--r--r-- 1 root root   16 Nov  4 16:17 address
-rw-rw-rw- 1 root root  256 Nov  4 16:17 alias
-r--r--r-- 1 root root    2 Nov  4 16:17 crc8
drwxrwxrwx 1 root root 4096 Mar 20 19:46 errata
-r--r--r-- 1 root root    2 Nov  4 16:17 family
-r--r--r-- 1 root root   12 Nov  4 16:17 fasttemp
-r--r--r-- 1 root root   12 Nov  4 16:17 id
-r--r--r-- 1 root root   16 Nov  4 16:17 locator
-r--r--r-- 1 root root    1 Mar 20 19:46 power
-r--r--r-- 1 root root   16 Nov  4 16:17 r_address
-r--r--r-- 1 root root   12 Nov  4 16:17 r_id
-r--r--r-- 1 root root   16 Nov  4 16:17 r_locator
-r--r--r-- 1 root root    9 Mar 20 19:46 scratchpad
-r--r--r-- 1 root root   12 Nov  4 16:17 temperature
-r--r--r-- 1 root root   12 Nov  4 16:17 temperature10
-r--r--r-- 1 root root   12 Nov  4 16:17 temperature11
-r--r--r-- 1 root root   12 Nov  4 16:17 temperature12
-r--r--r-- 1 root root   12 Nov  4 16:17 temperature9
-rw-rw-rw- 1 root root   12 Mar 20 19:46 temphigh
-rw-rw-rw- 1 root root   12 Mar 20 19:46 templow
-r--r--r-- 1 root root   32 Nov  4 16:17 type

root@raspberrypi:/mnt/1wire/28.0BA759050000# cat address 
280BA759050000FA

root@raspberrypi:/mnt/1wire/28.0BA759050000# cat family 
28

root@raspberrypi:/mnt/1wire/28.0BA759050000# cat temperature
51.375

root@raspberrypi:/mnt/1wire/28.0BA759050000#

I run a shell script every 5 minutes to read the latest data from all the sensors and store it in a text file.

> cat /root/scripts/logtemp.sh 

#!/bin/sh
date | tr -d '\n' >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.E6B059050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.0BA759050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.49B159050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.168F59050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.C8AA59050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.33A559050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.849459050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.BBA459050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.229659050000/temperature >> /home/pi/templog.txt
echo -n ',' >> /home/pi/templog.txt
cat /mnt/1wire/28.AAB059050000/temperature >> /home/pi/templog.txt
echo ',END' >> /home/pi/templog.txt

I then use this data from a simple web page written in Python to display the latest temperatures in the tank. I decided 35 degrees Celsius is “cold”. If the water is below this I show it as blue (Cold), if its above this I show it as red (Hot). This is open to future expansion where I can fade the colour from red to blue depending on the temperature, more red for hot, more blue for cold, rather than a single colour, but that’s for another day.

> cat hotwater.py 

#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorage()

print 'Content-type: text/html\n\n'
print '<html><head></head><body>'

fn = '/home/pi/templog-latest.txt'
f = open(fn, 'r')
t = f.readline()
f.close()

temps = t.split(',')

o = ''

if form.getvalue("up","true") == 'true':
        up = True
else:
        up = False

for temp in temps:
        if len(temp) > 8:
                d = temp +"<br>"
        elif len(temp) < 2:
                if up:
                        o = o +'<tr><td bgcolor="#00FF00" align="center"></td></tr>'
                else:
                        o = '<tr><td bgcolor="#00FF00" align="center"></td></tr>'+ o
        elif temp.strip('\n') == 'END':
                z = 1
        else :
                n = int(float(temp))
                if n > 35:
                        if up:
                                o = o +'<tr><td bgcolor="#FF0000" align="center">'+ str(n) +'</td></tr>'
                        else:
                                o = '<tr><td bgcolor="#FF0000" align="center">'+ str(n) +'</td></tr>'+ o
                else:
                        if up:
                                o = o +'<tr><td bgcolor="#0000FF" align="center">'+ str(n) +'</td></tr>'
                        else:
                                o = '<tr><td bgcolor="#0000FF" align="center">'+ str(n) +'</td></tr>'+ o

print d +'<table width=150>'+ o +'</table>'
print '</body></html>'

I can access the web page from anywhere in my house, on my mobile phone, and it instantly shows the quantity of hot water left in the tank, plus each of the 10 individual temperature readings from the sensors. The query string parameter in the web page script reverses the order of the sensor readings in the tank. “up=false” or with no query string, is the default setting, where the temperatures are shown in the correct order, with the hottest water “floating” at the top of the tank. The alternate view, is for users who don’t want a view based on physics, and would rather the visualise a tank full of hot water emptying from the bottom. In this view the hot water is seen at the bottom, slowly draining away to empty. Not scientifically correct, but easier to explain to my 8 year old. Either way the bookmark is saved with the appropriate query string parameter, and everyone in my house can now tell how much hot water is left, before they get in the shower. No more showers suddenly going cold half way through.

Hot water monitoring web page. This shows the tank about half full of hot water. The top of the tank at 45 degrees. The bottom of the tank at 16.

Hot water monitoring web page. This shows the tank about half full of hot water. The top of the tank at 45 degrees. The bottom of the tank at 16.

 

Raspberry Pi – Stratum 1 NTP Server

This blog is mostly about robots, but not exclusively. 🙂

I needed an NTP server at home, as my security cameras were drifting out of sync. So, I thought I’d create a Stratum 1 NTP Server, with a Raspberry Pi and a GPS receiver.

There are lots of guides on the web, so I just followed the instructions, but it was very easy, once you understand the basics. There are two ways to synchronise the time on the Raspberry Pi to a GPS receiver. The first is just to use the GPS NMEA data to get the time. With a 1 Hz update, you have be accurate to about a second. However, some GPS receivers provide a pulse-per-second output, that provides a digital signal every second that can be attached to a hardware interrupt and this can be accurate to a microsecond.

Nearly all the instructions I used came from here :

I did a couple of other things too, as I had trouble keeping my Raspberry Pi’s running for longer than 3 months on an SD card. After 3 months of being continuously on, I usually got SD card corruption and the server died. I decided to switch this Raspberry Pi to use a USB flash drive to the filing system, and the SD card, just to boot.

The instructions for using a USB flash filing system are here :

I did this first, then configured the GPS / NTP. For this post, I’ll ignore the USB configuration, and it’s not relevant to the GPS / NTP install. It’s up to you if you need it. I’ve heard of lots of people that have run a Raspberry Pi for over a year on an SD card without any issues, and others who have had the same issues as me, with no more than a few months without file system corruption.

The first thing to do is connect the GPS receiver to the RPi. I used an Adafriut Ultimate GPS breakout board.  It has lots of useful features; it’s cheap, it’s easy to connect as it has 0.1” headers, it has a PPS output, it’s 3.3v and it has an external aerial mount.

Adafruit Ultimate GPS Breakout Board

Adafruit Ultimate GPS Breakout Board

The only problem I found with these GPS units is I couldn’t find a way to permanently change the baud rate. If you set the baud rate on the GPS receiver, the setting doesn’t survive a power cycle. If anyone knows how to do this, let me know. Even in production I am running the GPS at 9600 baud. I would have preferred to run it at a faster rate, which would give better accuracy as the NMEA data can be processed faster. But seeing as the clock is set using the PPS, its not a major issue.

I used a Slice of Pi prototype board to make it easy to connect the GPS to the Raspberry Pi. The wiring is straight forward, 3.3v and Gnd, Tx & Rx, and the PPS connected to GPIO pin 8.

Slice of Pi prototype board

Slice of Pi prototype board

I also have a Power Over Ethernet switch, so I added a PoE power adapter, so the Raspberry Pi would have minimal wiring. I bought a plastic box from Maplins and mounted the PoE adapter, RPi, GPS and external GPS connector all in the box. The box had a clear plastic lid, which also means you can see the RPi in action.

Power Over Ethernet adapter

Power Over Ethernet adapter

Assembled Raspberry Pi NTP Server

Assembled Raspberry Pi NTP Server

Assembled Raspberry Pi NTP Server in case with PoE

Assembled Raspberry Pi NTP Server in case with PoE

Once the hardware was attached, the software configuration follows the instruction linked above.

1. Disable serial comms on the console. We need it for the GPS.

Disable console output to serial

sudo vi /boot/cmdline.txt

find this :

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

and edit it to this :

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Disable the login prompt

sudo vi /etc/inittab

find the line near the end

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

add # to comment it out.

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

2. Configure Static IP

I need my NTP server to have a static IP

If you use DHCP, remove “ntp-servers” from the “request” line in /etc/dhcp/dhclient.conf

Remove /var/lib/ntp/ntp.conf.dhcp if present

sudo vi /etc/network/interfaces

Edit the following entry:

iface eth0 inet dhcp

Change it to (using your local network settings):

iface eth0 inet static
address 10.1.0.128
netmask 255.255.255.0
gateway 10.1.0.1
network 10.1.0.0
broadcast 10.1.0.255

reboot…

At this point you should see the GPS NMEA data coming from the serial port. Test it like this :

sudo cat /dev/ttyAMA0

If you dont see NMEA data, go back and check your wiring and baud settings.

3. Install gpsd

sudo apt-get install gpsd gpsd-clients python-gps
sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

test it recieves GPS data :

sudo cgps –s

+-------------------------------------------++---------------------------------+
|    Time:       2014-07-07T22:34:15.000Z   ||PRN:   Elev:  Azim:  SNR:  Used: |
|    Latitude:    51.501114 N               ||  20    73    246    32      Y   |
|    Longitude:   -0.142448 W               ||   1    72    117    44      Y   |
|    Altitude:   99.8 m                     ||  32    61    068    51      Y   |
|    Speed:      0.0 kph                    ||  11    45    142    38      Y   |
|    Heading:    67.1 deg (true)            ||  17    43    296    21      Y   |
|    Climb:      0.0 m/min                  ||  33    29    199    00      Y   |
|    Status:     3D FIX (10 secs)           ||  23    28    180    00      Y   |
|    Longitude Err:   +/- 4 m               ||   4    20    294    28      Y   |
|    Latitude Err:    +/- 3 m               ||  31    12    085    42      N   |
|    Altitude Err:    +/- 9 m               ||  14    11    035    17      N   |
|    Course Err:      n/a                   ||  28    08    250    00      N   |
|    Speed Err:       +/- 31 kph            ||  13    02    191    00      N   |
|    Time offset:     0.662                 ||  19    01    161    00      N   |
+-------------------------------------------++---------------------------------+

4. Configure gpsd to auto start

sudo dpkg-reconfigure gpsd

The configuration program will ask you a series of questions :

Start gpsd automatically? Yes
Should gpsd handle attached USB GPS receivers automatically? No
Device the GPS receiver is attached to: /dev/ttyAMA0
Options to gpsd: -n
gpsd control socket path: /var/run/gpsd.sock

reboot…

sudo cgps –s

You should get the same output as before. This shows everything is starting up correctly on boot.

5. Configure NTP

Make a backup of the ntp.conf file. Edit the conf file.

sudo cp /etc/ntp.conf /etc/ntp.old.conf
sudo vi /etc/ntp.conf

Remove the IP access restrictions

Comment out :

restrict -4 default kod notrap nomodify nopeer noquery

#restrict -4 default kod notrap nomodify nopeer noquery

Configure NTP to use the UK NTP pool servers.
I’m in the UK. If you’re not, pick the most local pool to you.

Replace:

server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

With:

pool uk.pool.ntp.org iburst

Add the local NTP server from your ISP.

server ntp.eclipse.co.uk iburst

Restart NTP and check its working.

sudo /etc/init.d/ntp restart
sudo ntpq -p -n

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*213.249.130.101 10.100.94.8      2 u    3   64  377  120.208   37.434  53.254
+87.124.126.49   195.66.241.3     2 u   10   64  377   32.008   -8.111  99.007
 82.219.4.30     .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 217.10.144.130  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
-151.230.30.222  103.7.151.4      2 u   25   64  377   47.016    0.743  98.865

Basic NTP is now working, but without GPS. Even without GPS, its still accurate to about 37ms.

6. Add the GPS configuration to NTP

Edit ntp.conf

sudo vi /etc/ntp.conf

add :

# Server from shared memory provided by gpsd
server 127.127.28.0 minpoll 4 maxpoll 4
fudge  127.127.28.0 time1 0.000 refid GPS

Restart NTP and check its working.

sudo /etc/init.d/ntp restart
sudo ntpq -p -n

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*127.127.28.0    .GPS.            0 l    7   16  377    0.000   -353.23 15.024
-213.249.130.101 10.100.94.8      2 u   62   64  377   52.603   -3.554  77.753
-87.124.126.49   195.66.241.3     2 u    6   64  377   42.207   -5.468  78.352
 82.219.4.30     .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 217.10.144.130  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
+151.230.30.222  103.7.151.4      2 u   16   64  377   47.016    0.743  58.425

Adjust the time1 fudge offset to compensate for drift. The GPS NMEA input is taking about 350ms to process.

fudge  127.127.28.0 time1 0.350 refid GPS

Restart NTP and check again. The GPS inout should be more accurate. (now only 11ms out)

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*127.127.28.0    .GPS.            0 l    3   16  377    0.000   11.721  38.208
+213.249.130.101 10.100.94.8      2 u   33   64  377   72.434    1.227  98.033
-87.124.126.49   195.66.241.3     2 u   48   64  377   50.215   -0.824  76.877
 82.219.4.30     .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 217.10.144.130  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
-151.230.30.222  103.7.151.4      2 u   56   64  377   48.522    0.481  50.334

7. Install user mode PPS module

For more details see : http://vanheusden.com/time/rpi_gpio_ntp/

sudo wget http://vanheusden.com/time/rpi_gpio_ntp/rpi_gpio_ntp-1.3.tgz
sudo tar -zxvf rpi_gpio_ntp-1.3.tgz
sudo cat rpi_gpio_ntp-1.3/readme.txt

Read the instructions. You must build and install the program:

sudo cd rpi_gpio_ntp-1.3
sudo make install

You probably want to let rpi_gpio_ntp start at boot.

To do so, edit /etc/rc.local

sudo vi /etc/rc.local

and add the following line (BEFORE the “exit 0” statement and AFTER the “#!/bin/sh” line):

/usr/local/bin/rpi_gpio_ntp -N 1 -g 8

This assumes that the PPS signal of the GPS is connected to GPIO pin 8 which is physical pin 24.

reboot…

8. Add the PPS configuration to NTP

Edit ntp.conf

sudo vi /etc/ntp.conf

add :

# Server from PPS module 
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge  127.127.28.1 refid PPS

Restart NTP and check its working.

sudo /etc/init.d/ntp restart
sudo ntpq -p -n

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+127.127.28.0    .GPS.            0 l   15   16  377    0.000   65.031  38.403
*127.127.28.1    .PPS.            0 l   14   16  377    0.000    0.001   0.006
x213.249.130.101 10.100.94.8      2 u   12   64  377   79.034   16.835  82.844
+87.124.126.49   195.66.241.3     2 u   26   64  377   28.945    1.316  42.948
 82.219.4.30     .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 217.10.144.130  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
-151.230.30.222  103.7.151.4      2 u   39   64  377   36.126    2.120  57.079

This shows the Raspberry Pi system clock is accurate to 1us !!

My final ntp.conf file :

driftfile /var/lib/ntp/ntp.drift

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Server from shared memory provided by gpsd
server 127.127.28.0 minpoll 4 maxpoll 4
fudge  127.127.28.0 time1 0.550 refid GPS

# Server from PPS module 
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge  127.127.28.1 refid PPS

# You do need to talk to an NTP server or two (or three).
server ntp.eclipse.co.uk iburst

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: 
pool uk.pool.ntp.org iburst

# By default, exchange time with everybody, but don't allow configuration.
#restrict -4 default kod notrap nomodify nopeer noquery
#restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

The final NTP Server installed in my garage, with an external GPS aerial on the roof.

Assembled Raspberry Pi NTP Server in case with PoE

Assembled Raspberry Pi NTP Server in case with PoE