update gps sync guide

This commit is contained in:
Bob 2025-12-06 10:47:23 -08:00
parent 4e712bc436
commit 623c7ddd2f
1 changed files with 145 additions and 139 deletions

View File

@ -13,13 +13,13 @@
--code-bg: #f4f4f4; --code-bg: #f4f4f4;
--border-color: #ddd; --border-color: #ddd;
} }
* { * {
margin: 0; margin: 0;
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
} }
body { body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6; line-height: 1.6;
@ -29,7 +29,7 @@
padding: 20px; padding: 20px;
background-color: #f9f9f9; background-color: #f9f9f9;
} }
header { header {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: white; color: white;
@ -38,17 +38,17 @@
margin-bottom: 30px; margin-bottom: 30px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1); box-shadow: 0 4px 6px rgba(0,0,0,0.1);
} }
h1 { h1 {
font-size: 2.5em; font-size: 2.5em;
margin-bottom: 10px; margin-bottom: 10px;
} }
.subtitle { .subtitle {
font-size: 1.2em; font-size: 1.2em;
opacity: 0.9; opacity: 0.9;
} }
h2 { h2 {
color: var(--primary-color); color: var(--primary-color);
border-bottom: 3px solid var(--secondary-color); border-bottom: 3px solid var(--secondary-color);
@ -56,19 +56,19 @@
margin: 30px 0 20px 0; margin: 30px 0 20px 0;
font-size: 1.8em; font-size: 1.8em;
} }
h3 { h3 {
color: var(--secondary-color); color: var(--secondary-color);
margin: 25px 0 15px 0; margin: 25px 0 15px 0;
font-size: 1.4em; font-size: 1.4em;
} }
h4 { h4 {
color: var(--primary-color); color: var(--primary-color);
margin: 20px 0 10px 0; margin: 20px 0 10px 0;
font-size: 1.1em; font-size: 1.1em;
} }
.section { .section {
background: white; background: white;
padding: 30px; padding: 30px;
@ -76,7 +76,7 @@
border-radius: 8px; border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05); box-shadow: 0 2px 4px rgba(0,0,0,0.05);
} }
.info-box { .info-box {
background-color: #e8f4f8; background-color: #e8f4f8;
border-left: 4px solid var(--secondary-color); border-left: 4px solid var(--secondary-color);
@ -84,7 +84,7 @@
margin: 20px 0; margin: 20px 0;
border-radius: 4px; border-radius: 4px;
} }
.warning-box { .warning-box {
background-color: #fff3cd; background-color: #fff3cd;
border-left: 4px solid #ffc107; border-left: 4px solid #ffc107;
@ -92,7 +92,7 @@
margin: 20px 0; margin: 20px 0;
border-radius: 4px; border-radius: 4px;
} }
.success-box { .success-box {
background-color: #d4edda; background-color: #d4edda;
border-left: 4px solid var(--success-color); border-left: 4px solid var(--success-color);
@ -100,36 +100,36 @@
margin: 20px 0; margin: 20px 0;
border-radius: 4px; border-radius: 4px;
} }
.wiring-table { .wiring-table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
margin: 20px 0; margin: 20px 0;
box-shadow: 0 2px 4px rgba(0,0,0,0.1); box-shadow: 0 2px 4px rgba(0,0,0,0.1);
} }
.wiring-table th, .wiring-table th,
.wiring-table td { .wiring-table td {
padding: 12px 15px; padding: 12px 15px;
text-align: left; text-align: left;
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
} }
.wiring-table th { .wiring-table th {
background-color: var(--secondary-color); background-color: var(--secondary-color);
color: white; color: white;
font-weight: 600; font-weight: 600;
} }
.wiring-table tr:nth-child(even) { .wiring-table tr:nth-child(even) {
background-color: #f8f9fa; background-color: #f8f9fa;
} }
.wiring-table td:first-child { .wiring-table td:first-child {
font-weight: 600; font-weight: 600;
color: var(--primary-color); color: var(--primary-color);
} }
pre { pre {
background-color: var(--code-bg); background-color: var(--code-bg);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@ -141,7 +141,7 @@
font-size: 0.9em; font-size: 0.9em;
line-height: 1.4; line-height: 1.4;
} }
code { code {
background-color: var(--code-bg); background-color: var(--code-bg);
padding: 2px 6px; padding: 2px 6px;
@ -149,12 +149,12 @@
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
font-size: 0.9em; font-size: 0.9em;
} }
pre code { pre code {
background-color: transparent; background-color: transparent;
padding: 0; padding: 0;
} }
.pinout-diagram { .pinout-diagram {
text-align: center; text-align: center;
margin: 30px 0; margin: 30px 0;
@ -162,19 +162,19 @@
background-color: #f8f9fa; background-color: #f8f9fa;
border-radius: 8px; border-radius: 8px;
} }
.pinout-diagram img { .pinout-diagram img {
max-width: 100%; max-width: 100%;
height: auto; height: auto;
border: 2px solid var(--border-color); border: 2px solid var(--border-color);
border-radius: 4px; border-radius: 4px;
} }
.component-list { .component-list {
list-style: none; list-style: none;
padding: 0; padding: 0;
} }
.component-list li { .component-list li {
padding: 12px 15px; padding: 12px 15px;
margin: 8px 0; margin: 8px 0;
@ -182,22 +182,22 @@
border-left: 4px solid var(--success-color); border-left: 4px solid var(--success-color);
border-radius: 4px; border-radius: 4px;
} }
.component-list li strong { .component-list li strong {
color: var(--primary-color); color: var(--primary-color);
} }
a { a {
color: var(--secondary-color); color: var(--secondary-color);
text-decoration: none; text-decoration: none;
font-weight: 500; font-weight: 500;
} }
a:hover { a:hover {
text-decoration: underline; text-decoration: underline;
color: var(--primary-color); color: var(--primary-color);
} }
.btn { .btn {
display: inline-block; display: inline-block;
padding: 10px 20px; padding: 10px 20px;
@ -208,12 +208,12 @@
margin: 5px; margin: 5px;
transition: background-color 0.3s; transition: background-color 0.3s;
} }
.btn:hover { .btn:hover {
background-color: var(--primary-color); background-color: var(--primary-color);
text-decoration: none; text-decoration: none;
} }
.ascii-diagram { .ascii-diagram {
background-color: #1e1e1e; background-color: #1e1e1e;
color: #d4d4d4; color: #d4d4d4;
@ -223,7 +223,7 @@
overflow-x: auto; overflow-x: auto;
margin: 20px 0; margin: 20px 0;
} }
footer { footer {
text-align: center; text-align: center;
margin-top: 50px; margin-top: 50px;
@ -231,7 +231,7 @@
color: #666; color: #666;
border-top: 2px solid var(--border-color); border-top: 2px solid var(--border-color);
} }
@media print { @media print {
body { body {
background-color: white; background-color: white;
@ -255,7 +255,7 @@
<div class="section"> <div class="section">
<h2>Overview</h2> <h2>Overview</h2>
<p>This guide demonstrates how to synchronize an ESP32-C5-DevKitC-1-N8R4 to GPS time using a GPS module with PPS (Pulse Per Second) output. This enables precise timestamp correlation between WiFi collapse detector events and iperf2 latency measurements running on a GPS-synced Raspberry Pi 5.</p> <p>This guide demonstrates how to synchronize an ESP32-C5-DevKitC-1-N8R4 to GPS time using a GPS module with PPS (Pulse Per Second) output. This enables precise timestamp correlation between WiFi collapse detector events and iperf2 latency measurements running on a GPS-synced Raspberry Pi 5.</p>
<div class="info-box"> <div class="info-box">
<strong>Key Features:</strong> <strong>Key Features:</strong>
<ul style="margin: 10px 0 0 20px;"> <ul style="margin: 10px 0 0 20px;">
@ -271,12 +271,22 @@
<h2>Required Hardware</h2> <h2>Required Hardware</h2>
<ul class="component-list"> <ul class="component-list">
<li><strong>ESP32-C5-DevKitC-1-N8R4</strong> - Development board with WiFi 6/6E, 4MB PSRAM, dual USB-C ports</li> <li><strong>ESP32-C5-DevKitC-1-N8R4</strong> - Development board with WiFi 6/6E, 4MB PSRAM, dual USB-C ports</li>
<li><strong>MakerFocus GT-U7 GPS Module</strong> - With PPS output and IPEX active antenna <li><strong>MakerFocus GT-U7 GPS Module</strong> - With PPS output and IPEX connector
<ul style="margin: 10px 0 0 20px;"> <ul style="margin: 10px 0 0 20px;">
<li>Operating Voltage: 3.6V - 5V (works perfectly with ESP32's 3.3V)</li> <li>Operating Voltage: 3.6V - 5V (works perfectly with ESP32's 3.3V)</li>
<li>Baud Rate: 9600</li> <li>Baud Rate: 9600</li>
<li>Compatible with NEO-6M (same NMEA format)</li> <li>Compatible with NEO-6M (same NMEA format)</li>
<li>Includes: EEPROM, USB interface, IPEX antenna</li> <li>Includes: EEPROM, USB interface</li>
</ul>
</li>
<li><strong>GPS Active Antenna - Waterproof with Magnetic Base</strong>
<ul style="margin: 10px 0 0 20px;">
<li>28dB Gain Active Antenna</li>
<li>3-5VDC powered (perfect for GT-U7)</li>
<li>SMA connector</li>
<li>Magnetic base for easy mounting</li>
<li>Waterproof for outdoor/vehicle use</li>
<li><strong>Note:</strong> GT-U7 has IPEX connector - you'll need an IPEX to SMA adapter cable (often included with antenna)</li>
</ul> </ul>
</li> </li>
<li><strong>Female-to-Female Dupont Wires</strong> - 4-5 wires minimum <li><strong>Female-to-Female Dupont Wires</strong> - 4-5 wires minimum
@ -285,7 +295,7 @@
<li><strong>USB-C Cable</strong> - For programming and power (use UART USB port on right side)</li> <li><strong>USB-C Cable</strong> - For programming and power (use UART USB port on right side)</li>
<li><strong>Raspberry Pi 5</strong> - Already GPS-synced, running iperf2</li> <li><strong>Raspberry Pi 5</strong> - Already GPS-synced, running iperf2</li>
</ul> </ul>
<div class="info-box"> <div class="info-box">
<strong>Note on USB Ports:</strong><br> <strong>Note on USB Ports:</strong><br>
The ESP32-C5 has TWO USB-C ports: The ESP32-C5 has TWO USB-C ports:
@ -295,22 +305,31 @@
</ul> </ul>
For development, use the <strong>UART USB port (right side)</strong> as it's more reliable for flashing and monitoring. For development, use the <strong>UART USB port (right side)</strong> as it's more reliable for flashing and monitoring.
</div> </div>
<div class="success-box"> <div class="success-box">
<strong>✓ GT-U7 & ESP32-C5 Compatibility:</strong><br> <strong>✓ GT-U7 & ESP32-C5 Compatibility:</strong><br>
The MakerFocus GT-U7 operates at 3.6V-5V and is fully compatible with the ESP32-C5's 3.3V power output. You can safely connect GT-U7's VCC directly to the ESP32's 3V3 pin (J1 Pin 1). The GT-U7's logic levels are also 3.3V/5V tolerant, making it a perfect match. The MakerFocus GT-U7 operates at 3.6V-5V and is fully compatible with the ESP32-C5's 3.3V power output. You can safely connect GT-U7's VCC directly to the ESP32's 3V3 pin (J1 Pin 1). The GT-U7's logic levels are also 3.3V/5V tolerant, making it a perfect match.
</div> </div>
<div class="warning-box">
<strong>⚠️ Antenna Connection:</strong><br>
The GT-U7 GPS module has an <strong>IPEX connector</strong>, while your active antenna has an <strong>SMA connector</strong>. You'll need an <strong>IPEX to SMA adapter cable</strong> (also called U.FL to SMA). These are inexpensive (~$5-10) and usually included with external GPS antennas. The adapter allows you to connect the SMA antenna to the GT-U7's IPEX port.
</div>
</div> </div>
<div class="section"> <div class="section">
<h2>Pin Connections</h2> <h2>Pin Connections</h2>
<h3>ESP32-C5 Pinout</h3> <h3>ESP32-C5 Official Pinout Diagram</h3>
<div class="info-box">
<strong>📌 Refer to this official diagram</strong> from Espressif to locate the exact pins on your board.
</div>
<div class="pinout-diagram"> <div class="pinout-diagram">
<img src="https://docs.espressif.com/projects/esp-dev-kits/en/latest/_images/esp32-c5-devkitc-1-pin-layout_v1.2.png" <img src="https://docs.espressif.com/projects/esp-dev-kits/en/latest/_images/esp32-c5-devkitc-1-pin-layout_v1.2.png"
alt="ESP32-C5 Pinout Diagram"> alt="ESP32-C5 Pinout Diagram"
<p style="margin-top: 10px; font-size: 0.9em; color: #666;"> style="width: 100%; max-width: 1000px; height: auto; border: 3px solid #34495e; border-radius: 8px; background: white; padding: 20px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
Source: <a href="https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32c5/esp32-c5-devkitc-1/user_guide.html" target="_blank">Espressif ESP32-C5 Documentation</a> <p style="margin-top: 10px; font-size: 0.9em; color: #666; text-align: center;">
<strong>Source:</strong> <a href="https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32c5/esp32-c5-devkitc-1/user_guide.html" target="_blank">Espressif ESP32-C5 Official Documentation</a>
</p> </p>
</div> </div>
@ -358,62 +377,39 @@
</tbody> </tbody>
</table> </table>
<h3>Visual Connection Guide</h3> <h3>Quick Wiring Reference</h3>
<div style="background: #2c3e50; padding: 30px; border-radius: 8px; margin: 20px 0;"> <div style="background: #2c3e50; padding: 25px; border-radius: 8px; margin: 20px 0;">
<pre style="color: #ecf0f1; font-size: 1.2em; line-height: 1.8; margin: 0; font-family: 'Courier New', monospace; font-weight: bold;"> <pre style="color: #ecf0f1; font-size: 1.3em; line-height: 2; margin: 0; font-family: 'Courier New', monospace; font-weight: bold;">
GT-U7 GPS Module ESP32-C5-DevKitC-1 Board <span style="color: #f39c12;">4 WIRES NEEDED:</span>
---------------- ═══════════════════════════════════════
<span style="color: #f39c12;"> ┌─── J1 (LEFT) ──┐ ┌── J3 (RIGHT) ──┐</span> <span style="color: #27ae60;">1. GT-U7 VCC → J1 Pin 1 (3V3) [Left side, top]</span>
<span style="color: #27ae60;">VCC (3.3V-5V) ────────→ │ Pin 1: 3V3 │ │ │</span> <span style="color: #27ae60;">2. GT-U7 GND → J1 Pin 15 (GND) [Left side, bottom]</span>
│ Pin 2: RST │ │ │ <span style="color: #27ae60;">3. GT-U7 TXD → J3 Pin 8 (GPIO4) [Right side]</span>
│ Pin 3: GPIO2 │ │ │ <span style="color: #27ae60;">4. GT-U7 PPS → J1 Pin 6 (GPIO1) [Left side]</span>
│ Pin 4: GPIO3 │ │ │
│ Pin 5: GPIO0 │ │ │
<span style="color: #27ae60;">PPS (pulse) ────────→ │ Pin 6: GPIO1 │ │ │</span>
│ Pin 7: GPIO6 │ │ │
│ Pin 8: GPIO7 │ │ │
│ Pin 9: GPIO8 │ │ │
│ Pin 10: GPIO9 │ │ │
│ Pin 11: GPIO10 │ │ │
│ Pin 12: GPIO26 │ │ │
│ Pin 13: GPIO25 │ │ │
│ Pin 14: 5V │ │ │
<span style="color: #27ae60;">GND ────────→ │ Pin 15: GND │ │ │</span>
│ Pin 16: NC │ │ │
└────────────────┘ │ │
│ Pin 1: GND │
│ Pin 2: TX │
│ Pin 3: RX │
│ Pin 4: GPIO24 │
│ Pin 5: GPIO23 │
│ Pin 6: NC │
│ Pin 7: GPIO27 │
<span style="color: #27ae60;">TXD (data out) ──────────────────────────→ │ Pin 8: GPIO4 │</span>
<span style="color: #95a5a6;">RXD (optional) ←────────────────────────────│ Pin 9: GPIO5 │</span>
│ Pin 10: NC │
│ Pin 11: GPIO28 │
│ Pin 12: GND │
│ Pin 13: GPIO14 │
│ Pin 14: GPIO13 │
│ Pin 15: GND │
│ Pin 16: NC │
└────────────────┘
<span style="color: #3498db;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GT-U7 IPEX ANTENNA:
• Connect active antenna to GT-U7's IPEX connector
• Place antenna with clear view of sky for best reception
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</span>
<span style="color: #e74c3c;">REQUIRED CONNECTIONS (4 wires):</span>
<span style="color: #27ae60;"> 1. GT-U7 VCC → J1 Pin 1 (3V3)
2. GT-U7 GND → J1 Pin 15 (GND)
3. GT-U7 TXD → J3 Pin 8 (GPIO4)
4. GT-U7 PPS → J1 Pin 6 (GPIO1)</span>
</pre> </pre>
</div> </div>
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0; border: 2px solid #34495e;">
<div style="font-weight: bold; font-size: 1.2em; margin-bottom: 15px;">📍 Pin Locations on Board:</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div style="background: white; padding: 15px; border-radius: 6px;">
<div style="font-weight: bold; color: #e74c3c; margin-bottom: 10px;">J1 (LEFT SIDE)</div>
<div style="font-family: monospace; font-size: 1.1em;">
Pin 1: 3V3 ← <span style="color: #27ae60;">VCC</span><br>
Pin 6: GPIO1 ← <span style="color: #27ae60;">PPS</span><br>
Pin 15: GND ← <span style="color: #27ae60;">GND</span>
</div>
</div>
<div style="background: white; padding: 15px; border-radius: 6px;">
<div style="font-weight: bold; color: #3498db; margin-bottom: 10px;">J3 (RIGHT SIDE)</div>
<div style="font-family: monospace; font-size: 1.1em;">
Pin 8: GPIO4 ← <span style="color: #27ae60;">TXD</span><br>
Pin 9: GPIO5 ← <span style="color: #95a5a6;">RXD (optional)</span>
</div>
</div>
</div>
</div>
<div class="warning-box"> <div class="warning-box">
<strong>⚠️ Important Notes:</strong> <strong>⚠️ Important Notes:</strong>
<ul style="margin: 10px 0 0 20px;"> <ul style="margin: 10px 0 0 20px;">
@ -496,38 +492,38 @@ static bool parse_gprmc(const char* nmea, struct tm* tm_out, bool* valid) {
if (strncmp(nmea, &quot;$GPRMC&quot;, 6) != 0 &amp;&amp; strncmp(nmea, &quot;$GNRMC&quot;, 6) != 0) { if (strncmp(nmea, &quot;$GPRMC&quot;, 6) != 0 &amp;&amp; strncmp(nmea, &quot;$GNRMC&quot;, 6) != 0) {
return false; return false;
} }
char *p = strchr(nmea, ','); char *p = strchr(nmea, ',');
if (!p) return false; if (!p) return false;
// Time field // Time field
p++; p++;
int hour, min, sec; int hour, min, sec;
if (sscanf(p, &quot;%2d%2d%2d&quot;, &amp;hour, &amp;min, &amp;sec) != 3) { if (sscanf(p, &quot;%2d%2d%2d&quot;, &amp;hour, &amp;min, &amp;sec) != 3) {
return false; return false;
} }
// Status field (A=valid, V=invalid) // Status field (A=valid, V=invalid)
p = strchr(p, ','); p = strchr(p, ',');
if (!p) return false; if (!p) return false;
p++; p++;
*valid = (*p == 'A'); *valid = (*p == 'A');
// Skip to date field (8 commas ahead from time) // Skip to date field (8 commas ahead from time)
for (int i = 0; i &lt; 7; i++) { for (int i = 0; i &lt; 7; i++) {
p = strchr(p, ','); p = strchr(p, ',');
if (!p) return false; if (!p) return false;
p++; p++;
} }
// Date field: ddmmyy // Date field: ddmmyy
int day, month, year; int day, month, year;
if (sscanf(p, &quot;%2d%2d%2d&quot;, &amp;day, &amp;month, &amp;year) != 3) { if (sscanf(p, &quot;%2d%2d%2d&quot;, &amp;day, &amp;month, &amp;year) != 3) {
return false; return false;
} }
year += (year &lt; 80) ? 2000 : 1900; year += (year &lt; 80) ? 2000 : 1900;
tm_out-&gt;tm_sec = sec; tm_out-&gt;tm_sec = sec;
tm_out-&gt;tm_min = min; tm_out-&gt;tm_min = min;
tm_out-&gt;tm_hour = hour; tm_out-&gt;tm_hour = hour;
@ -535,7 +531,7 @@ static bool parse_gprmc(const char* nmea, struct tm* tm_out, bool* valid) {
tm_out-&gt;tm_mon = month - 1; tm_out-&gt;tm_mon = month - 1;
tm_out-&gt;tm_year = year - 1900; tm_out-&gt;tm_year = year - 1900;
tm_out-&gt;tm_isdst = 0; tm_out-&gt;tm_isdst = 0;
return true; return true;
} }
@ -543,41 +539,41 @@ static bool parse_gprmc(const char* nmea, struct tm* tm_out, bool* valid) {
static void gps_task(void* arg) { static void gps_task(void* arg) {
char line[128]; char line[128];
int pos = 0; int pos = 0;
while (1) { while (1) {
uint8_t data; uint8_t data;
int len = uart_read_bytes(GPS_UART_NUM, &amp;data, 1, 100 / portTICK_PERIOD_MS); int len = uart_read_bytes(GPS_UART_NUM, &amp;data, 1, 100 / portTICK_PERIOD_MS);
if (len &gt; 0) { if (len &gt; 0) {
if (data == '\n') { if (data == '\n') {
line[pos] = '\0'; line[pos] = '\0';
struct tm gps_tm; struct tm gps_tm;
bool valid; bool valid;
if (parse_gprmc(line, &amp;gps_tm, &amp;valid)) { if (parse_gprmc(line, &amp;gps_tm, &amp;valid)) {
if (valid) { if (valid) {
time_t gps_time = mktime(&amp;gps_tm); time_t gps_time = mktime(&amp;gps_tm);
xSemaphoreTake(sync_mutex, portMAX_DELAY); xSemaphoreTake(sync_mutex, portMAX_DELAY);
next_pps_gps_second = gps_time + 1; next_pps_gps_second = gps_time + 1;
xSemaphoreGive(sync_mutex); xSemaphoreGive(sync_mutex);
vTaskDelay(pdMS_TO_TICKS(300)); vTaskDelay(pdMS_TO_TICKS(300));
xSemaphoreTake(sync_mutex, portMAX_DELAY); xSemaphoreTake(sync_mutex, portMAX_DELAY);
if (last_pps_monotonic &gt; 0) { if (last_pps_monotonic &gt; 0) {
int64_t gps_us = (int64_t)next_pps_gps_second * 1000000LL; int64_t gps_us = (int64_t)next_pps_gps_second * 1000000LL;
int64_t new_offset = gps_us - last_pps_monotonic; int64_t new_offset = gps_us - last_pps_monotonic;
if (monotonic_offset_us == 0) { if (monotonic_offset_us == 0) {
monotonic_offset_us = new_offset; monotonic_offset_us = new_offset;
} else { } else {
// Low-pass filter: 90% old + 10% new // Low-pass filter: 90% old + 10% new
monotonic_offset_us = (monotonic_offset_us * 9 + new_offset) / 10; monotonic_offset_us = (monotonic_offset_us * 9 + new_offset) / 10;
} }
gps_has_fix = true; gps_has_fix = true;
ESP_LOGI(TAG, &quot;GPS sync: %04d-%02d-%02d %02d:%02d:%02d, offset=%lld us&quot;, ESP_LOGI(TAG, &quot;GPS sync: %04d-%02d-%02d %02d:%02d:%02d, offset=%lld us&quot;,
gps_tm.tm_year + 1900, gps_tm.tm_mon + 1, gps_tm.tm_mday, gps_tm.tm_year + 1900, gps_tm.tm_mon + 1, gps_tm.tm_mday,
gps_tm.tm_hour, gps_tm.tm_min, gps_tm.tm_sec, gps_tm.tm_hour, gps_tm.tm_min, gps_tm.tm_sec,
@ -588,7 +584,7 @@ static void gps_task(void* arg) {
gps_has_fix = false; gps_has_fix = false;
} }
} }
pos = 0; pos = 0;
} else if (pos &lt; sizeof(line) - 1) { } else if (pos &lt; sizeof(line) - 1) {
line[pos++] = data; line[pos++] = data;
@ -599,9 +595,9 @@ static void gps_task(void* arg) {
void gps_sync_init(void) { void gps_sync_init(void) {
ESP_LOGI(TAG, &quot;Initializing GPS sync&quot;); ESP_LOGI(TAG, &quot;Initializing GPS sync&quot;);
sync_mutex = xSemaphoreCreateMutex(); sync_mutex = xSemaphoreCreateMutex();
uart_config_t uart_config = { uart_config_t uart_config = {
.baud_rate = GPS_BAUD_RATE, .baud_rate = GPS_BAUD_RATE,
.data_bits = UART_DATA_8_BITS, .data_bits = UART_DATA_8_BITS,
@ -610,12 +606,12 @@ void gps_sync_init(void) {
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT, .source_clk = UART_SCLK_DEFAULT,
}; };
ESP_ERROR_CHECK(uart_driver_install(GPS_UART_NUM, UART_BUF_SIZE, 0, 0, NULL, 0)); ESP_ERROR_CHECK(uart_driver_install(GPS_UART_NUM, UART_BUF_SIZE, 0, 0, NULL, 0));
ESP_ERROR_CHECK(uart_param_config(GPS_UART_NUM, &amp;uart_config)); ESP_ERROR_CHECK(uart_param_config(GPS_UART_NUM, &amp;uart_config));
ESP_ERROR_CHECK(uart_set_pin(GPS_UART_NUM, GPS_TX_PIN, GPS_RX_PIN, ESP_ERROR_CHECK(uart_set_pin(GPS_UART_NUM, GPS_TX_PIN, GPS_RX_PIN,
UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
gpio_config_t io_conf = { gpio_config_t io_conf = {
.intr_type = GPIO_INTR_POSEDGE, .intr_type = GPIO_INTR_POSEDGE,
.mode = GPIO_MODE_INPUT, .mode = GPIO_MODE_INPUT,
@ -624,24 +620,24 @@ void gps_sync_init(void) {
.pull_down_en = GPIO_PULLDOWN_DISABLE, .pull_down_en = GPIO_PULLDOWN_DISABLE,
}; };
ESP_ERROR_CHECK(gpio_config(&amp;io_conf)); ESP_ERROR_CHECK(gpio_config(&amp;io_conf));
ESP_ERROR_CHECK(gpio_install_isr_service(0)); ESP_ERROR_CHECK(gpio_install_isr_service(0));
ESP_ERROR_CHECK(gpio_isr_handler_add(PPS_GPIO, pps_isr_handler, NULL)); ESP_ERROR_CHECK(gpio_isr_handler_add(PPS_GPIO, pps_isr_handler, NULL));
xTaskCreate(gps_task, &quot;gps_task&quot;, 4096, NULL, 5, NULL); xTaskCreate(gps_task, &quot;gps_task&quot;, 4096, NULL, 5, NULL);
ESP_LOGI(TAG, &quot;GPS sync initialized (RX=GPIO%d, PPS=GPIO%d)&quot;, GPS_RX_PIN, PPS_GPIO); ESP_LOGI(TAG, &quot;GPS sync initialized (RX=GPIO%d, PPS=GPIO%d)&quot;, GPS_RX_PIN, PPS_GPIO);
} }
gps_timestamp_t gps_get_timestamp(void) { gps_timestamp_t gps_get_timestamp(void) {
gps_timestamp_t ts; gps_timestamp_t ts;
xSemaphoreTake(sync_mutex, portMAX_DELAY); xSemaphoreTake(sync_mutex, portMAX_DELAY);
ts.monotonic_us = esp_timer_get_time(); ts.monotonic_us = esp_timer_get_time();
ts.gps_us = ts.monotonic_us + monotonic_offset_us; ts.gps_us = ts.monotonic_us + monotonic_offset_us;
ts.synced = gps_has_fix; ts.synced = gps_has_fix;
xSemaphoreGive(sync_mutex); xSemaphoreGive(sync_mutex);
return ts; return ts;
} }
@ -660,7 +656,7 @@ static const char *TAG = &quot;MAIN&quot;;
void log_collapse_event(float nav_duration_us, int rssi) { void log_collapse_event(float nav_duration_us, int rssi) {
gps_timestamp_t ts = gps_get_timestamp(); gps_timestamp_t ts = gps_get_timestamp();
// CSV format: monotonic_us, gps_us, synced, nav_duration, rssi // CSV format: monotonic_us, gps_us, synced, nav_duration, rssi
printf(&quot;COLLAPSE,%lld,%lld,%d,%.2f,%d\n&quot;, printf(&quot;COLLAPSE,%lld,%lld,%d,%.2f,%d\n&quot;,
ts.monotonic_us, ts.monotonic_us,
@ -672,26 +668,26 @@ void log_collapse_event(float nav_duration_us, int rssi) {
void app_main(void) { void app_main(void) {
ESP_LOGI(TAG, &quot;Starting GPS sync&quot;); ESP_LOGI(TAG, &quot;Starting GPS sync&quot;);
gps_sync_init(); gps_sync_init();
ESP_LOGI(TAG, &quot;Waiting for GPS fix...&quot;); ESP_LOGI(TAG, &quot;Waiting for GPS fix...&quot;);
while (!gps_is_synced()) { while (!gps_is_synced()) {
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
} }
ESP_LOGI(TAG, &quot;GPS synced!&quot;); ESP_LOGI(TAG, &quot;GPS synced!&quot;);
while (1) { while (1) {
gps_timestamp_t ts = gps_get_timestamp(); gps_timestamp_t ts = gps_get_timestamp();
ESP_LOGI(TAG, &quot;Time: mono=%lld gps=%lld synced=%d&quot;, ESP_LOGI(TAG, &quot;Time: mono=%lld gps=%lld synced=%d&quot;,
ts.monotonic_us, ts.gps_us, ts.synced); ts.monotonic_us, ts.gps_us, ts.synced);
// Example: log collapse event // Example: log collapse event
if (ts.monotonic_us % 10000000 &lt; 100000) { if (ts.monotonic_us % 10000000 &lt; 100000) {
log_collapse_event(1234.5, -65); log_collapse_event(1234.5, -65);
} }
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
} }
}</code></pre> }</code></pre>
@ -750,17 +746,17 @@ iperf -c target_ip --histograms --trip-times -i 0.1</code></pre>
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
# Load ESP32 collapse events # Load ESP32 collapse events
esp32_events = pd.read_csv('collapse_events.csv', esp32_events = pd.read_csv('collapse_events.csv',
names=['event', 'mono_us', 'gps_us', 'synced', 'nav_dur', 'rssi'], names=['event', 'mono_us', 'gps_us', 'synced', 'nav_dur', 'rssi'],
parse_dates=['gps_us'], parse_dates=['gps_us'],
date_parser=lambda x: pd.to_datetime(int(x), unit='us')) date_parser=lambda x: pd.to_datetime(int(x), unit='us'))
# Load iperf2 data # Load iperf2 data
iperf_data = pd.read_csv('iperf_histograms.csv', iperf_data = pd.read_csv('iperf_histograms.csv',
parse_dates=['timestamp']) parse_dates=['timestamp'])
# Merge on GPS timestamp (within 100ms window) # Merge on GPS timestamp (within 100ms window)
merged = pd.merge_asof(iperf_data.sort_values('timestamp'), merged = pd.merge_asof(iperf_data.sort_values('timestamp'),
esp32_events.sort_values('gps_us'), esp32_events.sort_values('gps_us'),
left_on='timestamp', left_on='timestamp',
right_on='gps_us', right_on='gps_us',
@ -795,12 +791,12 @@ PORT_BASE=/dev/ttyUSB
for i in {0..31}; do for i in {0..31}; do
DEVICE=${PORT_BASE}${i} DEVICE=${PORT_BASE}${i}
IP=$((START_IP + i)) IP=$((START_IP + i))
echo &quot;Flashing device $i at $DEVICE with IP 192.168.1.$IP&quot; echo &quot;Flashing device $i at $DEVICE with IP 192.168.1.$IP&quot;
# Set device-specific config # Set device-specific config
idf.py -p $DEVICE -D DEVICE_ID=$i -D STATIC_IP=192.168.1.$IP flash idf.py -p $DEVICE -D DEVICE_ID=$i -D STATIC_IP=192.168.1.$IP flash
sleep 2 sleep 2
done done
@ -809,7 +805,15 @@ echo &quot;All devices flashed!&quot;</code></pre>
<h3>Physical Setup Recommendations</h3> <h3>Physical Setup Recommendations</h3>
<ul style="margin: 15px 0 0 20px;"> <ul style="margin: 15px 0 0 20px;">
<li>Use short (10cm) dupont wires to minimize antenna interference</li> <li>Use short (10cm) dupont wires to minimize antenna interference</li>
<li>Mount GPS modules on top of enclosure for best sky view</li> <li><strong>External Active Antenna:</strong> Mount waterproof SMA antenna with magnetic base on roof or high point for optimal GPS reception</li>
<li><strong>IPEX to SMA Adapter:</strong> Each GT-U7 needs an adapter cable (~3-6 inches) to connect to external antenna</li>
<li><strong>Antenna Placement:</strong> For 32+ device deployment, consider:
<ul style="margin-top: 5px;">
<li>Single roof-mounted antenna with GPS signal splitter (1-to-N)</li>
<li>OR individual antennas for each device (better accuracy but more expensive)</li>
<li>Keep antenna cables as short as possible (signal loss increases with length)</li>
</ul>
</li>
<li>Keep ESP32 antennas clear of metal/GPS modules</li> <li>Keep ESP32 antennas clear of metal/GPS modules</li>
<li>Consider 3D printed stackable enclosures for clean deployment</li> <li>Consider 3D printed stackable enclosures for clean deployment</li>
<li>Label each device with its static IP for tracking</li> <li>Label each device with its static IP for tracking</li>
@ -821,10 +825,12 @@ echo &quot;All devices flashed!&quot;</code></pre>
<h3>No GPS Fix</h3> <h3>No GPS Fix</h3>
<ul style="margin: 15px 0 0 20px;"> <ul style="margin: 15px 0 0 20px;">
<li><strong>GT-U7 Antenna:</strong> Ensure IPEX active antenna is properly connected to the module</li> <li><strong>External Active Antenna:</strong> Connect waterproof active antenna (SMA) to GT-U7 IPEX port using IPEX-to-SMA adapter</li>
<li><strong>Antenna Placement:</strong> Mount antenna outdoors or on window with magnetic base for best sky view</li>
<li>Ensure GPS module has clear view of sky (outdoors or near window)</li> <li>Ensure GPS module has clear view of sky (outdoors or near window)</li>
<li>Cold start can take 30-60 seconds, hot start &lt;1 second</li> <li>Cold start can take 30-60 seconds, hot start &lt;1 second</li>
<li>GT-U7 has excellent sensitivity - works in challenging environments</li> <li>GT-U7 has excellent sensitivity - works in challenging environments</li>
<li><strong>Active antenna power:</strong> GT-U7 provides 3.3V to power the active antenna (28dB gain)</li>
<li>Check UART connections (TXD→GPIO4, RXD←GPIO5)</li> <li>Check UART connections (TXD→GPIO4, RXD←GPIO5)</li>
<li>Verify 3.3V power (measure with multimeter - should be 3.2-3.4V)</li> <li>Verify 3.3V power (measure with multimeter - should be 3.2-3.4V)</li>
<li>GT-U7 LED should blink when acquiring satellites</li> <li>GT-U7 LED should blink when acquiring satellites</li>