Skip to content

shipped · · 7 min

A fifth protocol in one site visit: an attendance terminal the connector had never seen

An office had an attendance terminal that was none of the four brands the connector reads. It answered on port 5005, the office PC was paired, and no punch arrived. By evening the whole log had been read, punches came in every minute, and a signed release was out. The network picture, the five things that were wrong, and what the people setting it up see now.

The connector is a small Go program on an ordinary office PC. It reads biometric attendance terminals on the office network and sends every punch to an HR and attendance platform in the cloud. It spoke four brands. Then an office installed a fifth.

The terminal was set up, the office PC was paired, and the platform showed the machine as "never connected". Support had saved it as the wrong brand. When the brand was fixed, it still read nothing. When the address was fixed, the terminal answered and then refused every download with "code 3".

I spent a day on site with the office's network and a laptop. By the evening the connector had read the terminal's whole log, about 16,000 records, using only read requests; punches arrived every minute; ten days of history were in with no duplicates; and a signed release with the fix was on the public download page.

This post is the overview: what the connector is, what the network looked like, and the five things that were wrong. The series after it goes deep on each part:

  1. A fifth protocol in one site visit (this post)
  2. The whole day: from a Check button to live punches, in order
  3. How the connector reads six kinds of terminal
  4. Two bytes to the right: decoding an attendance terminal on site
  5. When your simulator agrees with your bugs
  6. Assumptions one terminal made: an audit for the next one
  7. Setup screens that tell the truth
  8. Shipping a signed connector release in an afternoon
  9. Reading a clock you cannot touch
  10. The connector field handbook: every command, and why
  11. The connector command sheet: every command, ready to copy

What the connector is

The cloud cannot reach an attendance terminal. It sits on an office network behind one router, often two. So a program on a PC that is already in the office fetches the punches: it reads each terminal over the LAN, keeps the punches on disk, and sends them out over HTTPS. It opens nothing towards the internet. The architecture post has the whole design; the parts that matter here are three:

  • A reader per protocol. Every brand sits behind one small Go interface: is it there, give me punches since a time, give me the people. The readers post covers the four that existed.
  • A machine list from the platform. The PC asks the platform which terminals it should read, at which address and port, every few minutes.
  • A machine link. For terminals stuck on a factory address in another range, the PC can add a second address of its own on a small private range and reach them there. Reaching a machine you cannot route to explains why. It is the right tool for that case and it was the wrong one here.

The network on the day

The office was one flat LAN. The PC and the terminal were both on it. The terminal listened on TCP port 5005, its factory setting, and had no communication password.

figure 1 · where the office PC dialled
office network · 192.168.1.0/24attendance terminal192.168.1.50 · TCP 5005machine link /2810.20.30.2 · nobodyoffice PCconnector192.168.1.20✕ i/o timeoutrouterthe platformHTTPS 443outbound only

Saved link address: the PC dials 10.20.30.2:5005 every minute. Nothing lives there, so every read ends in a timeout, and the card says the PC is online but the machine is not.

The terminal only ever lived on the office LAN. The setup flow had also saved a 'machine link' address for it, on a small private range the PC creates for terminals stuck on factory addresses. A terminal that never joined that range cannot answer there, and the PC tried the link address first.

Two things were wrong before the protocol came into it:

  • The terminal had been saved as the wrong brand. The platform knew four brands, so the first setup picked the nearest one. That brand reads on a different port with a different protocol, and nothing on this terminal spoke it.
  • The PC dialled a link address. Setup for that brand had also created a machine link: a /28 on the PC and an address for the terminal inside it. The terminal never moved there. The PC kept trying it first, every minute, and every read ended in a timeout.

Fixing the address by hand got the PC talking to the terminal. That is where the real problem started.

Five things that were wrong

WhatWhat it looked likeWhat fixed itWhere
The download request had its fields two bytes earlyEvery read refused with "code 3", or accepted with zero bytesRead-only probing on site; the public write-up's layoutPart 4
This model stores 20-byte records, not 12, and packs the year differentlyWould have read garbled punches dated in the year 505Three long runs in the log and one test punchPart 4
The simulator agreed with our guessesTests green, terminal refusingRebuild the simulator from captured bytesPart 5
A slow-retry rule hid the fixThe new version looked broken for five minutesRetry at once after an update or an address changePart 6
Getting the fix onto one PC fast, and onto every PC properlyPeople waiting on siteA signed release, and a same-code install over the LANPart 8

And one that was not wrong yet: the terminal's clock. Nobody could set it without standing in front of it, and the protocol's command for setting it is not public. Part 9 reads it from the outside instead.

Three rules that held all day

  • Read requests only. Every byte sent to the terminal was one of three requests that only read: hello, count, give me a block. The probe programs refused to send anything else. Some terminals in this family clear their log on the wrong command, and this one held about a year of the office's attendance.
  • No guessing at unknown commands. When the download failed I varied the arguments of a known read. I did not try new command bytes. When a fix needed a command nobody had documented, setting the clock, it waited.
  • Every fix leaves one test, and the test is checked by taking the fix out. If the test still passes with the fix removed, it is not a test. Part 5 is about how that rule held and still was not enough.

What the people setting it up see now

The protocol fix made the terminal readable. The day also showed every place the setup screens had made it hard. Those changed too:

  • One screen to add a terminal the office PC found. The PC already knows its address, port and network ID. HR types a name and picks a branch.
  • No serial number required. This terminal cannot send its serial over the network, so the platform knows it by its network ID instead, and two such terminals on one PC cannot be mixed up.
  • No phantom link address for this kind of terminal, ever.
  • Change address sits first in the machine's menu and opens in the side pane, with the same address check as adding a machine.
  • The status says what is happening. "Reading it for the first time", "the machine answers but won't hand over its punches", or "nothing answers at this address", in place of a bare "never connected".
  • "Test the connection" says what the PC last saw from the terminal, not only that the PC is online. On the day it said the PC was reading the machine while the machine had never been read.
  • A device number per terminal, so a second terminal set to device 2 on the same PC works.

The numbers

Records in the terminal's logabout 16,000
Time to read all of them over the LANabout 20 seconds
Requests sent that could change the terminal0
Wait from installing the fix to the first punch readabout a minute, after the retry fix
History brought in afterwardsten days, no punch stored twice
New interactive figures in this series10

The rest of the series is the detail. If you only read one, read part 4: it is the protocol work, byte by byte.

Working through something like this? I help teams ship AI and cloud systems that hold up, and cost what they should.