mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-28 15:22:55 +00:00
Merge branch 'develop' into multi-message-Storage
This commit is contained in:
commit
e7cdc7cc29
@ -148,6 +148,8 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
|
||||
|
||||
void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
if (webServerThread)
|
||||
webServerThread->markActivity();
|
||||
|
||||
LOG_DEBUG("webAPI handleAPIv1FromRadio");
|
||||
|
||||
@ -391,6 +393,9 @@ void handleFsDeleteStatic(HTTPRequest *req, HTTPResponse *res)
|
||||
|
||||
void handleStatic(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
if (webServerThread)
|
||||
webServerThread->markActivity();
|
||||
|
||||
// Get access to the parameters
|
||||
ResourceParameters *params = req->getParams();
|
||||
|
||||
|
||||
@ -49,6 +49,12 @@ Preferences prefs;
|
||||
using namespace httpsserver;
|
||||
#include "mesh/http/ContentHandler.h"
|
||||
|
||||
static const uint32_t ACTIVE_THRESHOLD_MS = 5000;
|
||||
static const uint32_t MEDIUM_THRESHOLD_MS = 30000;
|
||||
static const int32_t ACTIVE_INTERVAL_MS = 50;
|
||||
static const int32_t MEDIUM_INTERVAL_MS = 200;
|
||||
static const int32_t IDLE_INTERVAL_MS = 1000;
|
||||
|
||||
static SSLCert *cert;
|
||||
static HTTPSServer *secureServer;
|
||||
static HTTPServer *insecureServer;
|
||||
@ -175,6 +181,32 @@ WebServerThread::WebServerThread() : concurrency::OSThread("WebServer")
|
||||
if (!config.network.wifi_enabled && !config.network.eth_enabled) {
|
||||
disable();
|
||||
}
|
||||
lastActivityTime = millis();
|
||||
}
|
||||
|
||||
void WebServerThread::markActivity()
|
||||
{
|
||||
lastActivityTime = millis();
|
||||
}
|
||||
|
||||
int32_t WebServerThread::getAdaptiveInterval()
|
||||
{
|
||||
uint32_t currentTime = millis();
|
||||
uint32_t timeSinceActivity;
|
||||
|
||||
if (currentTime >= lastActivityTime) {
|
||||
timeSinceActivity = currentTime - lastActivityTime;
|
||||
} else {
|
||||
timeSinceActivity = (UINT32_MAX - lastActivityTime) + currentTime + 1;
|
||||
}
|
||||
|
||||
if (timeSinceActivity < ACTIVE_THRESHOLD_MS) {
|
||||
return ACTIVE_INTERVAL_MS;
|
||||
} else if (timeSinceActivity < MEDIUM_THRESHOLD_MS) {
|
||||
return MEDIUM_INTERVAL_MS;
|
||||
} else {
|
||||
return IDLE_INTERVAL_MS;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t WebServerThread::runOnce()
|
||||
@ -189,8 +221,7 @@ int32_t WebServerThread::runOnce()
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// Loop every 5ms.
|
||||
return (5);
|
||||
return getAdaptiveInterval();
|
||||
}
|
||||
|
||||
void initWebServer()
|
||||
|
||||
@ -10,13 +10,17 @@ void createSSLCert();
|
||||
|
||||
class WebServerThread : private concurrency::OSThread
|
||||
{
|
||||
private:
|
||||
uint32_t lastActivityTime = 0;
|
||||
|
||||
public:
|
||||
WebServerThread();
|
||||
uint32_t requestRestart = 0;
|
||||
void markActivity();
|
||||
|
||||
protected:
|
||||
virtual int32_t runOnce() override;
|
||||
int32_t getAdaptiveInterval();
|
||||
};
|
||||
|
||||
extern WebServerThread *webServerThread;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user