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) <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-03-18 16:31:23 +01:00
parent 361c0d1a76
commit 52b86dbc3d
2 changed files with 66 additions and 44 deletions

View File

@@ -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}`); addSelfTestLog(`NPM response: PM1=${npmResult.PM1}, PM2.5=${npmResult.PM25}, PM10=${npmResult.PM10}, status=${npmResult.npm_status_hex}`);
// Decode npm_status flags // Decode npm_status flags
const status = npmResult.npm_status || 0; const status = npmResult.npm_status !== undefined ? npmResult.npm_status : 0;
const statusFlags = {
0x01: "Sleep mode", if (status === 0xFF) {
0x02: "Degraded mode", // 0xFF = no response = disconnected
0x04: "Not ready", updateTestStatus(sensor.id, 'Failed', 'Capteur déconnecté', 'bg-danger');
0x08: "Heater error", testsFailed++;
0x10: "THP sensor error", } else {
0x20: "Fan error", const statusFlags = {
0x40: "Memory error", 0x01: "Sleep mode",
0x80: "Laser error" 0x02: "Degraded mode",
}; 0x04: "Not ready",
const activeErrors = []; 0x08: "Heater error",
Object.entries(statusFlags).forEach(([mask, label]) => { 0x10: "THP sensor error",
if (status & mask) activeErrors.push(label); 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) { if (activeErrors.length > 0) {
updateTestStatus(sensor.id, 'Warning', `Status ${npmResult.npm_status_hex}: ${activeErrors.join(', ')}`, 'bg-warning'); 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'); updateTestStatus(sensor.id, 'Warning', 'Incomplete data received', 'bg-warning');
testsFailed++; testsFailed++;
} }
} // end else (not 0xFF)
} else if (sensor.type === 'BME280') { } else if (sensor.type === 'BME280') {
// BME280 sensor test // BME280 sensor test

View File

@@ -155,36 +155,51 @@
// NPM status decoded // NPM status decoded
if (response.npm_status !== undefined) { if (response.npm_status !== undefined) {
const status = response.npm_status; 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(`
<tr>
<td>Status</td>
<td style="color: ${statusColor}; font-weight: bold;">${statusText}</td>
</tr>
`);
// Decode individual error bits if (status === 0xFF) {
const statusFlags = { // 0xFF = no response from sensor = disconnected
0x01: "Sleep mode", $("#data-table-body_" + port).append(`
0x02: "Degraded mode", <tr>
0x04: "Not ready", <td>Status</td>
0x08: "Heater error", <td style="color: red; font-weight: bold;">Capteur déconnecté</td>
0x10: "THP sensor error", </tr>
0x20: "Fan error", `);
0x40: "Memory error", } else if (status === 0) {
0x80: "Laser error" $("#data-table-body_" + port).append(`
}; <tr>
Object.entries(statusFlags).forEach(([mask, label]) => { <td>Status</td>
if (status & mask) { <td style="color: green; font-weight: bold;">OK</td>
$("#data-table-body_" + port).append(` </tr>
<tr class="error-row"> `);
<td></td> } else {
<td style="color: red;">⚠ ${label}</td> $("#data-table-body_" + port).append(`
</tr> <tr>
`); <td>Status</td>
} <td style="color: orange; font-weight: bold;">${response.npm_status_hex}</td>
}); </tr>
`);
// 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(`
<tr class="error-row">
<td></td>
<td style="color: red;">⚠ ${label}</td>
</tr>
`);
}
});
}
} }
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {