ESP32 firmware that bridges a ScanAvenger SA1100 barcode scanner from BLE to MQTT and documents its GATT protocol.
Firmware for an ESP32 that bridges a ScanAvenger SA1100 barcode scanner from BLE to MQTT over WiFi, so a scan reaches a backend and its accept/reject verdict reaches the operator without a phone in the middle.
It is not a data logger. Every scan owes an answer, and that premise shapes the whole design; see docs/decisions.md.
[SA1100] --BLE--> [ESP32] --MQTT--> [backend]
| |
LED feedback <---- verdict
Hardware
Target is a XIAO ESP32-C5. Phases 1-2 were developed on an ESP32-S3 bench board and the BLE central code carried over unchanged; the differences that did matter were all board-level, not chip-level, and are noted where they bite.
The XIAO has no addressable LED of its own, so the status pixel is an external WS2812 wired to the D10 pad; see Status LED.
Also works with the NETUM C750, which is a different OEM family entirely --
a Feasycom FSC-BT825 module with its own command set -- selected as a profile
in menuconfig. Same data path, every identifier different; the details are in
docs/scanner.md.
Probably works with rebrands of the same scanner. The SA1100 is one badge on
a widely-relabelled OEM design, and the %%SpecCode configuration dialect is
shared: juitnow/juit-alacrity-setup documents 274 of the same codes for an
"Alacrity" unit, and %%SpecCode15 is Battery Level in both. NETUM scanners
stream the same CR-terminated ASCII over a notify characteristic. If you have
one of those, docs/scanner.md is likely to apply: the GATT
handles are the part worth checking first.
Install
Requirements
ESP-IDF v6.0.2 or newer.
Not a preference. On a development snapshot everything works right up to the
point where data should arrive, and then silently never does: NimBLE never
delivers a notification while connect, pair, discover, MTU and CCCD read-back
all look perfect from both ends. Check idf.py --version before debugging
anything else.
Build and flash
. ~/Projects/Esp/esp-idf-v6.0.2/export.sh
idf.py build
idf.py flash cannot be used on the C5: its USB-Serial/JTAG port drops back
into download mode or wedges the console on the resets it issues. Flash once
with esptool and a hand reset, as in docs/serial.md; after
that, updates go over the air.
Usage
Getting the scanner into BLE mode
Four barcodes, plain ASCII in Code 128, so they can be rendered on screen:
zint --barcode=20 -d '%%EnterSet'.
| Payload | Meaning |
|---|---|
%%EnterSet |
enter setup mode |
%%SpecCodeAC |
Bluetooth BLE mode |
%%SpecCode99 |
pair with receiver |
%%ExitSet |
exit setup mode |
%%SpecCodeAA returns it to HID mode. Render that one before you need it.
Status LED
A WS2812 on D10 says whether the device can answer a scan; the board's own LED says whether WiFi is up.
| Colour | Meaning |
|---|---|
| dim blue | ready: scanner attached and broker reachable |
| amber | cannot answer: scanner or broker missing |
| green flash | scan sent, an answer is expected |
| amber flash | scan held, no link, no answer coming |
| red flash | scan lost: rescan it |
| Onboard LED | Meaning |
|---|---|
| off | firmware not running |
| slow blink | WiFi down: joining, retrying, or no SSID configured |
| solid | WiFi up, station has an IP |
Anything else on the pixel is the backend's verdict. docs/led.md has the pin, colour order and reasoning.
Configuration
Credentials live in sdkconfig.defaults.local, which is gitignored and picked
up automatically. Copy sdkconfig.defaults.local.example to start:
CONFIG_NETLINK_SSID="..."
CONFIG_NETLINK_PASS="..."
CONFIG_UPLINK_URI="mqtt://broker.lan:1883"
Everything else is idf.py menuconfig -> Scanner BLE link / Network link /
Uplink. Each option carries the measurement behind its default.
Nothing else belongs in a commit: an SSID and a broker hostname together are enough to identify a site, and a BSSID is enough to geolocate one.
Topics
The device names itself from its MAC (scanbridge-a1b2c3) and owns five
topics:
| Topic | Direction | QoS | Retained |
|---|---|---|---|
scanbridge/<id>/scan |
uplink | 1 | no |
scanbridge/<id>/status |
uplink | 1 | yes (also the last will) |
scanbridge/<id>/verdict |
downlink | 1 | no |
scanbridge/<id>/config |
downlink | 1 | no |
scanbridge/<id>/health |
uplink | 0 | no |
{"seq":100,"id":"scanbridge-a1b2c3","code":"123123","uptime_ms":11840}
The reply is a rendering instruction, not a judgement:
{"seq":100,"color":"#00c800","brightness":40,"blink":1,"sustain":800}
Run only one backend at a time: every backend answers what it hears on
scanbridge/+/scan, and the device shows whichever reply landed last.
docs/mqtt.md covers the health topic, the verdict rules and
why.
Updates
Serial flashing this board needs someone standing at it holding two buttons (see docs/serial.md), which does not scale past one device on one bench. So firmware goes over the air:
./tools/scanbridge-update build/scanbridge.bin
It serves the image over HTTP from this machine, publishes the URL and its
SHA256 to scanbridge/<id>/config, and watches until the device comes back.
The request is a plain JSON command, so nothing stops you sending it by hand:
{"cmd":"ota","url":"http://desk.lan:8080/scanbridge.bin","sha256":"4c8f2b..."}
The SHA256 is checked against what landed in flash, and a new image only stays
once it has reached the broker; docs/updates.md shows a
run and explains the rollback. scanbridge/<id>/config is not authenticated: do not put this
on a floor as it stands.
How it works
Five components that do not know about each other (the BLE link, WiFi, MQTT,
OTA and the board's battery) and a main/ that only joins them. The BLE
callbacks run on the NimBLE host task, so a handler must not block or touch
flash. docs/architecture.md has the layout and the
partition table.
Development
tools/scanbridge-watch subscribes to every device at once and prints scans as they
land, with presence tracked alongside.
./tools/scanbridge-watch -H 192.0.2.10
connected to 192.0.2.10:1883, waiting for scans
00:07:21 online scanbridge-a1b2c3 vaa33ab8
00:07:39 OFFLINE scanbridge-a1b2c3 vaa33ab8
00:07:39 online scanbridge-a1b2c3 vaa33ab8
00:07:40 #100 scanbridge-a1b2c3 test
--json emits one object per line for piping. It needs only paho-mqtt, which
the shebang fetches through uv: there is nothing to install.
tools/scanbridge-verdict is a stand-in backend, so the accept/reject path and
its timing can be exercised without one. It answers every scan using the
Response Topic and Correlation Data the device nominated.
./tools/scanbridge-verdict # accept everything
./tools/scanbridge-verdict --reject-prefix BAD # reject codes starting BAD
./tools/scanbridge-verdict --delay-ms 250 # simulate a slow backend
The rejection rule is deliberately trivial. The point is the timing and the round trip, not the business logic.
The findings are kept out of this file on purpose; it should stay readable.
| docs/scanner.md | the SA1100's undocumented protocol and its quirks: useful with any rebrand of the same OEM firmware |
| docs/measurements.md | every number taken on hardware, with the method: coexistence, latency, AP selection, stacks, power |
| docs/decisions.md | why the firmware is shaped this way, including the decisions that were reversed and what reversed them |
| docs/led.md | the status pixel and the WiFi lamp |
| docs/mqtt.md | the health topic, the verdict as an LED command, and one backend at a time |
| docs/updates.md | why a bad update undoes itself |
| docs/serial.md | flashing the C5, and the S3's native USB |
| docs/architecture.md | the component layout and the partition table |
License
MIT © 2026 Shaun Lastra. See LICENSE.