Skip to content

RAK13800: allow several simultaneous Companion TCP clients 🤖🤖 - #3828

Open
1sthandy wants to merge 1 commit into
meshcore-dev:devfrom
1sthandy:feature/rak13800-multi-client
Open

1sthandy wants to merge 1 commit into
meshcore-dev:devfrom
1sthandy:feature/rak13800-multi-client

Conversation

@1sthandy

Copy link
Copy Markdown

Split out of #2679 (which bundled it with PoE support, now #3827). Addresses the same problem as #2972, which targets the pre-refactor file layout.

Problem

RAK13800EthernetInterface holds a single EthernetClient and stops the live connection whenever another client connects. With Home Assistant and the phone app both pointed at the same node, they kick each other off the one socket and reconnect in a loop.

Change

Keep up to MAX_ETH_CLIENTS (default 3; the W5100S has 4 sockets and one is the listener) connections open at once:

  • per-client connection slot and receive-parser state, with round-robin polling so one busy client cannot starve the others
  • command responses go only to the client that sent the last command; push frames (code >= 0x80, such as adverts or LoRa-RX logs) are broadcast to all clients
  • a new client is rejected only when every slot is busy, and a dropped client frees just its own slot

Framing is unchanged (< / > plus a uint16 LE length), and a single client behaves as before.

Scope

Only RAK13800EthernetInterface.{h,cpp} changes. checkRecvFrame() and writeFrame() are overridden there because routing to several clients needs per-client state that the shared single-client SerialEthernetInterface does not track; the shared base, MultiSerialInterface, EthernetInterface.h and the CH390 driver are untouched. available() / read() / write() are kept as trivial stubs only to satisfy the base class's pure-virtual contract. If you would rather have multi-client support in the shared base so CH390 benefits too, I am happy to rework it that way.

Testing

  • Builds: RAK_4631_companion_radio_ethernet, RAK_4631_repeater_ethernet.
  • Hardware (RAK10720): Home Assistant and the phone app connected to the same node at the same time and stayed connected.

This and #3827 both touch RAK13800EthernetInterface.{h,cpp}, so whichever is merged second will need a small rebase.

🤖 Generated with Claude Code

RAK13800EthernetInterface keeps a single EthernetClient and closes the
live connection whenever another client connects, so Home Assistant and
the phone app kick each other off the one socket and keep reconnecting.

Keep up to MAX_ETH_CLIENTS (default 3; the W5100S has 4 sockets, one of
which is the listener) connections open at once:

- per-client connection slot and receive-parser state, with round-robin
  polling so one busy client cannot starve the others
- command responses go only to the client that sent the last command;
  push frames (code >= 0x80, e.g. adverts or LoRa-RX logs) go to all
- a new client is rejected only when every slot is busy, and a dropped
  client frees just its own slot

The framing is unchanged ('<' / '>' + uint16 LE length), and a single
client behaves as before. checkRecvFrame()/writeFrame() are overridden in
RAK13800EthernetInterface only; the shared SerialEthernetInterface base
and the CH390 driver are untouched.

Tested on a RAK10720: Home Assistant and the phone app connected to the
same node at the same time.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant