Case study · Devices · IoT
Turnstile Device Agent
I run the Raspberry Pi software that turns a membership approval into a gate pulse at venues across seven cities.
The partner platform decides who may enter, but the venue still needs a local policy for the time that platform stops answering.
- recorded approvals for entry or exit
- 90,000+
- cities in deployment records
- Seven
- delivery for every field update
- Remote
Stack: Python · Raspberry Pi · Linux · FastAPI · WebSocket · Prometheus · Grafana
From a member’s scan to the controller
A member scans the kiosk’s QR code with the partner’s app. The platform checks the membership and sends its decision over WebSocket. My Python agent on the Raspberry Pi resolves the direction, signals the turnstile controller and requests the next code.
I keep the partner protocol in an adapter. The kiosk and hardware see typed events. I can test a live exchange with a fake output, then check the electrical signal on a bench Pi. A field technician mounts the unit and checks passage in both directions.
Scroll sideways for the full diagram →
What the venue accepts during an outage
I left membership records with the partner. A local copy could go stale and would put member data on unattended hardware. The venue instead chooses to allow unchecked passage during a sustained platform interruption.
A brief disconnect gets a grace period. If it persists, the agent requests free passage, labels the offline state for staff and keeps trying to reconnect. A stable connection clears that offline request. Staff and platform requests for free passage have their own state.
What happens to overlapping grants
| At the controller | What the agent does |
|---|---|
| A second approval arrives in the same direction during a GPIO pulse | It can extend the active pulse. The log links the extension to that pulse. |
| A grant points the other way during the pulse | It logs and ignores the conflict. Queuing the grant could trigger a late pulse after the member has moved on. |
| The direction cannot be resolved | The adapter withholds the pulse. Hardware code only receives a grant with a known direction. |
Shipping a change to a working gate
I deliver a tagged release, check the candidate and verify the service after restart. If verification fails, deployment attempts recovery. I can redeploy a known-good tag. Preparing the candidate costs disk space on the Pi, and switching versions requires a restart.
Devices send heartbeats and audit events to a FastAPI collector. I use the audit trail to find the partner grant and the output decision that followed it. I work with the partner’s engineers and our field technician, review every change, including those written by coding agents, and make the release decision.
Ten hours without the platform
During a ten-hour platform interruption in September 2026, the affected turnstiles requested free passage and kept retrying. They reconnected within about a minute of my DNS change, with no deploy, restart or site visit. The incident record has the particulars.
Across two production windows the fleet recorded 90,000+ partner approvals for entry or exit. The technician checks physical passage separately. The field results explain how I matched approvals to device output.