document batching updates and restore bat_v in batches

This commit is contained in:
2026-02-01 20:59:45 +01:00
parent a0080b249d
commit 50436cd0bb
3 changed files with 27 additions and 11 deletions

View File

@@ -59,7 +59,7 @@ void sender_loop() {
read_battery(data); // VBAT + SoC
if (time_to_send_batch()) {
json = meterBatchToJson(samples, batch_id);
json = meterBatchToJson(samples, batch_id); // bat_v per batch, t_first/t_last included
compressed = compressBuffer(json);
lora_send(packet(MeterBatch, compressed));
}
@@ -92,7 +92,7 @@ bool lora_send(const LoraPacket &pkt); // add header + CRC16 and transmit
- Web UI:
- AP mode: status + WiFi/MQTT config.
- STA mode: status + per-sender pages.
- OLED cycles through receiver status and per-sender pages.
- OLED cycles through receiver status and per-sender pages (receiver OLED never sleeps).
**Receiver loop (pseudo-code)**:
```cpp
@@ -106,7 +106,7 @@ void receiver_loop() {
}
} else if (pkt.type == MeterBatch) {
json = reassemble_and_decompress_batch(pkt);
for (sample in jsonToMeterBatch(json)) {
for (sample in jsonToMeterBatch(json)) { // uses t_first/t_last for jittered timestamps
update_sender_status(sample);
mqtt_publish_state(sample);
}
@@ -176,7 +176,7 @@ Packet layout:
LoRa radio settings:
- Frequency: **433 MHz** or **868 MHz** (set by build env via `LORA_FREQUENCY_HZ`)
- SF12, BW 125 kHz, CR 4/5, CRC on, Sync Word 0x34
- SF10, BW 125 kHz, CR 4/5, CRC on, Sync Word 0x34
## Data Format
JSON payload (sender + MQTT):
@@ -203,6 +203,8 @@ MeterBatch JSON (compressed over LoRa) uses per-field arrays with integer units
"sender": "s01",
"batch_id": 1842,
"t0": 1738288000,
"t_first": 1738288000,
"t_last": 1738288030,
"dt_s": 1,
"n": 3,
"energy_wh": [123456700, 123456701, 123456701],
@@ -210,6 +212,7 @@ MeterBatch JSON (compressed over LoRa) uses per-field arrays with integer units
"p1_w": [480, 490, 500],
"p2_w": [450, 450, 450],
"p3_w": [0, 0, 0],
"bat_v": 3.92,
"meta": {
"rssi": -92,
"snr": 7.5,
@@ -221,6 +224,7 @@ MeterBatch JSON (compressed over LoRa) uses per-field arrays with integer units
Notes:
- `sender` maps to `EXPECTED_SENDER_IDS` order (`s01` = first sender).
- `meta` is injected by the receiver after batch reassembly.
- `bat_v` is a single batch-level value (percent is calculated locally).
## Device IDs
- Derived from WiFi STA MAC.
@@ -236,9 +240,7 @@ inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { 0xF19C };
## OLED Behavior
- Sender: OLED stays **ON for 10 seconds** on each wake, then powers down for sleep.
- Receiver: OLED follows the 10-minute auto-off behavior:
- GPIO14 HIGH: OLED forced ON.
- GPIO14 LOW: auto-off after 10 minutes.
- Receiver: OLED is always on (no auto-off).
- Pages rotate every 4s.
## Power & Battery
@@ -283,6 +285,10 @@ Key timing settings in `include/config.h`:
- `METER_SEND_INTERVAL_MS`
- `BATCH_ACK_TIMEOUT_MS`
- `BATCH_MAX_RETRIES`
- `BATCH_QUEUE_DEPTH`
- `BATCH_RETRY_POLICY` (keep or drop on retry exhaustion)
- `SERIAL_DEBUG_MODE` / `SERIAL_DEBUG_DUMP_JSON`
- `LORA_SEND_BYPASS` (debug only)
## Limits & Known Constraints
- **Compression**: uses lightweight RLE (good for JSON but not optimal).