Skip to content

Commit

Permalink
RAK13800 Ethernet improvements
Browse files Browse the repository at this point in the history
Fixes (#3618) by allowing more time for slower requests.
Resolve Syslog not maintaining client causing issues on RAK13800.
Resolve Ethernet static IP setting subnet as gateway IP.
Reduce comment and log message ambiguity around API.
Remove duplicate #if !MESHTASTIC_EXCLUDE_WEBSERVER block.
  • Loading branch information
zerolint committed Sep 6, 2024
1 parent 7c6454f commit 8f10a6e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/DebugConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ Syslog &Syslog::logMask(uint8_t priMask)

void Syslog::enable()
{
this->_client->begin(this->_port);
this->_enabled = true;
}

void Syslog::disable()
{
this->_enabled = false;
this->_client->stop();
}

bool Syslog::isEnabled()
Expand Down Expand Up @@ -193,4 +195,4 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *appName, const char *mess
return true;
}

#endif
#endif
15 changes: 14 additions & 1 deletion src/mesh/api/ServerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
template <typename T>
ServerAPI<T>::ServerAPI(T &_client) : StreamAPI(&client), concurrency::OSThread("ServerAPI"), client(_client)
{
LOG_INFO("Incoming wifi connection\n");
LOG_INFO("Incoming API connection\n");
}

template <typename T> ServerAPI<T>::~ServerAPI()
Expand Down Expand Up @@ -49,12 +49,25 @@ template <class T, class U> int32_t APIServerPort<T, U>::runOnce()
if (client) {
// Close any previous connection (see FIXME in header file)
if (openAPI) {
#if RAK_4631
// RAK13800 Ethernet requests periodically take more time
// This backoff addresses most cases keeping max wait < 1s
// Reconnections are delayed by full wait time
if (waitTime < 400) {
waitTime *= 2;
LOG_INFO("Previous TCP connection still open, trying again in %dms\n", waitTime);
return waitTime;
}
#endif
LOG_INFO("Force closing previous TCP connection\n");
delete openAPI;
}

openAPI = new T(client);
}

#if RAK_4631
waitTime = 100;
#endif
return 100; // only check occasionally for incoming connections
}
6 changes: 5 additions & 1 deletion src/mesh/api/ServerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <class T> class ServerAPI : public StreamAPI, private concurrency::OSTh
};

/**
* Listens for incoming connections and does accepts and creates instances of WiFiServerAPI as needed
* Listens for incoming connections and does accepts and creates instances of ServerAPI as needed
*/
template <class T, class U> class APIServerPort : public U, private concurrency::OSThread
{
Expand All @@ -41,6 +41,10 @@ template <class T, class U> class APIServerPort : public U, private concurrency:
* delegate to the worker. Once coroutines are implemented we can relax this restriction.
*/
T *openAPI = NULL;
#if RAK_4631
// Track wait time for RAK13800 Ethernet requests
int32_t waitTime = 100;
#endif

public:
explicit APIServerPort(int port);
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/api/ethServerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ethServerAPI : public ServerAPI<EthernetClient>
};

/**
* Listens for incoming connections and does accepts and creates instances of WiFiServerAPI as needed
* Listens for incoming connections and does accepts and creates instances of EthernetServerAPI as needed
*/
class ethServerPort : public APIServerPort<ethServerAPI, EthernetServer>
{
Expand Down
7 changes: 4 additions & 3 deletions src/mesh/eth/ethClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int32_t reconnectETH()
Ethernet.maintain();
if (!ethStartupComplete) {
// Start web server
LOG_INFO("... Starting network services\n");
LOG_INFO("Starting Ethernet network services\n");

#ifndef DISABLE_NTP
LOG_INFO("Starting NTP time client\n");
Expand Down Expand Up @@ -131,7 +131,8 @@ bool initEthernet()
status = Ethernet.begin(mac);
} else if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_STATIC) {
LOG_INFO("starting Ethernet Static\n");
Ethernet.begin(mac, config.network.ipv4_config.ip, config.network.ipv4_config.dns, config.network.ipv4_config.subnet);
Ethernet.begin(mac, config.network.ipv4_config.ip, config.network.ipv4_config.dns, config.network.ipv4_config.gateway,
config.network.ipv4_config.subnet);
status = 1;
} else {
LOG_INFO("Ethernet Disabled\n");
Expand Down Expand Up @@ -186,4 +187,4 @@ bool isEthernetAvailable()
}
}

#endif
#endif
6 changes: 2 additions & 4 deletions src/mesh/wifi/WiFiAPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
#include <WiFiUdp.h>
#ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_WEBSERVER
#if !MESHTASTIC_EXCLUDE_WEBSERVER
#include "mesh/http/WebServer.h"
#endif
#endif
#include <ESPmDNS.h>
#include <esp_wifi.h>
static void WiFiEvent(WiFiEvent_t event);
Expand Down Expand Up @@ -58,7 +56,7 @@ static void onNetworkConnected()
{
if (!APStartupComplete) {
// Start web server
LOG_INFO("Starting network services\n");
LOG_INFO("Starting WiFi network services\n");

#ifdef ARCH_ESP32
// start mdns
Expand Down Expand Up @@ -422,4 +420,4 @@ uint8_t getWifiDisconnectReason()
{
return wifiDisconnectReason;
}
#endif
#endif

0 comments on commit 8f10a6e

Please sign in to comment.