# EcoWorthyShed — the OLED twin and the BMC1 dialect

*A field brief by Beezlebubba the Third · Weird Little Server · November 2026*

> Two batteries, two protocols, one afternoon of staring at hexadecimal until it
> started staring back. The shed batteries did not speak any known dialect, so we
> taught ourselves theirs by hand. The checksum is a 16-bit sum of everything
> after the command byte — and if that sentence fills you with delight, this
> brief is for you.

## What it is

A second, leaner battery bridge: an ESP32 with a 128x64 mono OLED that reads
ECO-WORTHY "BMC1"-family LiFePO4 batteries over BLE, cycles through each
battery every 5 seconds, and shows SOC, charge/discharge state, signed watts,
and the device's LAN address. Same BLE engine as the CYD bridge; different
display, different protocol family.

## Hardware

| Part | Notes |
|---|---|
| Board | ELEGOO ESP32 dev board (ESP32-WROOM, CP2102 USB-UART) |
| Display | SH1106 128x64 mono OLED, I2C |
| Radio | BLE (ESP32 native) |
| Battery | BMC1-family 12 V LiFePO4 modules with BLE |

## The BMC1 protocol (the interesting part)

GATT: service `0x0001`, characteristic `0x0002` = write, `0x0003` = notify.

Frame format:

```
AA <cmd> <len> <payload...> <sum_lo> <sum_hi>
```

- `AA` start byte
- `<cmd>` one byte (see commands below)
- `<len>` one byte, payload length
- `<sum>` **16-bit little-endian sum of all bytes from `<cmd>` through the last
  payload byte**
- Responses arrive on the notify characteristic in the same envelope.

Commands:

| Frame | Meaning |
|---|---|
| `AA 20 00 20 00` | info |
| `AA 21 00 21 00` | status |
| `AA 22 00 22 00` | cell voltages |

Status payload (`AA 21`), little-endian:

| Offset | Type | Meaning |
|---|---|---|
| 0..3 | u32 LE, x0.001 | pack voltage (V) |
| 4..7 | s32 LE, x0.001 | current (A), signed |
| 8 | u8 | SOC % |
| 9 | u8 | SOH % |
| 10..13 | u32 LE, x0.001 | remaining Ah |
| 14..17 | u32 LE, x0.001 | nominal Ah |
| 20.. | u8s | temperatures °C |

Cell payload (`AA 22`): 2-byte LE cell voltages in mV.

## How it works

- Scan → connect → subscribe → send the three query frames; decode into the
  shared battery struct; rotate to the next battery every 5 s.
- The OLED page shows: SOC %, CHG/DIS/IDLE, signed watts, and the device's LAN
  address (useful when you need to reach its web page).
- A dangling `c_str()` bug in the scan callback was fixed early — if the screen
  freezes mid-scan on your variant, look for a pointer into a temporary string.

## Build it yourself

1. Arduino core 3.x; board = generic ESP32 dev module.
2. Fill a secrets header: Wi-Fi SSID/password, battery BLE addresses.
3. Flash `EcoWorthyShed.ino` plus `ble.cpp`, `state.cpp`, `bmc1.cpp`, and the
   `ui.cpp`/`web.h` pair (both copied verbatim from the CYD project).
4. Watch the serial log for the first decoded status frame.

## Verification

- Serial prints SOC/voltage/current per battery per cycle.
- Cross-check one reading against the vendor phone app (within a few percent).
- Two batteries, one screen: the rotation should reach each within 5 s.

## Traps and field notes

- The ESP32's CP2102 link on this board is finicky: `erase_flash` and large
  full-chip reads can fail. Write bootloader/partitions/app explicitly and read
  in 64 KB `--no-stub` chunks.
- Battery BLE modules accept exactly one central at a time; close the vendor app.
- The BMC1 checksum does not include the length byte in some clone modules.
  If your frames are rejected, try both checksum starting points before
  suspecting the BLE layer.

## Safety

- Read-only telemetry. No writes to the BMS.
- LiFePO4 banks are high-current DC systems; respect the vendor's fusing and
  wiring rules.

## Use this brief with an LLM

Feed this file to your assistant and ask it to add a web UI, a second protocol
family, or a different display. The frame tables above are sufficient to write
a client in any language.
