Table of Contents

PC Engines APU1 - Hopf NTP Server

Requirements

Documentation

Serial cable

Install packages

Install NTP

Hopf DCF /etc/ntp.conf

Check timecode

ntpq -c 'cv 0 timecode'
timecode="\x02CB154556010120\x0a\x0d\x03"

Nagios Hopf 7001 check

#!/bin/bash
#
# Tested with Hopf 7001 DCF Base station with 7245 serial interface boards
# Datastring 7001/6021
#
# BS, 2013/05

ntpq="/usr/bin/ntpq"

# get timecode variable, received from the clock
eval `$ntpq -c 'cv 0 timecode'`

function quit {
	case "$2" in
	0)	echo "OK: $1"
		exit 0
		;;
	1)	echo "Warning: $1"
		exit 1
		;;
	2)	echo "Critical: $1"
		exit 2
		;;
	3)	echo "Unknown: $1"
		exit 3
		;;
	esac
}

function clockstat {
	# Status nibble from hex
	hex0=0000
	hex1=0001
	hex2=0010
	hex3=0011
	hex4=0100
	hex5=0101
	hex6=0110
	hex7=0111
	hex8=1000
	hex9=1001
	hexA=1010
	hexB=1011
	hexC=1100
	hexD=1101
	hexE=1110
	hexF=1111

	eval statnibble='hex$1'
	snibble=${!statnibble}

	case ${snibble:0:2} in
	00)
		textstatus="time/date invalid"
		exitcode=2
		;;
	01)
		textstatus="crystal operation"
		exitcode=1
		;;
        10)
                textstatus="radio operation"
		exitcode=0
		;;
	11)
		textstatus="radio operation (high accuracy)"
		exitcode=0
		;;
	esac

	case ${snibble:2:1} in
	0)
		dss="standard time"
		;;
	1)
		dss="daylight saving time"
		;;
	esac

        case ${snibble:3:1} in
        0)
                ann="no announcement hour"
                ;;
        1)
                ann="announcement (ds-st-ds)"
                ;;
        esac

	quit "status hex=\"$1\", bin=\"$snibble\": $textstatus, $dss, $ann" $exitcode
}


# check for complete string, for example: \x028D194223310513\x0a\x0d\x03
# This is from the Hopf 7245 serial interface board
#
# x20 = Space
# x0D = CR (carriage return)
# x0A = LF (line feed)
# x02 = STX (start of text)
# x03 = ETX (end of text)
#
if [[ $timecode == \\x02*\\x0a\\x0d\\x03 ]];
then
	clockstat ${timecode:4:1}
else
	quit "Timecode not complete" 3	# return Unkown status
fi

Troubleshooting