|
21 | 21 | // §12 FIRESTORE SCALE HEARTBEAT & SYNC 1101– 2031 |
22 | 22 | // §13 WEBSOCKET 2032– 2058 |
23 | 23 | // §14 5 — CLOUD WORKER TASK (non-blocking Firestore on core 0) 2059– 2118 |
24 | | -// §15 5 — UNIFIED WS FRAME BUILDER 2119– 2158 |
25 | | -// §16 WEIGHT FILTER HELPERS 2159– 2173 |
26 | | -// §17 POST-SEND STATE RESET (shared by all send paths) 2174– 2192 |
27 | | -// §18 SHARED WEIGHT PUSH HANDLER (used by /api/weight and /api/push-weight) 2193– 2265 |
28 | | -// §19 WEB SERVER 2266– 2966 |
29 | | -// §20 CLOUD COMMUNICATION 2967– 3149 |
30 | | -// §21 WEIGH WORKFLOW (IDLE → SCANNING → STABLE_WAIT → SENDING) 3150– 3385 |
31 | | -// §22 mDNS 3386– 3423 |
32 | | -// §23 SCALE 3424– 3515 |
33 | | -// §24 RFID 3516– 3845 |
34 | | -// §25 OTA — Over-the-air firmware + filesystem update 3846– 4214 |
35 | | -// §26 SETUP & LOOP 4215– 4591 |
| 24 | +// §15 5 — UNIFIED WS FRAME BUILDER 2119– 2162 |
| 25 | +// §16 WEIGHT FILTER HELPERS 2163– 2177 |
| 26 | +// §17 POST-SEND STATE RESET (shared by all send paths) 2178– 2196 |
| 27 | +// §18 SHARED WEIGHT PUSH HANDLER (used by /api/weight and /api/push-weight) 2197– 2269 |
| 28 | +// §19 WEB SERVER 2270– 2970 |
| 29 | +// §20 CLOUD COMMUNICATION 2971– 3153 |
| 30 | +// §21 WEIGH WORKFLOW (IDLE → SCANNING → STABLE_WAIT → SENDING) 3154– 3389 |
| 31 | +// §22 mDNS 3390– 3427 |
| 32 | +// §23 SCALE 3428– 3519 |
| 33 | +// §24 RFID 3520– 3849 |
| 34 | +// §25 OTA — Over-the-air firmware + filesystem update 3850– 4218 |
| 35 | +// §26 SETUP & LOOP 4219– 4595 |
36 | 36 | // |
37 | 37 | // To regenerate this block: ./scripts/update_toc.sh |
38 | 38 | // ─── TOC END ─────────────────────────────────────────────── |
@@ -2132,10 +2132,14 @@ static String buildWsFrame(float weight) { |
2132 | 2132 | else if (sendPhase == "error") stcWs = "error"; |
2133 | 2133 |
|
2134 | 2134 | int cwt = (gLastContainer > 0.0f) ? (int)roundf(gLastContainer) : 0; |
2135 | | - int nwt = (cwt > 0 && roundWeight(weight) > cwt) ? roundWeight(weight) - cwt : 0; |
| 2135 | + // Clamp displayed weight to 0 when below MIN_WEIGHT_TO_SEND_G — avoids showing |
| 2136 | + // "-1g / -2g" on the web UI due to tare dead zone or HX711 drift. |
| 2137 | + // Raw value is kept internally for tare and slope calculations. |
| 2138 | + int displayW = (weight < MIN_WEIGHT_TO_SEND_G) ? 0 : roundWeight(weight); |
| 2139 | + int nwt = (cwt > 0 && displayW > cwt) ? displayW - cwt : 0; |
2136 | 2140 |
|
2137 | 2141 | StaticJsonDocument<768> doc; |
2138 | | - doc["weight"] = roundWeight(weight); |
| 2142 | + doc["weight"] = displayW; |
2139 | 2143 | doc["netWeight"] = nwt; |
2140 | 2144 | doc["containerWeight"] = cwt; |
2141 | 2145 | doc["uid"] = lastUID; |
@@ -2383,8 +2387,8 @@ void setupWebServer() { |
2383 | 2387 | // Status - uses ArduinoJson |
2384 | 2388 | server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request){ |
2385 | 2389 | StaticJsonDocument<640> doc; |
2386 | | - doc["weight"] = roundWeight(currentWeight); |
2387 | | - doc["rawWeight"] = (float)((int)(currentWeight * 100)) / 100.0f; |
| 2390 | + doc["weight"] = (currentWeight < MIN_WEIGHT_TO_SEND_G) ? 0 : roundWeight(currentWeight); |
| 2391 | + doc["rawWeight"] = (float)((int)(currentWeight * 100)) / 100.0f; // unfiltered, for debug |
2388 | 2392 | doc["uid"] = lastUID; |
2389 | 2393 | doc["uid_hex"] = lastUIDHex; |
2390 | 2394 | doc["uid2"] = lastUID2; |
|
0 commit comments