Commit Graph
433 Commits
Author SHA1 Message Date
Florent d75a85b40f start using CommandType instead of raw values 2026-10-03 15:18:17 -04:00
fdlamotteandGitHub 990f6536f1 Merge pull request #113 from maxburto/fix/get-msg-channel-data
Wait for CHANNEL_DATA_RECV in get_msg()
2026-10-03 15:11:31 -04:00
fdlamotteandGitHub c376c7b62a Merge pull request #114 from maxburto/feat/send-channel-data
Add send_channel_data() for CMD_SEND_CHANNEL_DATA (0x3E)
2026-10-03 15:10:14 -04:00
Maxwell Burton 8b08f0feb1 Add send_channel_data() for CMD_SEND_CHANNEL_DATA (0x3E)
Sends a binary channel datagram: flood by default, or along a given path. Validates data_type (1..0xFFFF), payload length (<= 163) and channel index (one byte), like send_raw_data.
2026-10-02 18:45:04 +00:00
Maxwell BurtonandClaude Sonnet 5.5 9f22c05b0c Wait for CHANNEL_DATA_RECV in get_msg()
The companion protocol lists PACKET_CHANNEL_DATA_RECV (0x1B) as an
answer to GET_MESSAGE (0x0A). PR #88 added the CHANNEL_DATA_RECV
event and parser, but get_msg() still waited only for
CONTACT_MSG_RECV, CHANNEL_MSG_RECV, ERROR and NO_MORE_MSGS. When the
next queued message is a channel datagram, get_msg() therefore ignored
the device's answer and returned ERROR (reason "timeout") after
default_timeout, which also stops the auto-fetch loop.

Add CHANNEL_DATA_RECV to the expected events and cover it with a test
that runs a real CHANNEL_DATA_RECV frame through MessageReader and
EventDispatcher.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-02 17:03:17 +00:00
fdlamotteandGitHub e84f9a32b7 Merge pull request #112 from jpettitt/fix-connect-leak
Stop the dispatcher when connect() fails or is cancelled
2026-09-27 14:16:44 -04:00
John PettittandClaude Opus 5.5 40e0dd321e Stop the dispatcher when connect() fails or is cancelled
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewed-by: John Pettitt @jpettitt
2026-09-26 16:18:28 -07:00
fdlamotteandGitHub f4427bc316 Merge pull request #111 from johnterickson/special-carnival
Fix direction LPP values being encoded as lists
2026-09-22 13:35:40 -04:00
johntericksonandCopilot 8161c0f675 Fix direction LPP values being encoded as lists
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-22 15:29:04 +00:00
Florent b32d8203ae v2.3.14 v2.3.14 2026-09-19 18:48:31 -04:00
fdlamotteandGitHub 6d60f63873 Merge pull request #109 from kylemanna/fix-test-issues
Fix send_cmd destination handling and ADVERT_PATH test fixture
2026-09-19 18:06:28 -04:00
Kyle Manna 170f94e0bd tests: Fix ADVERT_PATH packet fixture
- Use packet type 0x16 and include the four-byte timestamp so the
  fixture exercises ADVERT_PATH parsing instead of PRIVATE_KEY handling.
- Preserve the embedded zero byte and existing path assertions.
2026-09-19 12:17:02 -07:00
Kyle Manna d48b941d56 messaging: Fix send_cmd destination type handling
- Fall back to repeater commands when a destination has no contact type.
- Keep an explicit dst_type instead of overwriting it with REPEATER.
2026-09-19 12:16:39 -07:00
Florent 7e5f2ab470 v2.3.13 v2.3.13 2026-09-19 13:46:39 -04:00
fdlamotteandGitHub 12e93fb127 Merge pull request #108 from agessaman/fix/send-msg-retry-ack
Fix send_msg_with_retry reporting delivered messages as failed
2026-09-19 13:42:25 -04:00
agessaman 9c65f60c23 Fix send_msg_with_retry reporting delivered messages as failed
send_msg_with_retry could return None for a message the recipient received and ACKed:

- The ACK subscription was registered only after send_msg returned. If the ACK was queued right behind MSG_SENT (both frames in one read, or the event loop busy for the round trip), it was dispatched with no listener.
- Each attempt waited only for its own ACK code. A late ACK for an earlier attempt, which the device still reports from its expected-ACK table, was ignored.

The ACK subscription now spans the whole call and accepts the code of any attempt sent so far. All attempts also share one timestamp—the attempt byte already makes each packet unique—so receivers can tell a retry from a new message.
2026-09-19 10:18:10 -07:00
Florent 5e38117671 v2.3.12 v2.3.12 2026-09-19 13:10:07 -04:00
Florent fc7e797e41 send_msg_with_retries: now fetches contacts before resetting path 2026-09-19 10:59:26 -04:00
Florent fa93dc66cb fix send_msg_with_retry so it gets flood status from the send result 2026-09-19 10:35:03 -04:00
Florent 825de8a5de v2.3.11 v2.3.11 2026-09-15 11:25:22 -04:00
Florent 1145c08bcf try to invert dtr and reconnect if serial connection fails 2026-09-15 08:46:28 -04:00
Florent ec0582df22 make dtr configurable and true by default (rts false by default) 2026-09-15 08:11:00 -04:00
Florent f757e2b2f6 let user specify rts state upon connect 2026-09-14 12:37:28 -04:00
Florent 6ffb875c28 v2.3.10 v2.3.10 2026-09-13 17:10:50 -04:00
fdlamotteandGitHub 1bfd8385d5 Merge pull request #102 from joeyleake/fix/58-dont-configure-root-logger
Stop configuring the root logger on import
2026-09-12 11:43:10 -04:00
fdlamotteandGitHub 10b4f74305 Merge pull request #104 from PY5HC/fix/serial-dtr-handling
Fix serial DTR handling
2026-09-12 11:36:26 -04:00
fdlamotteandGitHub 3d8a8a6c85 Merge pull request #103 from joeyleake/docs/84-document-path-hash-mode
Document set_path_hash_mode / get_path_hash_mode in README
2026-09-12 11:34:18 -04:00
fdlamotteandGitHub 23ccdecb75 Merge pull request #101 from joeyleake/fix/95-serial-fd-leak-on-timeout
Fix serial fd leak in SerialConnection.connect() on timeout
2026-09-12 11:34:00 -04:00
fdlamotteandGitHub 832bec72d3 Merge pull request #100 from joeyleake/fix/97-ble-reconnect-duplicate-notify
Fix BLE reconnect leaving stale notification registration (duplicate notifications)
2026-09-12 11:32:51 -04:00
Hipólito Luiz 9676f0f4b8 Fix serial DTR handling 2026-09-11 14:29:37 -03:00
fdlamotteandGitHub 837ac53e77 Update MeshCore URL in README 2026-09-03 11:37:05 -04:00
Joey Leake df72e95603 Document set_path_hash_mode / get_path_hash_mode in README
Both commands already existed in commands/device.py but had no entry in
the README's command reference table, so users had no way to discover
them (reported as "missing"). Add rows under Advanced Configuration
explaining that mode controls how many bytes of each hop's node ID are
stored per hop in advertised/logged paths (bytes per hop = mode + 1),
matching the plen >> 6 / hash_mode + 1 logic in reader.py and
commands/base.py.

Fixes #84
2026-08-31 13:25:01 -04:00
Joey Leake 9163efa4f3 Stop configuring the root logger on import
logging.basicConfig() at import time in __init__.py silently clobbered the
embedding application's own logging setup. Replace it with a NullHandler so
the library stays silent by default without touching global config.

Also stop MeshCore.__init__ from unconditionally forcing the "meshcore"
logger to INFO when neither debug= nor only_error= is passed - only set a
level when the caller explicitly asks for one, otherwise leave whatever the
app already configured alone.

Document the idiomatic logging setup for consumers in README.md.

Fixes #58
2026-08-31 13:18:23 -04:00
Joey Leake 42627f09c6 Fix serial fd leak in SerialConnection.connect() on timeout
Fixes #95
2026-08-31 13:04:59 -04:00
Joey Leake 585833690d Fix BLE reconnect leaving stale notification registration (Fixes #97) 2026-08-31 12:42:10 -04:00
fdlamotteandGitHub 664ba0c99e Merge pull request #99 from ErikBrown2/fix-advert-path-zero-bytes
Fix ADVERT_PATH parsing of embedded zero bytes
2026-08-30 07:50:20 -04:00
ErikBrown2andGitHub e5a82eba5b Add regression test for ADVERT_PATH zero bytes
Verify that embedded 0x00 bytes in multi-byte ADVERT_PATH hashes are preserved during parsing.
2026-08-30 13:14:51 +02:00
ErikBrown2andGitHub 35e483e312 Fix ADVERT_PATH parsing of zero bytes
Preserve valid 0x00 bytes in ADVERT_PATH data by reading the exact number of path bytes instead of stripping all zero bytes.
2026-08-30 12:45:01 +02:00
fdlamotteandGitHub af64ace4d7 Merge pull request #98 from aluminique/fix/rxlog-keyerror-message
Fix KeyError: 'message' when a duplicate of an undecryptable channel frame is parsed
2026-08-29 17:50:23 -04:00
Aluminique 85fc311652 Do not raise KeyError copying an undecryptable channels_log entry
parsePacketPayload copies message/msg_hash/sender_timestamp/attempt/txt_type from a
prior channels_log entry matched by pkt_hash. When that prior entry was logged while
the channel could not be decrypted it has none of those keys, so a later duplicate of
the same transmission raises KeyError: 'message' and aborts handle_rx for the whole
packet, dropping its RX_LOG_DATA. It triggers when a channel-table refresh lands
between two copies of a flooded channel message.

Copy with .get() so the fields are simply absent instead of raising. Adds a regression
test that reproduces the crash (fails on main, passes here).
2026-08-29 02:07:07 +01:00
Florent dd5502b968 fix issue when sending a cli cmd to room or sensor 2026-08-25 15:25:13 -04:00
Florent d2aca51296 send raw packets v2.3.9 2026-08-24 08:13:34 -04:00
Florent 7f614fe9b8 support for run_cli_command 2026-08-23 20:26:00 -04:00
Florent c487efbe18 v2.3.8 v2.3.8 2026-07-27 10:27:00 -04:00
Florent c61f94bbfe deal with set_flood_scope, now * means force_unscoped 2026-07-27 09:47:29 -04:00
fdlamotteandGitHub e1756555d6 Merge pull request #96 from agessaman/fix/anon-req-reply-path-encoding
Four fixes to anon requests and the BLE transport
2026-07-27 08:30:01 -04:00
agessaman 6eeab56779 fix(ble): bound the write, and correct two reply-path edge cases
Follow-up to review of the two preceding commits.

The write lock added in 00135bb prevented concurrent writes from dropping the
link, but bounded nothing. CommandHandler's own timeout does not cover the
write: send() awaits _sender_func() and only afterwards arms
asyncio.wait(futures, timeout=...). So a stalled write -- observed on hardware
running to minutes -- held the lock indefinitely while every other command
queued behind it, with nothing logged, no error raised and no DISCONNECTED
event. Before the lock only the stalled command hung; the others went out and
could trip the error-19 disconnect, which at least recovered. The lock turned
a bounded, self-healing failure into an unbounded silent one, and also blocked
the post-reconnect CMD_APP_START behind the dead connection's holder.

The write (lock acquisition included) is now bounded by
BLEConnection.WRITE_TIMEOUT. On expiry the link is torn down rather than the
lock merely released: the underlying CoreBluetooth write may still be in
flight, and a second write racing it re-creates the overlap the lock exists to
prevent. Tearing down hands over to the reconnect path, which is bounded and
self-healing.

The lock is now a lazily-created property, mirroring _mesh_request_lock in
commands/base.py, so an instance built without __init__ still works. The two
BLE tests previously assigned _write_lock themselves, which meant deleting the
__init__ line left them green; there is now a test that __init__ provides it.

Also in send_anon_req:

- A failed change_contact_path() no longer proceeds. The device still has the
  contact as flood, so sendAnonReq() floods the request, and the server gates
  REGIONS/OWNER/BASIC behind isRouteDirect() and drops it -- the caller then
  waits out a full path-scaled timeout for a reply that cannot arrive. It now
  returns ERROR path_reset_failed.
- encode_reply_path() clamps to the server's 64-byte reply_path buffer, which
  MyMesh.cpp memcpys into with no length check, and rejects hash mode 3 (the
  4-byte hops Packet::isValidPathLen refuses). Not a regression -- the previous
  encoder overflowed identically -- but this function is the chokepoint and its
  comment claimed to bound the read.
- The hop count saturates at 63 instead of being masked with & 63, which would
  wrap a 64-hop path to zero hops, i.e. request a zero-hop reply from a distant
  node. Not reachable from a device-sourced contact (the reader caps the field
  at 63) but silent if it ever were.
- The suggested_timeout multiplier now scales by the hops actually emitted
  rather than the contact's claimed out_path_len, which can differ once the
  encoder clamps or truncates.

Correction to 30446ed's message: the claim that mode 0 is "byte-for-byte
identical" is wrong. Differentially, over 30000 randomised contact fields
restricted to what a device can actually emit, mode 0 diverges in 1177 of
10118 cases -- every one of them a path containing a 0x00 byte, and in every
one the old encoder was the wrong one. The accurate claim is "unchanged for
mode-0 paths containing no 0x00 byte".
2026-07-26 20:25:18 -07:00
agessaman 30446ed093 fix(anon-req): encode the reply path with its hash mode and hop order
An anon request tells the server how to route its answer back. The leading
byte of that reply path packs two fields, which the server unpacks as:

    reply_path_len       = byte & 63
    reply_path_hash_size = (byte >> 6) + 1

Three defects in producing it:

1. The hash mode was never written into the top two bits, so the server always
   read a hash size of 1 whatever the contact's real mode was.
2. The path was reversed byte-wise (out_path[::-1]) rather than hop-wise. A
   return path visits the same hops in reverse order with each hop's
   multi-byte hash intact.
3. reader.py built out_path by stripping every NUL from the fixed 64-byte
   field. That trims the padding but also eats a legitimate 0x00 inside a hop
   hash, shortening the path and shifting every hop after it. It now takes
   out_path_len * hash_size bytes, as PATH_DISCOVERY_RESPONSE already did.

Worked example at hash mode 2 (3 bytes per hop), for a contact two hops away
via aabbcc then ddeeff:

    before:  lenbyte 0x02, path ffeeddccbbaa
             -> server reads 2 hops of 1 byte, replies via ['ff', 'ee']
    after:   lenbyte 0x82, path ddeeffaabbcc
             -> server reads 2 hops of 3 bytes, replies via ['ddeeff', 'aabbcc']

The old form routes the response to hops that do not exist, so it is dropped
and the request times out.

At hash mode 0 both encodings are byte-identical -- the mode contributes
nothing to the high bits and byte-wise reversal equals hop-wise reversal for
single-byte hops -- which is why this stayed latent: mode 0 is the default.
Confirmed by the mode-0 and zero-hop tests passing unchanged against the old
code while the mode-1/mode-2 tests fail.

Scope: only anon requests routed direct to a contact with a known multi-hop
path. Flood requests are unaffected (the server answers via createPathReturn
and ignores the supplied reply path), as is login (handleLoginReq never sets
reply_path_len, so its reply always goes out flood). The neighbors zero-hop
probe is unaffected: length 0 makes hash size irrelevant.

Encoding is extracted into encode_reply_path() so it can be tested directly.
Verified on hardware only for the zero-hop case, which still works; the
multi-hop paths are covered by unit tests, as the test radio has no multi-hop
contacts to exercise on air.
2026-07-26 19:38:33 -07:00
agessaman 00135bbb95 fix(ble): serialise writes to the RX characteristic
Two overlapping write_gatt_char() calls on the same characteristic drop the
BLE link outright. Observed on macOS/CoreBluetooth as "BLE write failed: 19",
after which the connection is gone and the pending command never completes.

Nothing above the transport guaranteed callers were sequential: schedulers,
health checks, periodic status queries and user commands all issue commands
independently, so any unlucky overlap could take the radio down. The existing
_mesh_request_lock only guards a few binary-request helpers, not the transport.

Reproduced on a companion radio over BLE by issuing send_device_query() and
send_node_discover_req() concurrently:

  before:  BLE write failed: 19, connected=False, command hung >45s
  after:   both complete in 0.12s, connected=True

Issued sequentially the same two commands take 0.09s each and are fine, so it
is specifically the overlap. Ruled out as causes beforehand: notification load
(three discovers under a 91-packet firehose kept writes at 0.06-0.17s with the
link stable) and the discover command itself.

The lock is created lazily so it binds to the running loop, and is released on
the failure path so one failed write cannot wedge every later command.
2026-07-26 19:24:03 -07:00
agessaman 4ebde385dd fix(anon-req): allow requests to destinations that are not contacts
send_anon_req() refused to send whenever the destination pubkey was absent
from the client-side contact cache, returning ERROR contact_not_found.

The contact is consulted for one thing only: building the reply-path bytes
appended to the request. The companion firmware needs no contact of its own --
since FIRMWARE_VER_CODE 13 its CMD_SEND_ANON_REQ handler synthesises a
transient anon contact for an unknown pubkey with out_path_len = 0 (zero-hop
direct). Those entries live in a reserved slot ring, are hidden from
CMD_GET_CONTACTS and are never persisted, so nothing is polluted by them.

The client-side refusal therefore blocked a case the device supports, such as
asking a freshly discovered neighbour for its regions before it has ever been
added as a contact. Fall back to a zero-hop reply path instead.

Two smaller fixes in the same function:

- out_path_len is now read once into a local rather than re-read from the
  contact dict after the await. That dict is a live reference other commands
  mutate in place (send_msg_with_retry's flood fallback, reset_path); if it
  flipped to -1 mid-send the suggested_timeout multiplier became 4000 * 0 = 0,
  registering the binary request with a zero timeout so the response was
  dropped the moment it arrived.
- The value is clamped at 0. update_contact() normally reflects the change
  back onto the dict, but if it fails the dict stays -1 and the unsigned
  to_bytes raises OverflowError -- which skipped the reset_path at the end of
  the method and left the contact pinned to zero-hop on the device.

Verified against a companion radio on fw ver 13: without the change all five
discovered repeaters were refused client-side in 0.0s with no RF sent; with it
all three answered with their region scopes in ~1.1s.

test_send_anon_req_contact_not_found is replaced -- it codified the removed
limitation -- but its original regression (a TypeError on the NoneType
subscript) stays covered.
2026-07-26 19:23:32 -07:00