-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgps-test.sh
More file actions
executable file
·202 lines (180 loc) · 6.08 KB
/
Copy pathgps-test.sh
File metadata and controls
executable file
·202 lines (180 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# GPS Diagnostic Script
# This script helps diagnose GPS connection and synchronization issues
echo "RPI-Clock GPS Diagnostic Script"
echo "==============================="
echo ""
# Check if running as root
if [[ $EUID -eq 0 ]]; then
echo "This script should not be run as root. Please run as a regular user."
echo "The script will prompt for sudo when needed."
exit 1
fi
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
echo "Step 1: Checking GPS daemon service..."
echo "--------------------------------------"
if systemctl is-active --quiet gpsd.service; then
echo "✓ gpsd.service is running"
else
echo "✗ gpsd.service is NOT running"
echo " Run: sudo systemctl start gpsd.service"
fi
if systemctl is-enabled --quiet gpsd.service; then
echo "✓ gpsd.service is enabled"
else
echo "✗ gpsd.service is NOT enabled"
echo " Run: sudo systemctl enable gpsd.service"
fi
echo ""
echo "Step 2: Checking GPS hardware connection..."
echo "------------------------------------------"
if [[ -c /dev/ttyAMA0 ]]; then
echo "✓ GPS HAT device /dev/ttyAMA0 exists (primary GPS interface)"
else
echo "✗ GPS HAT device /dev/ttyAMA0 NOT found"
echo " Check GPS HAT connection and UART configuration"
echo " Run: sudo raspi-config nonint do_serial 1"
echo " Ensure UART is enabled: enable_uart=1 in /boot/firmware/config.txt"
echo " Disable Bluetooth: dtoverlay=disable-bt in /boot/firmware/config.txt"
fi
if [[ -c /dev/serial0 ]]; then
echo "✓ Serial device /dev/serial0 exists (fallback interface)"
else
echo "✗ Serial device /dev/serial0 NOT found"
fi
if [[ -c /dev/pps0 ]]; then
echo "✓ PPS device /dev/pps0 exists (precision timing)"
else
echo "✗ PPS device /dev/pps0 NOT found"
echo " PPS provides microsecond precision timing"
fi
echo ""
echo "Step 3: Checking GPS daemon socket..."
echo "------------------------------------"
if [[ -S /var/run/gpsd.sock ]]; then
echo "✓ GPS daemon socket exists"
else
echo "✗ GPS daemon socket NOT found"
echo " GPS daemon may not be running properly"
fi
echo ""
echo "Step 4: Testing GPS client tools..."
echo "----------------------------------"
if command_exists cgps; then
echo "✓ cgps is available"
else
echo "✗ cgps is NOT available"
echo " Run: sudo apt install gpsd-clients"
fi
if command_exists gpsmon; then
echo "✓ gpsmon is available"
else
echo "✗ gpsmon is NOT available"
echo " Run: sudo apt install gpsd-clients"
fi
echo ""
echo "Step 5: Testing GPS data reception..."
echo "------------------------------------"
if command_exists cgps; then
echo "Testing GPS data reception (timeout: 10 seconds)..."
timeout 10 cgps -s 2>/dev/null | head -20
if [[ ${PIPESTATUS[0]} -eq 124 ]]; then
echo "✗ GPS data reception timeout"
echo " Possible causes:"
echo " - GPS antenna not connected or damaged"
echo " - No clear view of sky"
echo " - GPS HAT not properly connected"
echo " - Cold start (wait 5-15 minutes)"
else
echo "✓ GPS data reception successful"
fi
else
echo "Cannot test GPS data - cgps not available"
fi
echo ""
echo "Step 6: Checking GPS fix status..."
echo "---------------------------------"
if command_exists gpsmon; then
echo "Checking GPS fix status (timeout: 5 seconds)..."
timeout 5 gpsmon 2>/dev/null | grep -E "(Fix|Status|Satellites)" | head -10
if [[ ${PIPESTATUS[0]} -eq 124 ]]; then
echo "✗ GPS fix check timeout"
else
echo "✓ GPS fix check completed"
fi
else
echo "Cannot check GPS fix - gpsmon not available"
fi
echo ""
echo "Step 7: Testing GPS time synchronization..."
echo "------------------------------------------"
if command_exists gpspipe; then
echo "Testing GPS time data (timeout: 5 seconds)..."
timeout 5 gpspipe -r 2>/dev/null | grep -E "TPV|TIME" | head -5
if [[ ${PIPESTATUS[0]} -eq 124 ]]; then
echo "✗ GPS time data timeout"
else
echo "✓ GPS time data received"
fi
else
echo "Cannot test GPS time - gpspipe not available"
fi
echo ""
echo "Step 8: Checking GPSD configuration..."
echo "------------------------------------"
if [[ -f /etc/default/gpsd ]]; then
echo "GPSD configuration:"
cat /etc/default/gpsd | grep -E "(DEVICES|GPSD_OPTIONS|USBAUTO)" || echo "No GPSD configuration found"
else
echo "✗ GPSD configuration file not found"
fi
echo ""
echo "Step 9: Checking chrony GPS integration..."
echo "------------------------------------------"
if command_exists chronyc; then
echo "Checking chrony sources..."
sudo chronyc sources | grep -E "(GPS|SHM)" || echo "No GPS sources found in chrony"
echo ""
echo "Checking chrony tracking..."
sudo chronyc tracking | head -5
echo ""
echo "Checking GPSD shared memory segments..."
if command_exists ntpshmmon; then
echo "GPSD SHM data (first 3 samples):"
sudo ntpshmmon | head -4
else
echo "✗ ntpshmmon not available"
echo " Run: sudo apt install gpsd-clients"
fi
else
echo "✗ chronyc not available"
echo " Run: sudo apt install chrony"
fi
echo ""
echo "Step 10: Checking system time synchronization..."
echo "----------------------------------------------"
echo "System time: $(date)"
echo "UTC time: $(date -u)"
echo "Timezone: $(timedatectl show --property=Timezone --value 2>/dev/null || echo 'Unknown')"
if command_exists timedatectl; then
echo ""
echo "Time synchronization status:"
timedatectl status | grep -E "(NTP|synchronized|time)"
fi
echo ""
echo "Diagnostic complete!"
echo "==================="
echo ""
echo "Troubleshooting tips:"
echo "1. Ensure GPS antenna has clear view of sky"
echo "2. Wait 5-15 minutes for cold start GPS fix"
echo "3. Check all GPS HAT connections"
echo "4. Verify GPS antenna is not damaged"
echo "5. Test with external GPS antenna if available"
echo "6. Check chrony configuration: sudo nano /etc/chrony/chrony.conf"
echo "7. Restart services: sudo systemctl restart gpsd chrony"
echo ""
echo "For more help, see TROUBLESHOOTING.md"