Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test/nul
/test/test_settings_manager
/test/test_logger
/test/test_integration
/test/tsan_output.txt

# Logs
logs
Expand Down
43 changes: 27 additions & 16 deletions src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,23 @@ void WebServer::begin()
kRouteUpdateSettings,
[this](AsyncWebServerRequest *request, JsonVariant &json)
{
bool alreadyPending = false;
portENTER_CRITICAL(&pendingMutex);
bool alreadyPending = pendingSettingsUpdate;
if (pendingSettingsUpdate)
{
alreadyPending = true;
}
else
{
pendingSettingsDoc.clear();
JsonObject src = json.as<JsonObject>();
JsonObject dst = pendingSettingsDoc.to<JsonObject>();
for (JsonPair kv : src)
{
dst[kv.key()] = kv.value();
}
pendingSettingsUpdate = true;
}
portEXIT_CRITICAL(&pendingMutex);

if (alreadyPending)
Expand All @@ -154,17 +169,6 @@ void WebServer::begin()
return;
}

portENTER_CRITICAL(&pendingMutex);
pendingSettingsDoc.clear();
JsonObject src = json.as<JsonObject>();
JsonObject dst = pendingSettingsDoc.to<JsonObject>();
for (JsonPair kv : src)
{
dst[kv.key()] = kv.value();
}
pendingSettingsUpdate = true;
portEXIT_CRITICAL(&pendingMutex);

request->send(200, "application/json", "{\"status\":\"ok\"}");
}));

Expand Down Expand Up @@ -236,10 +240,9 @@ void WebServer::begin()
statusEvents.onConnect([this](AsyncEventSourceClient *client) {
if (statusEvents.count() > kMaxSSEClients)
{
// Over limit - the library already added the client, so we
// just won't send data and it will be cleaned up on next sweep.
logger.logf("SSE client rejected (count=%d, max=%d)",
logger.logf("SSE client rejected: closing excess client (count=%d, max=%d)",
statusEvents.count(), kMaxSSEClients);
client->close();
return;
}
client->send("connected", "init", millis(), 1000);
Expand Down Expand Up @@ -523,7 +526,15 @@ void WebServer::processPendingCommands()
if (jsonObj.containsKey("detection_grace_period_ms"))
settingsManager.setDetectionGracePeriodMs(jsonObj["detection_grace_period_ms"].as<int>());
if (jsonObj.containsKey("detection_ratio_threshold"))
settingsManager.setDetectionRatioThreshold(jsonObj["detection_ratio_threshold"].as<int>());
{
float threshold = jsonObj["detection_ratio_threshold"].as<float>();
// Accept legacy 0.0-1.0 ratio payloads as well as 0-100 percent.
if (threshold > 0.0f && threshold <= 1.0f)
{
threshold *= 100.0f;
}
settingsManager.setDetectionRatioThreshold(static_cast<int>(threshold + 0.5f));
}
if (jsonObj.containsKey("detection_hard_jam_mm"))
settingsManager.setDetectionHardJamMm(jsonObj["detection_hard_jam_mm"].as<float>());
if (jsonObj.containsKey("detection_soft_jam_time_ms"))
Expand Down