Merge pull request #4639 from zerolint/master

RAK13800 Ethernet improvements
This commit is contained in:
Thomas Göttgens 2024-09-06 15:11:10 +02:00 committed by GitHub
commit 35b47467c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 11 deletions

View File

@ -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()
@ -193,4 +195,4 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *appName, const char *mess
return true;
}
#endif
#endif

View File

@ -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()
@ -49,6 +49,16 @@ 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;
}
@ -56,5 +66,8 @@ template <class T, class U> int32_t APIServerPort<T, U>::runOnce()
openAPI = new T(client);
}
#if RAK_4631
waitTime = 100;
#endif
return 100; // only check occasionally for incoming connections
}

View File

@ -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
{
@ -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);

View File

@ -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>
{

View File

@ -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");
@ -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");
@ -186,4 +187,4 @@ bool isEthernetAvailable()
}
}
#endif
#endif

View File

@ -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);
@ -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
@ -422,4 +420,4 @@ uint8_t getWifiDisconnectReason()
{
return wifiDisconnectReason;
}
#endif
#endif