This QuackPack adds GPS position and time to a Duck. It reads NMEA from a GPS module on an ESP32 hardware UART with TinyGPS++, without blocking the Duck's loop(). It also:
- detects the module's baud rate;
- configures u-blox receivers (NEO-6M, NEO-7M, NEO-M8N and similar);
- builds the GPS payload for the ClusterDuck Protocol
gpstopic.
CDP logging is used when available; standalone GNSS sketches need only TinyGPSPlus. For L76K use the nonblocking start(Options) API below. The legacy u-blox begin() API still performs blocking setup.
A QuackPack is a modular library that extends Duck firmware with application-specific functionality. QuackPacks are not standalone projects: they are included in a Duck firmware project and configured from its sketch.
- Primary: LilyGO T-Beam v1.2 (SX1262, AXP2101 PMU)
- Also: T-Beam v1.0/v1.1, and ESP32 boards with a GPS module on a hardware UART
- New profile/example: T-Beam Supreme L76K, compile- and host-tested; physical validation remains required. This PR does not add M10 configuration support.
begin() uses the board's CDPCFG_GPS_RX / CDPCFG_GPS_TX from the CDP board headers. Without them, it uses the T-Beam pins.
| Signal | T-Beam GPIO | Notes |
|---|---|---|
CDPCFG_GPS_RX (ESP32 receives) |
34 | wired to the GPS module's TX |
CDPCFG_GPS_TX (ESP32 sends) |
12 | wired to the GPS module's RX |
| GPS power | AXP2101 ALDO3 | T-Beam v1.2: must be on, 3.3 V |
On the T-Beam v1.2 the GPS module runs from the AXP2101 PMU's ALDO3 rail. The library does not manage power. Switch the rail on before dgps.begin(), or baud detection will hear nothing:
#include <XPowersLib.h>
XPowersAXP2101 pmu;
Wire.begin(21, 22);
if (pmu.begin(Wire, AXP2101_SLAVE_ADDRESS, 21, 22)) {
pmu.setALDO3Voltage(3300);
pmu.enableALDO3();
}Cutting ALDO3 before deep sleep powers the GPS down. Call dgps.end() before sleep, then turn the rail back on and call begin() again after wake.
- PlatformIO
- An ESP32 Arduino project; CDP 5.x is optional (the mesh example is built against CDP 5.5)
Add the QuackPack to your project's lib_deps. Pin it by commit SHA and name the tag in a comment, the same way the project pins CDP. A tag can be moved; a SHA cannot. Name the dependency (QuackPack-DuckGPS = ...) so PlatformIO treats every reference as one package.
lib_deps =
; your project owns the CDP pin
ClusterDuck-Protocol = https://github.com/Project-Owl/ClusterDuck-Protocol.git#0f47693450c948f6a3d9426a6077456560b9c838
; QuackPack-DuckGPS v1.1.0
QuackPack-DuckGPS = https://github.com/Project-Owl/QuackPack-DuckGPS.git#<v1.1.0 commit SHA>git rev-list -n 1 v1.1.0 prints the commit of a tag.
The library depends only on mikalhart/TinyGPSPlus, pinned to tested version 1.0.3. Broad ^1.0.2 resolution now selects 1.1.0, whose new pending location mode field is read uninitialized when GGA commits before an RMC mode; sanitizer testing caught this. Do not silently override the verified parser version in the application. No third-party source is modified or vendored here.
It has no ClusterDuck-Protocol dependency on purpose. A git-URL dependency in a library's library.json is re-resolved on every pio pkg install, and it replaces the CDP version the project pinned. Version 1.0.0 did this: a project pinning CDP 5.5 ended up building CDP 5.0.1. Each project pins CDP itself.
With PlatformIO's default library finder (chain), only sketches that #include <DuckGPS.h> compile the library, so other ducks in the same project (for example PapaDucks) do not grow.
#include <CDP.h>
#include <arduino-timer.h>
#include <DuckGPS.h>
MamaDuck duck("MAMAGPS1");
DuckGPS dgps; // Serial1; nothing happens until begin()
auto timer = timer_create_default();
int32_t gpsCounter = 0;
bool sendGps(void*) {
char payload[DuckGPS::JSON_MAX_LEN];
if (dgps.toJson(payload, sizeof(payload), gpsCounter) > 0 &&
duck.sendData(topics::gps, std::string(payload)) == DUCK_ERR_NONE) {
gpsCounter++;
}
return true;
}
void setup() {
// power the GPS here (see above), then:
dgps.begin(); // board pins, automatic baud, u-blox setup
duck.setupWithDefaults();
timer.every(60000, sendGps);
}
void loop() {
dgps.update(); // never blocks
timer.tick();
duck.run();
}The full sketch is in examples/BasicDuckFirmware.
DuckGPS gnss;
DuckGPS::Options options;
options.receiver = DuckGPS::Receiver::L76K;
options.rxPin = 9; // Supreme host RX, per LILYGO working example
options.txPin = 8;
options.baud = 9600; // confirmed/default L76K baud
options.constellations = 0; // preserve factory selection; 7 requests GPS+BDS+GLONASS
// Power GNSS first. start() accepts options; it does not wait for a receiver/fix.
bool accepted = gnss.start(options);
// In every loop pass:
gnss.update();See the standalone Supreme example for AXP2101 ALDO4, PMU Wire1 pins 42/41, and L76K wake GPIO7. The classic T-Beam's ALDO3 example must not be copied to the Supreme. Manufacturer utilities specify host RX9/TX8; module-perspective tables can be misleading. Verify your purchased revision and antenna before flashing.
Options.receiver = Receiver::NmeaOnly is passive/read-only, including for a preconfigured receiver. It sends no proprietary configuration. The L76K path uses PCAS, not u-blox UBX or MediaTek PMTK. There is no auto-detection guess about receiver model. The selected profile is a caller assertion, not verified hardware identity.
| Phase | Behaviour |
|---|---|
| Power settling | Default 1500 ms elapsed-time grace, matching LILYGO's startup example. update() returns between checks; the board must already be powered. |
| Detection | Listen for a checksummed NMEA sentence; no first fix required. Fixed baud is preferred. baud=0 passively tries 9600, 115200, 38400, 57600, 19200 and 4800 with a 1500 ms window each. |
| Configuration | L76K: request 1 Hz and GGA/RMC once per solution using PCAS02/03; optional PCAS04 constellation selection. At least 100 ms between command writes, no blocking delay. Only enqueue a command when the whole frame fits the UART TX buffer. |
| Observation | commandsSent is not a configuration ACK. Observe paired GGA/RMC and consecutive 1-second solution times before Ready for configured L76K. Observation timeout defaults to 10 s. |
| Acquisition | Valid output with no position is normal while searching. Keep servicing GNSS/mesh; never sit in a wait-for-fix loop or reset the receiver every report. Ready describes observed output, not a usable location or verified constellation readback. |
| Late/missing output | TimedOut is visible but parsing continues; late valid output can recover. A completed passive scan falls back to 9600. For other known baud rates supply the actual baud or deliberately restart scanning. |
The PCAS text set commands used here have no handled ACK/readback. Rate and sentence output are observed, not proof that every configuration choice applied. No factory reset, baud change, flash-save, assistance download or unverified jamming settings are sent. The 1 Hz configuration intentionally avoids the protocol's higher-rate sentence/115200 constraints. Use the Quectel L76K protocol specification for those extensions.
There is no delay/wait loop in start() or its update() path. Arduino UART opening/enqueueing and callback execution still cost time: this is cooperative bounded work, not a hard real-time guarantee. maxBytesPerUpdate defaults to 512 and the UART RX buffer to 2048. Call more often than the incoming data can fill that buffer, measure the worst loop gap, and bound SD work. A UART/hardware overrun can lose data before this library sees it; this API does not claim an overrun counter it cannot observe.
void capture(const DuckGPSFix& fix, void* context) {
// Copy EVERY snapshot into your bounded logger queue here.
// Account for queue-full; do not write SD, print, wait, or call update() here.
}
gnss.onFix(capture, nullptr); // registration survives restart
DuckGPSFix current;
if (gnss.latestFix(current)) { /* inspect immutable fields/validity */ }The stream pairs GGA and RMC by UTC time-of-day (millisecond resolution), regardless of talker/order. It emits once after both arrive, at the next epoch, or after joinWindowMs (250 ms default) when the UART backlog is drained. Missing partners are explicit: RMC-only has no GGA quality/altitude; GGA-only has no date. No previous date is inferred across midnight. Late partners are ignored rather than producing another row. The bounded duplicate cache covers the last 16 emitted epochs within 60 seconds, not arbitrary historical replay.
Invalid/no-fix solutions are emitted with positionValid=false. Preserve them as diagnostics without presenting zero/default coordinates as a valid location. quality, satellite/HDOP validity, MSL altitude, original UTC, receive millis and sequence are available. rejectedSentences() counts checksum/format rejects; fixCount() counts emitted solutions. No SD storage is implemented by this library.
A first valid fix is not an accuracy guarantee. Keep the receiver running between radio reports, allow open-sky acquisition, compare constellation mode 7 against factory selection on the actual antenna, and measure stationary spread and reference error before choosing thresholds. Applications may require fresh UTC, enough satellites, acceptable HDOP and stable consecutive fixes for a usable report, while retaining every snapshot in the log. Poor HDOP should not erase evidence. A GNSS outage must remain unknown; the library never invents a position or a horizontal accuracy in metres from HDOP. hasFix() checks current snapshot validity/arrival age only, not these application quality thresholds.
Raw getters and parser() remain legacy latest-field access. Use latestFix() or onFix() for coherent records; epoch()/timeValid() describe parser time and can advance independently of position. toJson() uses the immutable snapshot.
Include <DuckGPS.h>; the class is DuckGPS. All times are UTC.
| Method | Description |
|---|---|
DuckGPS(HardwareSerial& port = Serial1) |
Creates the handler. Does not touch the hardware. |
bool begin(int rx = DUCKGPS_DEFAULT_RX, int tx = DUCKGPS_DEFAULT_TX, uint32_t baud = DuckGPS::AUTO_BAUD, bool configureUblox = true) |
Opens the UART and detects and configures the module (see below). Returns false if nothing answered; the UART stays open. |
void end() |
Closes the UART (for example before deep sleep). |
bool update() |
Advances async startup and parses at most 512 waiting bytes by default. Call frequently. True if a solution snapshot was emitted, including a no-fix solution. |
bool readData(unsigned long ms = 5000) |
Blocking: parses for ms milliseconds. True if a new fix arrived. Prefer update(). |
bool hasFix(uint32_t maxAgeMs = 5000) |
A position fix arrived within maxAgeMs. |
bool timeValid(uint32_t maxAgeMs = 5000) |
A plausible UTC date and time arrived within maxAgeMs. A receiver often knows the time before it has a fix. |
double lat(), double lng() |
Last position, decimal degrees. |
double altitudeM() |
Altitude above mean sea level, metres. |
double altitudeFt() |
Altitude above mean sea level, feet. |
double speedKmph() |
Ground speed, km/h. |
uint32_t satellites() |
Satellites used in the fix. |
uint32_t hdop() |
HDOP in hundredths (120 means 1.2). |
std::time_t epoch() |
Unix time of the last sentence, or 0 when the date or time is invalid. Computed without mktime() or TZ. |
std::string ISO8601() |
YYYY-MM-DDThh:mm:ssZ, or "" when epoch() is 0. |
std::string geoJsonPoint() |
{"type": "Point", "coordinates": [lng,lat]} |
size_t toJson(char* out, size_t size, int32_t counter = -1, uint32_t maxAgeMs = 5000) |
Writes the GPS payload (below). Returns its length, or 0 if it did not fit. |
uint32_t baud(), bool isUblox() |
What begin() found. |
bool sendUbx(uint8_t cls, uint8_t id, const uint8_t* payload, uint16_t len, uint16_t ackTimeoutMs) |
Sends any UBX message; waits for its ACK unless ackTimeoutMs is 0. |
TinyGPSPlus& parser() |
The underlying TinyGPS++ parser, for anything not wrapped here (course, custom NMEA fields, counters). |
Constants: DuckGPS::AUTO_BAUD (0), DuckGPS::DEFAULT_MAX_AGE_MS (5000), DuckGPS::JSON_MAX_LEN (192, always enough for toJson()), DUCKGPS_VERSION ("1.1.0").
With a position:
{"c":7,"lat":48.117300,"lng":11.516667,"alt":545.4,"sats":8,"hdop":0.90,"t":"2026-11-04T12:35:19.000Z"}Without a position:
{"c":7,"error":"No GPS fix","chars":420}cis the counter argument; it is left out when the counter is negative.latandlnghave 6 decimals; this is representation precision, not measured accuracy.altis in metres, the unit the DMS expects.hdopis the real HDOP."stale":trueis added when the last fix is older thanmaxAgeMs.tis the original solution UTC (including milliseconds), retained when stale. A GGA-only solution has no known date and omitst. A later time-only sentence never relabels old coordinates.alt,satsandhdoponly appear when supplied in this solution. No old quality or altitude fields are carried forward.hdopis dimensionless, not metres.charscounts bytes parsed from the module. Zero is a diagnostic cue, not proof of a specific wiring/power fault.- The bounded JSON writer returns 0 (and an empty buffer) on overflow; check its result before sending.
-
Opens the UART with a 2 KB receive buffer.
-
With
AUTO_BAUD, probes 9600, 115200, 38400, 57600 and 19200 baud with a UBX CFG-RATE poll. A u-blox answers at its configured rate; this is the same probe as the DMSgetUbloxAck(). A module that only sends NMEA is recognised from a sentence with a valid checksum. If nothing answers, the UART stays atDUCKGPS_FALLBACK_BAUD(9600). -
When a u-blox answered and
configureUbloxis true, it configures the receiver:- 1 Hz updates, with GGA, GSA and RMC output (GLL, GSV and VTG off);
- GPS + SBAS + Galileo + QZSS + GLONASS;
- AssistNow Autonomous and interference detection.
Each message waits up to 1 s for its ACK at 9600 baud, and 0.3 s at higher rates. Configuration stops after two unanswered messages.
Typical blocking time in setup():
- about 0.2-0.7 s for a u-blox at 9600 baud;
- about 1.2 s at 115200;
- about 3.4 s when no module answers.
begin(rx, tx, 9600, false) opens the UART and returns at once.
Set these with -D in build_flags.
| Define | Default | Meaning |
|---|---|---|
DUCKGPS_DEFAULT_RX / DUCKGPS_DEFAULT_TX |
CDPCFG_GPS_RX / CDPCFG_GPS_TX, else 34 / 12 |
Default pins for begin() |
DUCKGPS_FALLBACK_BAUD |
9600 | Baud rate when detection hears nothing |
DUCKGPS_RX_BUFFER_SIZE |
2048 | UART receive buffer, bytes |
DUCKGPS_MIN_VALID_YEAR / DUCKGPS_MAX_VALID_YEAR |
2024 / 2079 | Dates outside this range count as invalid. u-blox modules report 1980-01-06 before they know the time; TinyGPS++ reads that as 2080. |
The tag phoenix-2026 marks the copy that phoenix-zoo vendors (temp-phoenix, a6699b9). From that copy:
DuckGPS dgps(34, 12);plusdgps.setup();becomesDuckGPS dgps;plusdgps.begin(34, 12);(or justdgps.begin()on a CDP board). The constructor no longer opens the UART.altitude(DuckGPS::AltitudeUnit::feet)becomesaltitudeFt(), or betteraltitudeM(). Note that a payload "alt" in feet becomes metres if you switch.speed(DuckGPS::SpeedUnit::kmph)becomesspeedKmph().localHour(),hour(),minute(),second()are gone. Useepoch()/ISO8601(), orparser().time.setBaudrate()andsendMsgWithAck()are gone;sendUbx()sends any UBX message.readData(ms)still exists and returns bool. It now parses correctly, butupdate()fromloop()is the intended use.epoch()now returns 0 for an invalid date or time, andISO8601()returns"".- Adafruit uBlox and Adafruit BusIO are no longer dependencies.
pio run # builds examples/BasicDuckFirmware for the T-Beam
pio run -t upload
pio device monitorplatformio.ini uses the same platform as the DMS builder (espressif32 7.0.1) and CDP 5.5 pinned by commit. GitHub Actions builds both examples and runs host tests on every push and pull request.
pio run -e supreme_l76k
bash tests/host/run.shThe host suite runs the real fix assembler and DuckGPS with a fake UART/clock under AddressSanitizer and UndefinedBehaviorSanitizer. It covers PCAS checksums, startup/backpressure/timeouts/recovery, bounded input, coherent burst capture, missing/invalid fields, dates/midnight, duplicates, JSON and the legacy API. These are not physical receiver/RF tests. Validate cold/warm start, observed rate, serial service gaps, fix spread and power on the actual L76K before deployment.
- ClusterDuck Protocol: 5.x (built and tested against Project-Owl CDP 5.5, 0f476934)
- PlatformIO: 6.1+
- Platform: espressif32 7.0.1 (Arduino core 2.0.17)
- Development environment: PlatformIO only (Arduino IDE not supported)
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
- Explicit nonblocking L76K/read-only startup profiles; existing blocking u-blox begin API retained.
- Bounded GGA/RMC solution snapshots and callbacks, including no-fix states and field validity.
- JSON retains original fix timestamps and six decimal places; current invalid fixes cannot reuse old coordinates.
- Standalone Supreme example, host regression tests and CI for both examples.
- No M10 configuration or physical GNSS accuracy/endurance claim in this release.
begin()opens the UART (no longer the constructor), detects the baud rate and configures u-blox modules with short ACK waits.update()forloop(), plushasFix()andtimeValid().- Fixed NMEA parsing: main never parsed anything, and temp-phoenix fed -1 bytes to TinyGPS++.
epoch()andISO8601()validate the time and compute UTC withoutmktime().- Altitude getters are explicit about units;
toJson()builds the GPS payload with altitude in metres. - No CDP dependency in
library.json, owner-qualified dependencies, and Adafruit uBlox dropped. - Example and CI build against CDP 5.5.
- Initial release
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
- Built on the ClusterDuck Protocol
- Created by OWL Integrations
- OWL Integrations
- OWL DMS - Device Management System for mesh networking
- ClusterDuck Protocol
- Discord Community
- DMS Support: support@owlintegrations.com
For questions and support:
- Join the ClusterDuck Protocol Discord
- Open an Issue
- Brenton Poke - Initial work - @BrentonPoke