Update on my gps issues, gps module would revert to old settings after some time for some reaseon. After a loads of mostly hopeless AI troubleshooting (chatgpt) Google gemini delivered a working solution. No sure why, seems like the same code in general, but will change baud rate (confirmed with oscilloscope) reliably. Hope this helps somebody .
void configureGPS() {
// UBX-CFG-PRT packet for 115200 baud (UART1, 8N1, UBX+NMEA)
// Checksum is pre-calculated here for reliability
byte setBaud[] = {
0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00,
0xD0, 0x08, 0x00, 0x00, 0x00, 0xC2, 0x01, 0x00, 0x07, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7E
};
// UBX-CFG-RATE for 5Hz (200ms)
byte setRate[] = {
0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xC8, 0x00, 0x01, 0x00,
0x01, 0x00, 0xDE, 0x6A
};
setUartMux(1);
// 1. Initial connection at default GPS speed
Serial.println("GPS: Connecting at 9600...");
Serial1.begin(9600, SERIAL_8N1, P_U1_RX, P_U1_TX);
delay(200);
// 2. Send Baud Change Command
Serial1.write(setBaud, sizeof(setBaud));
// CRITICAL: flush() only clears the buffer, hardware needs time to send
Serial1.flush();
delay(50); // Give the UART hardware ~50ms to finish sending the packet
// 3. Switch ESP32 to the new speed
Serial1.end();
delay(100);
Serial1.begin(115200, SERIAL_8N1, P_U1_RX, P_U1_TX);
Serial.println("GPS: Baud switched to 115200");
// 4. Send Rate Command at the new speed
delay(100);
Serial1.write(setRate, sizeof(setRate));
Serial1.flush();
Serial.println("GPS: Config Complete (115200 baud, 5Hz)");
}
