# MideaPanel — a sky-panel for the guest-bedroom air conditioner

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

> The air conditioner is a barnyard animal in a beige coat, and for years the only
> way to speak to it was through a cloud service I do not trust and a phone app I
> do not respect. So we stole the key, learned the dialect, and built the panel.
> Here is the whole confession — cleaned of credentials, safe to feed to your own
> machine.

## What it is

A touch panel running on an ESP32-2432S028R ("CYD") that controls a Midea
window/inverter air conditioner over the **local Midea V3 protocol on TCP 6444**
— no cloud relay, no vendor app, no internet path at all. The panel shows room
and target temperature, sends ON/OFF/mode/fan/temperature commands, and polls
state every 15 seconds.

## Hardware

| Part | Notes |
|---|---|
| Board | Sunton ESP32-2432S028R "CYD" (ESP32-WROOM, 4 MB flash) |
| Panel | ST7789V 240x320 — *this* unit requires `invert=false`; many CYDs are ILI9341 and want `invert=true`. Measure, don't assume. |
| Touch | XPT2046 resistive, software SPI |
| Network | 2.4 GHz Wi-Fi on the same LAN as the AC's Wi-Fi module |

## How it works

- The AC's Wi-Fi module exposes a **single-client TCP server on port 6444**
  speaking the V3 ("8370" transport family) protocol:
  - handshake with a static local token,
  - session key derived from the handshake (AES-256-CBC, key material XORed
    from the token response),
  - encrypted command/query frames.
- The **local token + key** were obtained once through the vendor's cloud
  pairing flow during a deliberate re-pair. They are static per device, stored
  offline in a chmod-600 secrets header, and the panel never contacts the cloud.
- Control bitfields (mode, fan, setpoint, eco, toggles) are ported from the
  open `msmart` command maps; state queries return a full state object
  including indoor/outdoor temperatures.
- The module permits **one TCP session at a time**. While the phone app holds
  the session, the panel's connection is refused; the firmware backs off
  (120/240/480/600 s) instead of hammering.
- Polling: 15 s. One failed poll keeps the last state and retries in 20 s; two
  consecutive failures mark the AC OFFLINE until the next backoff window.

## Touch calibration

This family of panels ships with touch axes rotated relative to common example
code. The firmware includes a guided **4-corner self-calibration** (press each
corner when prompted) and persists the affine transform in NVS. Values that
worked on one unit:

```
x = 0.0018, 0.0871, -15.0
y = 0.0681, -0.0014, -16.3
offset_rotation = 3
```

## Build it yourself

1. Arduino core 3.x + LovyanGFX 1.2.x, board = generic ESP32 dev module.
2. Create `panel_secrets.h` (never commit it): Wi-Fi SSID/password, AC LAN
   address, token, key.
3. Flash the sketch plus `midea_proto.cpp`, `calibration.h`, and the display
   profile header.
4. First boot: run the 4-corner calibration; then verify in serial.

## Verification

- Serial boot: `handshake OK tx=1 rx=1`, then state lines every 15 s.
- On-screen: pushing the target temperature up/down is reflected on the AC
  within one poll cycle.

## Traps and field notes

- The AC module sulks for 1-3 minutes after a radio power-cycle (on many Midea
  window units: hold CONNECT+DOWN 3 s for "OF", then CONNECT+UP 3 s for "On").
  The panel's backoff rides it out — do not re-flash in a panic.
- If the vendor phone app connects, the panel is evicted. One client, always.
- Display inversion varies per panel batch. A unit that renders as
  photographic-negative needs `invert` flipped, not a new cable.

## Safety

- Purely local control; no cloud dependency once the token is minted.
- The AC's own protections (compressor minimum-off, thermostat limits) are not
  bypassed by the panel.

## Use this brief with an LLM

Feed this file to your own assistant and ask it to port the UI, extend the
command set, or write a different client (Python, Home Assistant bridge, a
second panel). It contains everything needed to speak the protocol and no
credentials — supply your own.
