Address PR review feedback from liamcottle (second round)

- Rename eth command to eth.status for consistency with other commands
- Rename generateDeviceMac to generateEthernetMac for clarity
- Refactor ethernet_handle_command to return false by default
- Allow new TCP clients to replace existing connections (repeater, room server, SerialEthernetInterface)
- Boot companion radio without Ethernet on init failure (LoRa-only recovery mode)
- Remove > prompt from ethernet CLI for consistency with serial interface
- Fix variable redeclaration compile error in SerialEthernetInterface when ETHERNET_STATIC_IP is defined
- Fix TCP socket leak when duplicate client detection fires
- Remove dead recv_queue and adv_restart_time members from SerialEthernetInterface
- Fix port numbers in docs (port 23 for repeater/room server CLI, port 5000 for companion radio)
- Clarify eth.status command is only available in repeater and room server firmware

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ryan Gregg 2026-03-11 12:43:08 -07:00
parent 3e9ceba24a
commit 61ba79966b
8 changed files with 82 additions and 94 deletions

View file

@ -160,6 +160,7 @@ void setup() {
#ifdef BLE_PIN_CODE
serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
the_mesh.startInterface(serial_interface);
#elif defined(ETHERNET_ENABLED)
Serial.print("Waiting for serial to connect...\n");
time_t timeout = millis();
@ -167,14 +168,15 @@ void setup() {
if ((millis() - timeout) < 5000) { delay(100); } else { break; }
}
Serial.println("Initializing Ethernet adapter...");
if (!serial_interface.begin()) {
Serial.println("ETH: Init failed, halting");
halt();
if (serial_interface.begin()) {
the_mesh.startInterface(serial_interface);
} else {
Serial.println("ETH: Init failed, continuing without Ethernet (mesh only)");
}
#else
serial_interface.begin(Serial);
#endif
the_mesh.startInterface(serial_interface);
#endif
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
store.begin();

View file

@ -51,7 +51,7 @@
Ethernet.init(ETHERNET_SPI_PORT, PIN_ETHERNET_SS);
uint8_t mac[6];
generateDeviceMac(mac);
generateEthernetMac(mac);
Serial.printf("ETH: MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@ -92,20 +92,20 @@
// Format ethernet status into reply buffer. Returns true if command was handled.
static bool ethernet_handle_command(const char* command, char* reply) {
if (strcmp(command, "eth") != 0) return false;
if (!ethernet_running) {
strcpy(reply, "ETH: not connected");
} else {
IPAddress ip = Ethernet.localIP();
sprintf(reply, "ETH: %u.%u.%u.%u:%d", ip[0], ip[1], ip[2], ip[3], ETHERNET_TCP_PORT);
if (strcmp(command, "eth.status") == 0) {
if (!ethernet_running) {
strcpy(reply, "ETH: not connected");
} else {
IPAddress ip = Ethernet.localIP();
sprintf(reply, "ETH: %u.%u.%u.%u:%d", ip[0], ip[1], ip[2], ip[3], ETHERNET_TCP_PORT);
}
return true;
}
return true;
return false;
}
// Check for new TCP client connections
// Check for new TCP client connections, replacing any existing connection
static void ethernet_check_client() {
if (ethernet_client && ethernet_client.connected()) return;
auto newClient = ethernet_server.available();
if (newClient) {
if (ethernet_client) ethernet_client.stop();
@ -113,7 +113,6 @@
IPAddress ip = ethernet_client.remoteIP();
Serial.printf("ETH: Client connected from %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
ethernet_client.println("MeshCore Repeater CLI");
ethernet_client.print("> ");
}
}
#endif
@ -285,7 +284,6 @@ void loop() {
if (reply[0]) {
ethernet_client.print(" -> "); ethernet_client.println(reply);
}
ethernet_client.print("> ");
ethernet_command[0] = 0;
}
}

View file

@ -44,7 +44,7 @@
Ethernet.init(ETHERNET_SPI_PORT, PIN_ETHERNET_SS);
uint8_t mac[6];
generateDeviceMac(mac);
generateEthernetMac(mac);
Serial.printf("ETH: MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@ -80,18 +80,20 @@
}
static bool ethernet_handle_command(const char* command, char* reply) {
if (strcmp(command, "eth") != 0) return false;
if (!ethernet_running) {
strcpy(reply, "ETH: not connected");
} else {
IPAddress ip = Ethernet.localIP();
sprintf(reply, "ETH: %u.%u.%u.%u:%d", ip[0], ip[1], ip[2], ip[3], ETHERNET_TCP_PORT);
if (strcmp(command, "eth.status") == 0) {
if (!ethernet_running) {
strcpy(reply, "ETH: not connected");
} else {
IPAddress ip = Ethernet.localIP();
sprintf(reply, "ETH: %u.%u.%u.%u:%d", ip[0], ip[1], ip[2], ip[3], ETHERNET_TCP_PORT);
}
return true;
}
return true;
return false;
}
// Check for new TCP client connections, replacing any existing connection
static void ethernet_check_client() {
if (ethernet_client && ethernet_client.connected()) return;
auto newClient = ethernet_server.available();
if (newClient) {
if (ethernet_client) ethernet_client.stop();
@ -99,7 +101,6 @@
IPAddress ip = ethernet_client.remoteIP();
Serial.printf("ETH: Client connected from %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
ethernet_client.println("MeshCore Room Server CLI");
ethernet_client.print("> ");
}
}
#endif
@ -255,7 +256,6 @@ void loop() {
if (reply[0]) {
ethernet_client.print(" -> "); ethernet_client.println(reply);
}
ethernet_client.print("> ");
ethernet_command[0] = 0;
}
}