diff --git a/doc/esp32-c5-gps-sync-guide.html b/doc/esp32-c5-gps-sync-guide.html index 7684e5e..bccd2f4 100644 --- a/doc/esp32-c5-gps-sync-guide.html +++ b/doc/esp32-c5-gps-sync-guide.html @@ -13,13 +13,13 @@ --code-bg: #f4f4f4; --border-color: #ddd; } - + * { margin: 0; padding: 0; box-sizing: border-box; } - + body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; line-height: 1.6; @@ -29,7 +29,7 @@ padding: 20px; background-color: #f9f9f9; } - + header { background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); color: white; @@ -38,17 +38,17 @@ margin-bottom: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } - + h1 { font-size: 2.5em; margin-bottom: 10px; } - + .subtitle { font-size: 1.2em; opacity: 0.9; } - + h2 { color: var(--primary-color); border-bottom: 3px solid var(--secondary-color); @@ -56,19 +56,19 @@ margin: 30px 0 20px 0; font-size: 1.8em; } - + h3 { color: var(--secondary-color); margin: 25px 0 15px 0; font-size: 1.4em; } - + h4 { color: var(--primary-color); margin: 20px 0 10px 0; font-size: 1.1em; } - + .section { background: white; padding: 30px; @@ -76,7 +76,7 @@ border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); } - + .info-box { background-color: #e8f4f8; border-left: 4px solid var(--secondary-color); @@ -84,7 +84,7 @@ margin: 20px 0; border-radius: 4px; } - + .warning-box { background-color: #fff3cd; border-left: 4px solid #ffc107; @@ -92,7 +92,7 @@ margin: 20px 0; border-radius: 4px; } - + .success-box { background-color: #d4edda; border-left: 4px solid var(--success-color); @@ -100,36 +100,36 @@ margin: 20px 0; border-radius: 4px; } - + .wiring-table { width: 100%; border-collapse: collapse; margin: 20px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } - + .wiring-table th, .wiring-table td { padding: 12px 15px; text-align: left; border: 1px solid var(--border-color); } - + .wiring-table th { background-color: var(--secondary-color); color: white; font-weight: 600; } - + .wiring-table tr:nth-child(even) { background-color: #f8f9fa; } - + .wiring-table td:first-child { font-weight: 600; color: var(--primary-color); } - + pre { background-color: var(--code-bg); border: 1px solid var(--border-color); @@ -141,7 +141,7 @@ font-size: 0.9em; line-height: 1.4; } - + code { background-color: var(--code-bg); padding: 2px 6px; @@ -149,12 +149,12 @@ font-family: 'Courier New', Courier, monospace; font-size: 0.9em; } - + pre code { background-color: transparent; padding: 0; } - + .pinout-diagram { text-align: center; margin: 30px 0; @@ -162,19 +162,19 @@ background-color: #f8f9fa; border-radius: 8px; } - + .pinout-diagram img { max-width: 100%; height: auto; border: 2px solid var(--border-color); border-radius: 4px; } - + .component-list { list-style: none; padding: 0; } - + .component-list li { padding: 12px 15px; margin: 8px 0; @@ -182,22 +182,22 @@ border-left: 4px solid var(--success-color); border-radius: 4px; } - + .component-list li strong { color: var(--primary-color); } - + a { color: var(--secondary-color); text-decoration: none; font-weight: 500; } - + a:hover { text-decoration: underline; color: var(--primary-color); } - + .btn { display: inline-block; padding: 10px 20px; @@ -208,12 +208,12 @@ margin: 5px; transition: background-color 0.3s; } - + .btn:hover { background-color: var(--primary-color); text-decoration: none; } - + .ascii-diagram { background-color: #1e1e1e; color: #d4d4d4; @@ -223,7 +223,7 @@ overflow-x: auto; margin: 20px 0; } - + footer { text-align: center; margin-top: 50px; @@ -231,7 +231,7 @@ color: #666; border-top: 2px solid var(--border-color); } - + @media print { body { background-color: white; @@ -255,7 +255,7 @@
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.
- +
-
- Source: Espressif ESP32-C5 Documentation
+
+
-GT-U7 GPS Module ESP32-C5-DevKitC-1 Board ----------------- βββββββββββββββββββββββββββββββββββββββ +Quick Wiring Reference
++++4 WIRES NEEDED: - ββββ J1 (LEFT) βββ βββ J3 (RIGHT) βββ -VCC (3.3V-5V) βββββββββ β Pin 1: 3V3 β β β - β Pin 2: RST β β β - β Pin 3: GPIO2 β β β - β Pin 4: GPIO3 β β β - β Pin 5: GPIO0 β β β -PPS (pulse) βββββββββ β Pin 6: GPIO1 β β β - β Pin 7: GPIO6 β β β - β Pin 8: GPIO7 β β β - β Pin 9: GPIO8 β β β - β Pin 10: GPIO9 β β β - β Pin 11: GPIO10 β β β - β Pin 12: GPIO26 β β β - β Pin 13: GPIO25 β β β - β Pin 14: 5V β β β -GND βββββββββ β Pin 15: GND β β β - β Pin 16: NC β β β - ββββββββββββββββββ β β - β Pin 1: GND β - β Pin 2: TX β - β Pin 3: RX β - β Pin 4: GPIO24 β - β Pin 5: GPIO23 β - β Pin 6: NC β - β Pin 7: GPIO27 β -TXD (data out) βββββββββββββββββββββββββββ β Pin 8: GPIO4 β -RXD (optional) ββββββββββββββββββββββββββββββ Pin 9: GPIO5 β - β Pin 10: NC β - β Pin 11: GPIO28 β - β Pin 12: GND β - β Pin 13: GPIO14 β - β Pin 14: GPIO13 β - β Pin 15: GND β - β Pin 16: NC β - ββββββββββββββββββ - -βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -GT-U7 IPEX ANTENNA: -β’ Connect active antenna to GT-U7's IPEX connector -β’ Place antenna with clear view of sky for best reception -βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ - -REQUIRED CONNECTIONS (4 wires): - 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) +1. GT-U7 VCC β J1 Pin 1 (3V3) [Left side, top] +2. GT-U7 GND β J1 Pin 15 (GND) [Left side, bottom] +3. GT-U7 TXD β J3 Pin 8 (GPIO4) [Right side] +4. GT-U7 PPS β J1 Pin 6 (GPIO1) [Left side]++π Pin Locations on Board:+++++J1 (LEFT SIDE)++ Pin 1: 3V3 β VCC+
+ Pin 6: GPIO1 β PPS
+ Pin 15: GND β GND +++J3 (RIGHT SIDE)++ Pin 8: GPIO4 β TXD+
+ Pin 9: GPIO5 β RXD (optional) +β οΈ Important Notes:@@ -496,38 +492,38 @@ static bool parse_gprmc(const char* nmea, struct tm* tm_out, bool* valid) { if (strncmp(nmea, "$GPRMC", 6) != 0 && strncmp(nmea, "$GNRMC", 6) != 0) { return false; } - + char *p = strchr(nmea, ','); if (!p) return false; - + // Time field p++; int hour, min, sec; if (sscanf(p, "%2d%2d%2d", &hour, &min, &sec) != 3) { return false; } - + // Status field (A=valid, V=invalid) p = strchr(p, ','); if (!p) return false; p++; *valid = (*p == 'A'); - + // Skip to date field (8 commas ahead from time) for (int i = 0; i < 7; i++) { p = strchr(p, ','); if (!p) return false; p++; } - + // Date field: ddmmyy int day, month, year; if (sscanf(p, "%2d%2d%2d", &day, &month, &year) != 3) { return false; } - + year += (year < 80) ? 2000 : 1900; - + tm_out->tm_sec = sec; tm_out->tm_min = min; tm_out->tm_hour = hour; @@ -535,7 +531,7 @@ static bool parse_gprmc(const char* nmea, struct tm* tm_out, bool* valid) { tm_out->tm_mon = month - 1; tm_out->tm_year = year - 1900; tm_out->tm_isdst = 0; - + 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) { char line[128]; int pos = 0; - + while (1) { uint8_t data; int len = uart_read_bytes(GPS_UART_NUM, &data, 1, 100 / portTICK_PERIOD_MS); - + if (len > 0) { if (data == '\n') { line[pos] = '\0'; - + struct tm gps_tm; bool valid; if (parse_gprmc(line, &gps_tm, &valid)) { if (valid) { time_t gps_time = mktime(&gps_tm); - + xSemaphoreTake(sync_mutex, portMAX_DELAY); next_pps_gps_second = gps_time + 1; xSemaphoreGive(sync_mutex); - + vTaskDelay(pdMS_TO_TICKS(300)); - + xSemaphoreTake(sync_mutex, portMAX_DELAY); if (last_pps_monotonic > 0) { int64_t gps_us = (int64_t)next_pps_gps_second * 1000000LL; int64_t new_offset = gps_us - last_pps_monotonic; - + if (monotonic_offset_us == 0) { monotonic_offset_us = new_offset; } else { // Low-pass filter: 90% old + 10% new monotonic_offset_us = (monotonic_offset_us * 9 + new_offset) / 10; } - + gps_has_fix = true; - + ESP_LOGI(TAG, "GPS sync: %04d-%02d-%02d %02d:%02d:%02d, offset=%lld us", 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, @@ -588,7 +584,7 @@ static void gps_task(void* arg) { gps_has_fix = false; } } - + pos = 0; } else if (pos < sizeof(line) - 1) { line[pos++] = data; @@ -599,9 +595,9 @@ static void gps_task(void* arg) { void gps_sync_init(void) { ESP_LOGI(TAG, "Initializing GPS sync"); - + sync_mutex = xSemaphoreCreateMutex(); - + uart_config_t uart_config = { .baud_rate = GPS_BAUD_RATE, .data_bits = UART_DATA_8_BITS, @@ -610,12 +606,12 @@ void gps_sync_init(void) { .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .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_param_config(GPS_UART_NUM, &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)); - + gpio_config_t io_conf = { .intr_type = GPIO_INTR_POSEDGE, .mode = GPIO_MODE_INPUT, @@ -624,24 +620,24 @@ void gps_sync_init(void) { .pull_down_en = GPIO_PULLDOWN_DISABLE, }; ESP_ERROR_CHECK(gpio_config(&io_conf)); - + ESP_ERROR_CHECK(gpio_install_isr_service(0)); ESP_ERROR_CHECK(gpio_isr_handler_add(PPS_GPIO, pps_isr_handler, NULL)); - + xTaskCreate(gps_task, "gps_task", 4096, NULL, 5, NULL); - + ESP_LOGI(TAG, "GPS sync initialized (RX=GPIO%d, PPS=GPIO%d)", GPS_RX_PIN, PPS_GPIO); } gps_timestamp_t gps_get_timestamp(void) { gps_timestamp_t ts; - + xSemaphoreTake(sync_mutex, portMAX_DELAY); ts.monotonic_us = esp_timer_get_time(); ts.gps_us = ts.monotonic_us + monotonic_offset_us; ts.synced = gps_has_fix; xSemaphoreGive(sync_mutex); - + return ts; } @@ -660,7 +656,7 @@ static const char *TAG = "MAIN"; void log_collapse_event(float nav_duration_us, int rssi) { gps_timestamp_t ts = gps_get_timestamp(); - + // CSV format: monotonic_us, gps_us, synced, nav_duration, rssi printf("COLLAPSE,%lld,%lld,%d,%.2f,%d\n", ts.monotonic_us, @@ -672,26 +668,26 @@ void log_collapse_event(float nav_duration_us, int rssi) { void app_main(void) { ESP_LOGI(TAG, "Starting GPS sync"); - + gps_sync_init(); - + ESP_LOGI(TAG, "Waiting for GPS fix..."); while (!gps_is_synced()) { vTaskDelay(pdMS_TO_TICKS(1000)); } ESP_LOGI(TAG, "GPS synced!"); - + while (1) { gps_timestamp_t ts = gps_get_timestamp(); - + ESP_LOGI(TAG, "Time: mono=%lld gps=%lld synced=%d", ts.monotonic_us, ts.gps_us, ts.synced); - + // Example: log collapse event if (ts.monotonic_us % 10000000 < 100000) { log_collapse_event(1234.5, -65); } - + vTaskDelay(pdMS_TO_TICKS(1000)); } } @@ -750,17 +746,17 @@ iperf -c target_ip --histograms --trip-times -i 0.1 import matplotlib.pyplot as plt # 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'], - parse_dates=['gps_us'], + parse_dates=['gps_us'], date_parser=lambda x: pd.to_datetime(int(x), unit='us')) # Load iperf2 data -iperf_data = pd.read_csv('iperf_histograms.csv', +iperf_data = pd.read_csv('iperf_histograms.csv', parse_dates=['timestamp']) # 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'), left_on='timestamp', right_on='gps_us', @@ -795,12 +791,12 @@ PORT_BASE=/dev/ttyUSB for i in {0..31}; do DEVICE=${PORT_BASE}${i} IP=$((START_IP + i)) - + echo "Flashing device $i at $DEVICE with IP 192.168.1.$IP" - + # Set device-specific config idf.py -p $DEVICE -D DEVICE_ID=$i -D STATIC_IP=192.168.1.$IP flash - + sleep 2 done @@ -809,7 +805,15 @@ echo "All devices flashed!"
Physical Setup Recommendations
- Use short (10cm) dupont wires to minimize antenna interference
-- Mount GPS modules on top of enclosure for best sky view
+- External Active Antenna: Mount waterproof SMA antenna with magnetic base on roof or high point for optimal GPS reception
+- IPEX to SMA Adapter: Each GT-U7 needs an adapter cable (~3-6 inches) to connect to external antenna
+- Antenna Placement: For 32+ device deployment, consider: +
+
+- Single roof-mounted antenna with GPS signal splitter (1-to-N)
+- OR individual antennas for each device (better accuracy but more expensive)
+- Keep antenna cables as short as possible (signal loss increases with length)
+- Keep ESP32 antennas clear of metal/GPS modules
- Consider 3D printed stackable enclosures for clean deployment
- Label each device with its static IP for tracking
@@ -821,10 +825,12 @@ echo "All devices flashed!"No GPS Fix
-
- GT-U7 Antenna: Ensure IPEX active antenna is properly connected to the module
+- External Active Antenna: Connect waterproof active antenna (SMA) to GT-U7 IPEX port using IPEX-to-SMA adapter
+- Antenna Placement: Mount antenna outdoors or on window with magnetic base for best sky view
- Ensure GPS module has clear view of sky (outdoors or near window)
- Cold start can take 30-60 seconds, hot start <1 second
- GT-U7 has excellent sensitivity - works in challenging environments
+- Active antenna power: GT-U7 provides 3.3V to power the active antenna (28dB gain)
- Check UART connections (TXDβGPIO4, RXDβGPIO5)
- Verify 3.3V power (measure with multimeter - should be 3.2-3.4V)
- GT-U7 LED should blink when acquiring satellites