alp@vilnius: ~ up since 2019 · Vilnius Download cv.pdf

← ALP-OS

alp ~ $ work cold-chain

30,000 records over BLE in 5–6 minutes

Two BLE projects, one limit: how much data fits in a packet. In a phone app, 30,000 records now download in 5–6 minutes, every chunk CRC-checked. In tracker firmware, smaller chunks fixed the iPhone link, and I built the MTU exchange the vendor wouldn’t add.

30,000 recordsover BLE in 5–6 min, CRC-checked

BLE sends data in small packets. Both sides agree on a maximum size, the MTU, and anything bigger doesn’t get through.

I ran into this limit from two sides: a phone app that downloads logs from a cold-chain temperature recorder, and tracker firmware that iPhones couldn’t talk to.

The app: every record has to arrive

I co-developed the React Native app for a family of BLE sensors, on iOS and Android: about 140 commits, about 85 tickets and 14 releases to Google Play and TestFlight.

For the recorder’s cold-chain certification, every record has to arrive, and you have to be able to show it did. I added a CRC check on every chunk, so each row in the export says whether its chunk arrived intact. I also fixed a page-header shift, where the header sometimes arrived one slot late and the app read a record chunk as the header. Then I raised the MTU to 247 and the chunk size from 15 to 60 records.

How the app reads cold-chain records, one CRC-checked chunk at a time The read loop: the sensor stores records in pages. Each page starts with a header and holds at most 63 chunks, a firmware limit. Over a BLE link with an MTU of 247 the app reads one chunk of 60 records, computes its own CRC16 over the records, compares it with the chunk's CRC, writes Valid CRC yes or no on every CSV row, and sends next chunk. It repeats until the page ends, with leftover-record logic for the tail. The page-header shift: the next chunk command did not always refresh the characteristic, so the header arrived one slot later than the app expected and a record chunk sat in the header slot. Before the fix there was no header check, the app parsed that chunk as the header and the download stopped after 1 page. After the fix a header sanity check fails, the app re-reads the data as a record chunk, the real header comes next and all pages are read. QA download times after raising the MTU to 247 and the chunk size from 15 to 60 records, drawn to scale on an axis from 0 to 6 minutes: 6,830 records in about 1 minute, 15,510 records in about 2 minutes 26 seconds, and 30,000 records in 5 to 6 minutes. ONE PAGE ON THE SENSOR · read over BLE, MTU 247 header chunk 1 chunk 2 … chunk 63 header ≤ 63 chunks per page (firmware limit) read chunk 60 records compute CRC16 over records compare with chunk's CRC every CSV row Valid CRC Y/N send next chunk Repeat until the page ends, with leftover-record logic for the tail. THE PAGE-HEADER SHIFT · “next chunk” did not always refresh app expects chunk chunk header chunk arrived chunk chunk chunk header, +1 slot before no header check chunk parsed as the header download stopped after 1 page after header sanity check fails re-read as a record chunk real header next, all pages read QA DOWNLOAD TIMES · MTU 247, chunk 15 → 60 records · to scale 6,830 records ~1 min 15,510 records ~2 min 26 s 30,000 records 5–6 min 0 1 2 3 4 5 6 min
How the app reads cold-chain records, one CRC-checked chunk at a time

To test full-size downloads, I added a fake-record generator to the app. 30,000 records now download in 5–6 minutes.

The firmware: iPhones and 512-byte chunks

An iPhone can only reach the tracker over BLE. The tracker isn’t MFi certified, so iOS can’t use its Bluetooth Classic serial link. And our firmware sent BLE data in fixed 512 B chunks, which iOS can’t take.

In 2024 I wrote up how MTU negotiation really worked on the platform. The chip vendor’s Bluetooth layer negotiated the MTU, and our code sent fixed 512 B chunks on top of it. I set the chunk payload to 182 B, tested on iOS and Android, and released it as an experimental iOS-compatible firmware. That fixed the iPhone link.

When the vendor said no

The vendor SDK had no MTU negotiation in its GATT server layer. In 2025 I opened a support case, and they declined to add it. So I built the MTU exchange in the GATT client layer myself, for links where the tracker is the client. I tested it in the cold-chain firmware, where the tracker reads temperature recorders as a client, and updated the BLE MTU docs.

Conclusion

In the app, 30,000 records download in 5–6 minutes, and every chunk is CRC-checked. In the firmware, QA verified 182 B chunks on two tracker models.

On the firmware side, the write-up mattered more than the code. Once it was clear who negotiated the MTU and what our code did with it, the iPhone fix was small.

Tags ble apps release