blink: a fixed burst is a race against walking to the bench -- 30 blinks
(~7 s) was not enough to find the board in time. `blink on` now runs until
`blink off`, with a 10-minute backstop so a node left blinking does not
quietly eat a battery. Cap on the counted form raised to 999.
txpwr: `set tx` cannot tell you whether the radio took the value. It clamps
to -9..30, saves the pref and replies "OK", but SX1262 accepts only -9..+22
and rejects the rest WITHOUT touching the PA -- so `get tx` can report a
power the radio never had. An earlier sweep here measured +2 dBm and -9 dBm
as RSSI -44.1 and -44.0 at a witness and concluded runtime tx power "does
not work"; that conclusion rested on an instrument that could not
distinguish a refused request from a link that does not care.
RadioLibWrapper::setTxPower keeps the status now (the signature stays void,
it implements an upstream callback), and `txpwr [dBm]` reports it. It
deliberately does not write the pref, so a sweep cannot leave a node booting
at some experimental power.
xiao_uf2_flash.sh: the 1200-baud touch is roughly a coin flip on this build.
Today it worked twice, then wedged x4, then wedged x1 -- and a wedged board
is gone from USB *and* BLE, does not recover on its own (waited 400 s) and
needs a physical replug. Not a "too soon after boot" effect: x1 had been up
23 minutes. Double-tap RESET into UF2 is reliable and takes seconds, so this
makes that the easy path. It refuses to act when several UF2 drives are
present rather than guessing, since they are all labelled XIAO-SENSE.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A bench of identical XIAOs cannot be told apart. The USB serial number
needs a data cable, and boards sharing power rails have none; the BLE MAC
is printed nowhere; and ADVERT_NAME is only as trustworthy as the last
flash, which is usually the thing being checked. Today two boards in the
same breadboard were both advertising "bench-board" -- one of them the
board with the burned DIO1, still happily running BLE.
`blink 10` flashes an LED ten times (default 6, clamped 1..30), and works
from serial, the BLE console and the mesh admin CLI, so it also reaches a
node that is already mounted somewhere.
Deliberately not the status LED. On XIAO that is LED_BLUE, which Bluefruit
drives as its connection indicator -- every BLE node blinks blue the same
way, which is why the LED was useless for identification in the first
place. Preference order LED_GREEN (XIAO, free) -> LED_WHITE (SenseCap, only
ever touched at boot and powerOff) -> LED_BUILTIN, which is last because on
SenseCap it is pin 12, the LoRa TX indicator. Variants may define a colour
they do not physically have by pointing it at PINS_COUNT (SenseCap does
that with LED_RED), so the chain range-checks rather than trusting #ifdef.
Driven from loop(), not inline: a blocking burst would stall the mesh for
up to ~7 s at the cap and disturb the very LoRa timing this fleet measures.
Always finishes dark. Goes through LED_STATE_ON, which is 0 on XIAO and 1
on SenseCap -- hard-coding HIGH would leave half the fleet unlit.
Verified on bench-board over the USB console: "blink 10" ->
"OK - blinking 10 times", and the build stamps v1.16.0-ttha12965f+.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two halves of the same problem: the stamped version reached the device but
not the client.
RESP_CODE_DEVICE_INFO carries the build date in 12 bytes and the version in
20, NUL included -- 11 and 19 usable characters. The version field is
written with strzcpy() and truncates safely; the build date was a bare
strcpy() into a memset region, so a longer string simply ran past the end
into the manufacturer-name field. It never showed because strzcpy()
overwrote that field on the very next line. Benign today, and driven by a
compile-time constant rather than anything remote, but it is an unbounded
copy into a fixed frame slot and the only reason it was invisible is luck
about the write order. Now strzcpy(..., 12) like every other string there.
The stamp then had to fit. "v1.16.0-tth-0dbaba04" is 20 chars, so the node
reported "v1.16.0-tth-0dbaba0" -- readable, but a character short of the SHA
it was built from. "04 Aug 2026 11:28" is 17, so the time was cut clean off.
Now a 7-char SHA with a "-tth" marker (19 with the dirty '+', 18 without)
and a yymmdd hhmm date (11). The budget never sacrifices the base version or
the dirty marker -- a lost '+' would make an uncommitted build look
reproducible -- and warns instead of truncating silently if it ever cannot
fit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ble_dfu find(): with want_dfu it accepted ANY device whose name contained "DFU"
and then took the first one the scan returned. With more than one board in
bootloader at the same time that reaches for someone else's hardware. It just
did: target CE:72:…:02, connected FE:11:…:C4. Caught only because the log was
being read by hand -- a few seconds later START_DFU would have overwritten a
different node. The address is now mandatory (MAC or MAC+1, covering both the
SCAP_DFU-on-MAC+1 and AdaDFU-on-same-MAC bootloaders), and foreign boards in
bootloader are listed as explicitly ignored.
ble_cli.py: the BLE console had no tool, so every ad-hoc script re-implemented
it and re-learned the same trap: a NUS write carries ATT_MTU-3 bytes and BlueZ
will not split it, so at the usual MTU 23 anything over 20 bytes fails with
"Failed to initiate write" -- which reads like a dropped link, not "command too
long". Commands up to 18 chars work, longer ones fail, deterministically.
Chunking is now in one place, with retries and the pairing/single-console
caveats documented.
simple_repeater: ADVERT_INTERVAL_DEFAULT / FLOOD_ADVERT_INTERVAL_DEFAULT /
DISABLE_FWD_DEFAULT, so a node can be built to ship silent. ENABLE_ADVERT_ON_BOOT
alone is not enough -- it only suppresses the boot advert, the periodic timer
still fires, so an `erase`d node is on the air within two minutes. Found the
hard way: a node flashed before this change and then erased spent ~44 s
transmitting on the live CZ frequency from a desk.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Upstream never initialises _prefs.path_hash_mode, so a fresh node came up at
mode 0 = 1 byte per hop. Nobody on the CZ mesh runs 1 B any more, which meant
every new install needed a manual `set path.hash.mode 1`. Default it to 1 at
compile time in both the repeater and the companion; the pref still overrides
it, so existing nodes are unaffected.
NOTE this is the PATH hash, not PATH_HASH_SIZE. It is used as
sendFlood(..., path_hash_mode + 1), i.e. the bytes each hop appends to the path
while flooding, and the size travels in the packet -- Packet.h:85 packs it into
the top two bits of path_len and Mesh.cpp:93 matches with getPathHashSize() --
so mixed-mode nodes still route for each other. PATH_HASH_SIZE (1) is a
different field, the destination and channel hash in Mesh.cpp:458/548, and
changing THAT would break the wire format against every other node in the mesh.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two diagnostic levers for the BLE/LoRa coexistence work, plus a correction to
what the existing tx power call actually does.
Bluefruit.setTxPower(8) is ADVERTISING power only. Bluefruit stores the value
and BLEAdvertising::start() hands it to sd_ble_gap_tx_power_set() with
BLE_GAP_TX_POWER_ROLE_ADV; nothing in the library ever sets the CONN role, so an
established link runs at the SoftDevice default of 0 dBm. The +8 buys discovery
range and nothing else. Confirmed on hardware: `blepwr` reports
"conn tx: 0 dBm, adv tx: 8 dBm".
- RPT_BLE_CONN_TX_POWER (default 0 = unchanged behaviour), applied per
connection on every 'secured' since the handle is new each time.
- `blepwr [dBm]` sets it at runtime over serial, the BLE console or the mesh
admin CLI. Runtime rather than a build flag because a dose-response sweep
needs many points and reflashing the XIAO costs a physical UF2 dance.
- Auto-revert after 5 min (`blepwr <p> hold` opts out). Without it the command
locks you out of the console you would need to undo it: the value is
re-applied on every 'secured', at -20 dBm the node's replies stop arriving and
at -40 dBm a connection cannot be established at all. Hit this on the bench;
recovery was over USB, and on the mast the only way back would be `reboot`
over the mesh admin CLI.
- `bleconn` reports the connection parameters actually in force. bleOnSecured()
only REQUESTS 15-30/60-80 ms and the central may refuse, so without reading
them back "the pre-fix interval showed no loss either" cannot be told apart
from "the pre-fix interval was never in force". Latched once a second from
loop() so it can be read over USB after the central is gone -- reading it over
the BLE console while connected would collide on the shared command[160].
Measured with these: at a verified 22.50 ms interval, sweeping the connection
tx power from 0 to -20 dBm (RSSI -67..-87 at the central, covering the whole
-75..-90 window the mast sits in) produced zero lost DIRECT forwards, with
tx_timeout and tx_start_fail at zero in every cell.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bleWriteAll used to spin-retry with delay(3) when the SoftDevice
notification queue was full, stalling loop() up to ~0.9 s per call
while a client streamed the console (rxlog/pktlog drains). That is
long enough to disturb LoRa RX/TX timing on the relay path.
Replace with a 4 KB ring buffer: bleWriteAll only enqueues, and
bleTxPump() (each loop pass) hands the SoftDevice as much as it will
take right now — zero waiting. Overflow truncates the newest bytes;
a torn page loses its 'E,' trailer so the bridge re-requests the
same cursor.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fewer SoftDevice connection events = fewer LoRa TX collisions (the
measured driver of the direct-forward loss); the Dispatcher TX retry
covers the residue. Bigger pktfeed ring buys margin for the bridge's
new connect->drain->disconnect duty cycle (~3-4 min between drains).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A TX that fails to start (startTransmit error) or never completes
(send-complete IRQ lost) was released permanently — with an nRF52
SoftDevice servicing BLE connection events this silently ate ~40 % of
DIRECT-route forwards (measured A/B on mast-three: direct_rx +5 / direct_tx
+3 with an idle BLE connection, 5/5 with BLE off). Flood redundancy
masked the same loss for flood traffic.
Retry up to MESH_TX_RETRIES (3) with a short growing backoff; a
duplicate on air is harmless (hasSeen dedup). New tallies
tx_start_fail/tx_timeout in stats-packets + ERR_EVENT_TX_* flags make
this failure class visible at last.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Small sibling ring to rxlog (PKTFEED_SIZE=32, ~8.6 KB) that keeps the FULL
raw frame bytes: staged pre-parse in logRxRaw, committed post-parse in logRx
(radio garbage never enters). Paged `pktlog [cursor]` mirrors rxlog paging;
the bridge derives route/type/payload and the MeshCore SHA packet hash
(analyzer correlation key) from raw, so the radio hot path stays SHA-free.
No 'always emit >=1' here: a ~550 B record line would overflow the 150 B
mesh-CLI budget — there the reply degrades to a bare trailer.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The BLE bridge drain was throttled by three multiplied costs: 150 B pages
(~3 rxlog records), 20 B NUS notification chunks, and the bridge waiting for
line silence per page. This fixes the firmware half:
- handleCommand() takes an explicit reply_max (default 150). The local console
(USB/BLE) passes ~1000 B -> ~20 rxlog records / ~7 nodes lines per round
trip; the mesh admin CLI keeps 150 so its reply still fits one LoRa packet.
Explicit parameter on purpose: a forged sender_timestamp==0 from the mesh
path must never be able to grow the reply past its 166 B buffer.
- bleWriteAll() chunks by negotiated MTU (247 -> 244 B) instead of fixed 20 B.
- Tables sized from channel physics instead of last week's traffic:
RXLOG_SIZE 512 = ~2 min of a saturated SF8/62.5k channel (~2-4 frames/s),
MAX_HEARD_NODES 128 > distinct nodes heard per neighbour advert period
(48 filled in <2 h and churned out real 0-hop neighbours).
- Page-sort scratch arrays moved off the loop-task stack into BSS.
RAM 17.7% -> 25.3% (59.6 KB / 235 KB). Flashed via BLE DFU 2026-07-15.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The path field emitted raw hex, but the hop-hash width (1/2/3 B, top 2 bits of
path_len) wasn't visible in it -- the bridge couldn't tell "A31FC2" from three
1-byte hops vs one-and-a-half 2-byte hops. Emit hops colon-separated instead
("A3:1F:C2" vs "A31F:C204"): each token is one hop, its width is len/2. Field
order/count is unchanged (path stays the same column), so the bridge only
changes how it splits that one token. Shared helper analyzer_path_hex() used by
both nodes and rxlog. (`HEX` had to be a local name other than the Arduino
Print.h `HEX` macro.)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two related improvements to how heard nodes are represented:
1. Multi-path. A node's advert reaches us via several paths at once, but the
mesh dedups by payload hash (path not hashed) so onAdvertRecv sees only the
first copy -> `nodes` kept one path. rxlog, however, is fed pre-dedup and
logs every copy with its own path+SNR. Add the advert's FNV id (`pkt_hash`)
to each `nodes` row as a JOIN KEY: the bridge groups rxlog by pkt_hash and
joins to nodes to reconstruct every route a named node arrived by. New
`nodes` field: N,...,<age>,<pkthash>,<path>,<name> (name now after 10th comma).
2. Prefer direct. onAdvertRecv often processes a relayed copy first (stronger),
so the direct 0-hop link was being overwritten by a relayed path -- the
direct neighbours only showed up via the old `neighbors` path. Track
`direct_heard`; keep the direct (empty) path + its SNR for
HEARD_DIRECT_TTL_SECS after last hearing the node 0-hop.
Shared FNV helper (analyzer_frame_id) now used by both captureRx and
putHeardNode so nodes.pkt_hash == the rxlog copies' pkt_hash exactly.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
btmon shows the disconnects are HCI reason 0x3E (Connection Failed to be
Established / lost sync), not supervision timeout -- so widening the timeout
didn't help. The mast link is weak (RSSI -75..-90) and the node is busy with
LoRa; with slave latency 4 the peripheral may skip connection events, so the
central loses sync and reports 0x3E. Respond on every event (latency 0) to
maximise sync on a weak/busy link.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6 s cut the reconnect churn from every 15-30 s to every ~60 s but didn't
eliminate it: under the bridge's real polling load the node shows a
periodic multi-second stall (advert TX airtime / SoftDevice-LoRa
coexistence) that occasionally exceeds 6 s. Widen the supervision timeout
to 16 s so those stalls are tolerated; a genuine freeze is still caught by
the 20 s hardware watchdog (16 s < 20 s).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The BLE console link dropped every ~15-30 s and the bridge kept
reconnecting. Root cause: Bluefruit's default supervision timeout is only
2 s, and this repeater relays heavy LoRa flood traffic, so main-loop /
radio coexistence stalls past 2 s and the central tears down the link.
Mirror the companion's proven approach (explicit sd_ble_gap_conn_param_update
on 'secured', since some centrals ignore the advertised PPCP) but widen the
supervision timeout to 6 s (a repeater is far busier than a client), with a
15-30 ms interval and slave latency 4. PPCP is also set before advertising.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
captureRx() ran calculatePacketHash() (SHA-256) on every received frame in
the logRx hot path. The mesh core already computes that SHA once per frame
in hasSeen() during routing, so the analyzer was doubling the crypto load
on the radio-shared main loop for no benefit.
Replace pkt_hash with a cheap FNV-1a over (type||payload): same purpose
(dedup / correlation across nodes running this FW), a fraction of the CPU.
RAM-only, no flash writes, still main-loop (not ISR) -- so this does not by
itself explain BLE link drops (those match the known SoftDevice/LoRa
coexistence instability the BLE watchdog already guards), but it removes
the one real RX-path cost the analyzer added.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two RAM-only, opt-in tables fed from the normal RX path and pulled out
over the text console (serial / BLE) for a BLE bridge + map to consume.
Both are compiled out unless the build sets a non-zero size; enabled on
SenseCap_Solar_repeater_ble (-D MAX_HEARD_NODES=48 -D RXLOG_SIZE=96,
~6 KB RAM).
nodes [offset] -- registry of heard REPEATERS and ROOM SERVERS (chat
clients are deliberately skipped: personal/mobile devices, privacy).
Per node: pubkey prefix, name, type, lat/lon, last SNR/RSSI, seconds
since heard, and the path the advert arrived by. Fed from onAdvertRecv
(adverts are signature-verified upstream). -> map dots + topology
edges + link quality.
rxlog [cursor] -- circular firehose of EVERY parsed frame heard, fed
from logRx() (synchronous, so SNR/RSSI belong to that frame). Per
record: monotonic seq (paging cursor), time, packet hash, header
(route|type), SNR/RSSI, hop path. -> live traffic / analyzer view.
Both replies are paged to stay within the ~160 B console reply cap and
carry a trailer (next cursor + totals) so the bridge can drain and detect
if it fell behind the ring. Reachable over serial, the PIN-paired BLE
console and the admin mesh CLI, same as `neighbors`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Repeater can be queried over BLE Nordic-UART (advert/neighbours/stats) without USB. Fix SoftDevice-protected TEMP peripheral access (sd_temp_get) that crashed BLE repeater telemetry, add USB-connected detection to ArduinoSerialInterface, and adjust the nRF52 ldscript/extra FS.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Backport of PR #1779 (BLE companion usable over USB while BLE disconnected), plus: track the active transport (secure-transport gating), and stop BLE advertising while a USB host is connected (docked) so the node stays quiet on 2.4 GHz; resume advertising when undocked. An active BLE link is never force-disconnected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add virtual BaseSerialInterface::isConnectionSecure() (default true). On the dual interface it is true only for MITM-paired BLE. Gate CMD_EXPORT_PRIVATE_KEY and CMD_SET_DEVICE_PIN, and hide the BLE PIN in CMD_DEVICE_QUERY, when the frame arrived over unauthenticated USB.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Before this commit, there was no way to set a different max hop count
for unscoped messages.
Now with this change, by defaul it tracks the flood.max setting, until
a user provides a flood.max.unscoped value, which tax precidence for
packets if ROUTE_TYPE_FLOOD is true.
AUTO_OFF_MILLIS is a power-save feature aimed at battery use. When the
board reports isExternalPowered() == true (USB or other DC source),
blanking the screen serves no purpose — there's nothing to conserve.
But OLEDs are vulnerable to burn-in with static content, so this
behaviour is gated behind a new build flag KEEP_DISPLAY_ON_USB. Default
is unchanged from upstream — the display blanks after AUTO_OFF_MILLIS
on USB or battery. Variants that ship with an LCD instead of an OLED
(e.g. heltec_t096) can opt in by adding -D KEEP_DISPLAY_ON_USB to
their env, gaining always-on-while-powered without exposing OLED users
to burn-in risk.
When the flag is enabled, the implementation refreshes _auto_off every
loop iteration while externally powered, so the timer naturally counts
a fresh AUTO_OFF_MILLIS window from the moment power is removed —
no instantaneous-blank-on-unplug.
Applied to all three companion_radio UI flavours (ui-new, ui-tiny,
ui-orig). Boards without an isExternalPowered() override use the
base-class default in MeshCore.h (returns false), so battery-powered
behaviour is unchanged everywhere.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Framework for upcoming variant-specific PRs that add LED feedback during boot. The hook gives users visual cues that the device is busy and
shouldn't be interacted with until startup completes.