mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
refactor: share the favorite store, tilt repeats and request timing log
- setMyPosition stored a new favorite the same way in each of its three tilt branches; storeMyPosition() now does it. The plain-lift branch now emits its state even when the radio refuses the favorite, which is harmless since sendSetMy() has already put the old one back. - tiltRepeats() replaces the repeated tiltmotor ? TILT_REPEATS : repeats. - timeRequest's two timing log blocks share logRequestTime(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bea2f78cb6
commit
0b7c57a9ab
3 changed files with 31 additions and 47 deletions
24
src/Web.cpp
24
src/Web.cpp
|
|
@ -1282,6 +1282,14 @@ void Web::handleNotFound(AsyncWebServerRequest *request) {
|
|||
// long the whole exchange took. The total includes chunked bodies like
|
||||
// /controller that are built while they are sent, after the handler returns.
|
||||
// The server name must be a literal as the disconnect handler keeps it.
|
||||
// Logs how long part of a request took, when it is worth logging.
|
||||
static void logRequestTime(const char *server, AsyncWebServerRequest *request, const IPAddress &ip, const char *part, uint32_t us) {
|
||||
if(!worthLogging(us)) return;
|
||||
char what[112];
|
||||
snprintf(what, sizeof(what), "%s %s %s from %u.%u.%u.%u %s", server, request->methodToString(), request->url().c_str(),
|
||||
ip[0], ip[1], ip[2], ip[3], part);
|
||||
logElapsed(TAG, what, us);
|
||||
}
|
||||
static void timeRequest(AsyncWebServerRequest *request, ArMiddlewareNext next, const char *server) {
|
||||
ElapsedTimer timer;
|
||||
// Taken now as the client may already be gone when the disconnect runs.
|
||||
|
|
@ -1289,22 +1297,10 @@ static void timeRequest(AsyncWebServerRequest *request, ArMiddlewareNext next, c
|
|||
// Uploads set their own disconnect handler while the body arrives, before
|
||||
// this runs, and replacing it would stop the reboot after an update.
|
||||
if(!request->multipart()) {
|
||||
request->onDisconnect([request, timer, server, ip]() {
|
||||
const uint32_t us = timer.us();
|
||||
if(!worthLogging(us)) return;
|
||||
char what[112];
|
||||
snprintf(what, sizeof(what), "%s %s %s from %u.%u.%u.%u total", server, request->methodToString(), request->url().c_str(),
|
||||
ip[0], ip[1], ip[2], ip[3]);
|
||||
logElapsed(TAG, what, us);
|
||||
});
|
||||
request->onDisconnect([request, timer, server, ip]() { logRequestTime(server, request, ip, "total", timer.us()); });
|
||||
}
|
||||
next();
|
||||
const uint32_t us = timer.us();
|
||||
if(!worthLogging(us)) return;
|
||||
char what[112];
|
||||
snprintf(what, sizeof(what), "%s %s %s from %u.%u.%u.%u handler", server, request->methodToString(), request->url().c_str(),
|
||||
ip[0], ip[1], ip[2], ip[3]);
|
||||
logElapsed(TAG, what, us);
|
||||
logRequestTime(server, request, ip, "handler", timer.us());
|
||||
}
|
||||
|
||||
void Web::begin() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue