From 52b86dbc3d81bd442304808c02f62fac92806512 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Wed, 18 Mar 2026 16:31:23 +0100 Subject: [PATCH] NPM 0xFF = capteur deconnecte sur page sensors et self-test Quand npm_status = 0xFF (aucune reponse du capteur), affiche "Capteur deconnecte" au lieu de lister tous les flags d'erreur. Co-Authored-By: Claude Opus 4.6 (1M context) --- html/assets/js/selftest.js | 37 +++++++++++-------- html/sensors.html | 73 +++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/html/assets/js/selftest.js b/html/assets/js/selftest.js index fe96879..52b02af 100644 --- a/html/assets/js/selftest.js +++ b/html/assets/js/selftest.js @@ -336,21 +336,27 @@ async function selfTestSequence() { addSelfTestLog(`NPM response: PM1=${npmResult.PM1}, PM2.5=${npmResult.PM25}, PM10=${npmResult.PM10}, status=${npmResult.npm_status_hex}`); // Decode npm_status flags - const status = npmResult.npm_status || 0; - const statusFlags = { - 0x01: "Sleep mode", - 0x02: "Degraded mode", - 0x04: "Not ready", - 0x08: "Heater error", - 0x10: "THP sensor error", - 0x20: "Fan error", - 0x40: "Memory error", - 0x80: "Laser error" - }; - const activeErrors = []; - Object.entries(statusFlags).forEach(([mask, label]) => { - if (status & mask) activeErrors.push(label); - }); + const status = npmResult.npm_status !== undefined ? npmResult.npm_status : 0; + + if (status === 0xFF) { + // 0xFF = no response = disconnected + updateTestStatus(sensor.id, 'Failed', 'Capteur déconnecté', 'bg-danger'); + testsFailed++; + } else { + const statusFlags = { + 0x01: "Sleep mode", + 0x02: "Degraded mode", + 0x04: "Not ready", + 0x08: "Heater error", + 0x10: "THP sensor error", + 0x20: "Fan error", + 0x40: "Memory error", + 0x80: "Laser error" + }; + const activeErrors = []; + Object.entries(statusFlags).forEach(([mask, label]) => { + if (status & mask) activeErrors.push(label); + }); if (activeErrors.length > 0) { updateTestStatus(sensor.id, 'Warning', `Status ${npmResult.npm_status_hex}: ${activeErrors.join(', ')}`, 'bg-warning'); @@ -362,6 +368,7 @@ async function selfTestSequence() { updateTestStatus(sensor.id, 'Warning', 'Incomplete data received', 'bg-warning'); testsFailed++; } + } // end else (not 0xFF) } else if (sensor.type === 'BME280') { // BME280 sensor test diff --git a/html/sensors.html b/html/sensors.html index 1d0367f..b45044f 100755 --- a/html/sensors.html +++ b/html/sensors.html @@ -155,36 +155,51 @@ // NPM status decoded if (response.npm_status !== undefined) { const status = response.npm_status; - const statusText = status === 0 ? "OK" : response.npm_status_hex; - const statusColor = status === 0 ? "green" : "orange"; - $("#data-table-body_" + port).append(` - - Status - ${statusText} - - `); - // Decode individual error bits - const statusFlags = { - 0x01: "Sleep mode", - 0x02: "Degraded mode", - 0x04: "Not ready", - 0x08: "Heater error", - 0x10: "THP sensor error", - 0x20: "Fan error", - 0x40: "Memory error", - 0x80: "Laser error" - }; - Object.entries(statusFlags).forEach(([mask, label]) => { - if (status & mask) { - $("#data-table-body_" + port).append(` - - - ⚠ ${label} - - `); - } - }); + if (status === 0xFF) { + // 0xFF = no response from sensor = disconnected + $("#data-table-body_" + port).append(` + + Status + Capteur déconnecté + + `); + } else if (status === 0) { + $("#data-table-body_" + port).append(` + + Status + OK + + `); + } else { + $("#data-table-body_" + port).append(` + + Status + ${response.npm_status_hex} + + `); + // Decode individual error bits + const statusFlags = { + 0x01: "Sleep mode", + 0x02: "Degraded mode", + 0x04: "Not ready", + 0x08: "Heater error", + 0x10: "THP sensor error", + 0x20: "Fan error", + 0x40: "Memory error", + 0x80: "Laser error" + }; + Object.entries(statusFlags).forEach(([mask, label]) => { + if (status & mask) { + $("#data-table-body_" + port).append(` + + + ⚠ ${label} + + `); + } + }); + } } }, error: function (xhr, status, error) {