fix: mutex FreeRTOS buffer historique, découplage LittleFS/REST
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-17
@@ -32,19 +32,22 @@ static String _buildJsonSondes() {
|
||||
static String _buildJsonHistory() {
|
||||
JsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
for (uint16_t i = 0; i < HIST_TAILLE; i++) {
|
||||
uint16_t idx = (histIdx + i) % HIST_TAILLE;
|
||||
if (historique[idx].timestamp == 0) continue;
|
||||
JsonObject pt = arr.add<JsonObject>();
|
||||
pt["ts"] = historique[idx].timestamp;
|
||||
JsonArray t = pt["t"].to<JsonArray>();
|
||||
for (uint8_t j = 0; j < NB_SONDES; j++) {
|
||||
if (isnan(historique[idx].temps[j])) {
|
||||
t.add(nullptr);
|
||||
} else {
|
||||
t.add(String(historique[idx].temps[j], 1));
|
||||
if (xSemaphoreTake(xHistMutex, pdMS_TO_TICKS(50)) == pdTRUE) {
|
||||
for (uint16_t i = 0; i < HIST_TAILLE; i++) {
|
||||
uint16_t idx = (histIdx + i) % HIST_TAILLE;
|
||||
if (historique[idx].timestamp == 0) continue;
|
||||
JsonObject pt = arr.add<JsonObject>();
|
||||
pt["ts"] = historique[idx].timestamp;
|
||||
JsonArray t = pt["t"].to<JsonArray>();
|
||||
for (uint8_t j = 0; j < NB_SONDES; j++) {
|
||||
if (isnan(historique[idx].temps[j])) {
|
||||
t.add(nullptr);
|
||||
} else {
|
||||
t.add(String(historique[idx].temps[j], 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
xSemaphoreGive(xHistMutex);
|
||||
}
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
@@ -61,11 +64,12 @@ static void _onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client,
|
||||
}
|
||||
|
||||
void web_server_init() {
|
||||
if (!LittleFS.begin()) {
|
||||
Serial.println("[FS] Erreur montage LittleFS !");
|
||||
return;
|
||||
bool fsOk = LittleFS.begin();
|
||||
if (!fsOk) {
|
||||
Serial.println("[FS] Erreur montage LittleFS — interface web indisponible, API REST active");
|
||||
} else {
|
||||
Serial.println("[FS] LittleFS monté");
|
||||
}
|
||||
Serial.println("[FS] LittleFS monté");
|
||||
|
||||
_ws.onEvent(_onWsEvent);
|
||||
_server.addHandler(&_ws);
|
||||
@@ -123,8 +127,9 @@ void web_server_init() {
|
||||
}
|
||||
);
|
||||
|
||||
// Servir index.html depuis LittleFS
|
||||
_server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
|
||||
if (fsOk) {
|
||||
_server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
|
||||
}
|
||||
|
||||
_server.begin();
|
||||
Serial.println("[HTTP] Serveur web démarré sur port 80");
|
||||
|
||||
Reference in New Issue
Block a user