Repository navigation
Runtime-configurable GPS pins and baud (companion) 🤖🤖 - #3683
ajgray2017 wants to merge 3 commits into
Conversation
External GPS modules are often wired to arbitrary header pins, but PIN_GPS_RX/TX/EN and the baud rate were fixed per variant, so such a GPS was never detected without a custom build. - New sensor settings gps_rx, gps_tx, gps_en, gps_baud via the existing custom vars. They show the effective value; setting a board default (or -1 / 0) follows the board again. - Companion persists them in NodePrefs (gps.pin_rx/pin_tx/pin_en/baud) and applies them before sensors.begin(); changes apply after reboot. - Listed even when no GPS was detected so bad pins can be fixed. - Pins used by the variant (LoRa, I2C, button, Vext, LED, ...) and ESP32 flash/PSRAM/USB-serial pins are rejected. - LocationProvider::setEnablePin() lets MicroNMEALocationProvider switch the enable pin at runtime. - Not applied to RAK WisBlock GPS boards. FAQ 5.17. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gps_rx/gps_tx/gps_en were parsed with atoi() and validated as int, then stored in int8_t. A value above 127 could pass validation and wrap on store: on a Heltec V3, gps_rx=300 was accepted and saved as 44 (UART0 RX, which the check itself rejects), and gps_en=290 was saved as 34 while gps_tx was 34, bypassing the duplicate-pin check. On ESP32, GPIO_IS_VALID_GPIO() shifts 1ULL by the pin with no bounds check, so pins of 64 and up were undefined behaviour. - Parse pins and baud as whole decimal numbers: "abc" or "34x" is now an error instead of 0. Pins must be -1..127 before any other check. - On ESP32, reject pins >= SOC_GPIO_PIN_COUNT before GPIO_IS_VALID_*. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
getSettingName()/getSettingValue() returned the pin settings by range but, unlike the "gps" entry, did not advance the running index. Any setting added after them would be looked up at the wrong index and return NULL while getNumSettings() still counted it; CMD_GET_CUSTOM_VARS strcpy()s that name. Advance the index so later settings (such as gps_duty in a separate PR) can be appended in either order. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
You should probabli use the cli instead of custom vars, now we have companion cli I'm not sure we'll continue with them as it is not as straightforward to use as we thought It would be good if it was also usable in repeaters, with as little change as possible (something like how radio prefs work) radio prefs work on both repeater and companion with the same cli interface (although the parameters are not stored in the same way) An please, you can use AI to help you ... but when you have a direction I think you should try to do your code yourself and not let claude do the commit for you ... it gives a bad impression along with all the bloat text it writes each time (and we as maintainers have to read with the risk of falling asleep). I'm sure you can do better than an AI. (I see no problem in copying generated code, and I sometimes do it myself, but by doing the integration yourself you really embrace what you write and don't let the AI write in your place) |
|
and also, about the PR itself, I'm not really sure ... As you mention meshtastic, we are not meshtastic ... and don't share the basic philosophy of one unique big firmware (which is a valid stance but not ours) So it totally make sense that, for a custom board, someone has to configure and compile its own firmware so that the firmware does not get bloated by unnecessary things ... |
|
I'm still not sure about this one ... If someone makes a custom configuration with it's own gps pinout configuration, he would probably know enough to make the variant that goes with it ... Won't close this PR (because other maintainers can have their own thought about it), but for now I won't be the one to merge it either ... |
Problem
External GPS modules are often wired to whatever header pins are free (for example on a Heltec V3), and Meshtastic lets users set those pins at runtime. MeshCore fixes
PIN_GPS_RX/TX/ENand the baud rate per variant, so such a GPS is never detected and the only fix is a custom build.Change
CMD_GET/SET_CUSTOM_VAR, so there is no protocol change:gps_rx,gps_tx,gps_enandgps_baud. The names follow the existingPIN_GPS_*macros.gps_rx:47, gps_tx:48, gps_en:26, gps_baud:9600. Setting the board's own value, or-1(0forgps_baud), makes the setting follow the board default again.NodePrefs(gps.pin_rx,gps.pin_tx,gps.pin_en,gps.baud) and applied beforesensors.begin(), so changes take effect on the next reboot. Existing prefs load as "board default".EnvironmentSensorManager::configureGPS(). Only the companion calls it, because only the companion saves the values. Repeater, room server and sensor firmware are unchanged. Wiring upCommonCLIprefs could be a follow-up.LocationProvider::setEnablePin()(a no-op by default) letsMicroNMEALocationProvidertake over the enable pin at runtime. It releases the variant's default pin.Testing
Two Heltec V3 companions (USB build), each with a u-blox module with TX on GPIO34, RX on GPIO33, VCC from GPIO42. Everything below passed on the first board. The second passed the same set except the
gps_rx=49and empty-value cases, which weren't run there:gps_rx:47, gps_tx:48, gps_en:26, gps_baud:9600, andgpsis absent.ERR_CODE_ILLEGAL_ARG:gps_rx=8(LoRa NSS),gps_en=29(flash),gps_en=43(UART0).gps_rx=34whilegps_tx=34.gps_baud=12345,gps_rx=300,gps_rx=127,gps_rx=49,gps_rx=abc,gps_rx=34x, an empty value,gps_baud=abc.gpslisted), the values persisted, and a savedgps=1was restored.-1/0) and rebooted. The GPS was no longer detected.pio test -e native -e native_kiss_modempasses (54/54).Compile-checked (all build, no new warnings;
wio_wm1110_repeatershows the same 5ENV_INCLUDE_GPS redefinedwarnings asdev):Heltec_v3_companion_radio_usb,Heltec_v3_companion_radio_ble,Heltec_v3_repeater,Heltec_v3_room_server,Heltec_t114_companion_radio_ble,Heltec_Wireless_Tracker_companion_radio_ble,Tbeam_SX1276_companion_radio_ble,Tbeam_SX1276_repeater,LilyGo_TDeck_companion_radio_ble,RAK_4631_companion_radio_ble,RAK_4631_companion_radio_ethernet,RAK_4631_repeater,RAK_4631_repeater_ethernet,RAK_4631_room_server,RAK_4631_room_server_ethernet,PicoW_repeater,wio-e5-mini_repeater,LilyGo_Tlora_C6_repeater_,wio_wm1110_repeater.Known limitations
RADIOLIB_NC, so it is accepted.Note
#3684 (GPS power cycling) is independent and also branches from
dev. Both touch the GPS settings list,GPSPrefsand the FAQ numbering. I test-merged the two: the conflicts are "keep both sides", plus one shared#ifblock in the header and the FAQ renumbered to 5.18. The result runs on a Heltec V3 with all six GPS settings working.🤖 Generated with Claude Code