Frame protocol
The TCP and UDP formats that mode 3 accepts, with header layouts, pixel formats and limits.
Mode 3 listens on one port number (default 5050) for both TCP and UDP. Set the port with MONO_PORT in idf.py menuconfig, under the Monochrome menu. All multi-byte numbers are little endian.
Pixel formats#
| Format | Value | Bytes per 720x350 frame | Pixel layout |
|---|---|---|---|
| 8 bits per pixel | 0 | 252,000 | One byte per pixel. Bit 0 is video, bit 1 is intensity. The other bits are ignored. |
| 1 bit per pixel | 1 | 31,500 | Eight pixels per byte, most significant bit first. 0 is black and 1 is normal. |
| 2 bits per pixel | 2 | 63,000 | Four pixels per byte, most significant pair first. 0 is black, 1 is normal, 2 and 3 are bright. |
Rows are packed with no padding: 720 bytes, 90 bytes or 180 bytes per row, top row first.
TCP#
The device accepts one client at a time. The client sends frames back to back. Each frame is a header followed by the payload.
| Offset | Size | Field | Value |
|---|---|---|---|
| 0 | 4 | Magic | MONO |
| 4 | 1 | Version | 1 |
| 5 | 1 | Format | 0, 1 or 2 |
| 6 | 1 | Flags | Bit 0: the payload is zlib-compressed |
| 7 | 1 | Reserved | 0 |
When bit 0 of the flags is set, a 4-byte compressed length follows the header, then that many bytes of zlib data. The data must inflate to exactly the number of bytes in the format table. The compressed length is at most 65,536 bytes. Send larger frames uncompressed.
The device shows each frame when it has fully arrived. It closes the connection after a bad header, an unknown format, a bad length or data that does not inflate to the right size.
UDP#
Each datagram carries some rows of a frame. No connection is needed, and a sender can update only some rows.
| Offset | Size | Field | Value |
|---|---|---|---|
| 0 | 2 | Magic | MU |
| 2 | 1 | Version | 1 |
| 3 | 1 | Format | 0, 1 or 2 |
| 4 | 2 | Sequence | Frame number. Packets with the same number belong to one frame. |
| 6 | 2 | First row | Row of the first row in this packet, 0 to 349 |
| 8 | 1 | Row count | Number of rows in this packet |
| 9 | 1 | Flags | Bit 0: last packet of the frame. Bit 1: the rows are zlib-compressed. |
The rows follow the 10-byte header. For a compressed packet the rows are the zlib data, which must inflate to exactly the row count times the row size. A packet carries at most 63,000 bytes of inflated rows. tools/send.py keeps each datagram under 1,400 bytes of rows so that it fits in one Wi-Fi packet.
The device ends a frame and shows it when one of these happens:
- a packet with the last-packet flag arrives
- a packet with a different sequence number arrives
- no packet arrives for 50 ms
Rows that a frame does not contain, or that were lost, keep the pixels of the frame that was on screen. A packet with a bad size or an unknown format is dropped.
One sender at a time#
A TCP client and a UDP sender share the frame buffers. While a TCP client is in the middle of a frame, the device drops UDP packets that arrive more than 5 ms later.
Measured speeds#
The device showed these rates on one 2.4 GHz network at a signal strength of -55 dBm, with the demo pattern from tools/send.py. The demo is a repeating pattern, so it compresses far better than a photo.
| Format | Protocol | Compression | Bytes per frame | Frames per second |
|---|---|---|---|---|
| 1 bit | UDP | No | 31.7 KB | 50, no packet loss |
| 2 bits | UDP | No | 62 KB | 40, about one packet in five lost |
| 2 bits | UDP | Yes | 1.8 KB | 49.7 |
| 2 bits | TCP | No | 63 KB | 22 |
| 2 bits | TCP | Yes | 1.5 KB | 50 |
| 8 bits | TCP | No | 252 KB | 7.5 |
| 8 bits | TCP | Yes | 8.4 KB | 20 to 26 |
Random noise does not compress. The sender then sends raw rows, and the device reached about 26 frames per second over TCP and 30 over UDP for 1-bit and 2-bit noise.