A fixed UHF reader at a dock door does not tell you "pallet 4471 left the building". It tells you the same tag ID dozens of times a second, from several antennas, sometimes from pallets that are only parked nearby. Turning that into clean business events is mostly a filtering problem.
The raw read
from dataclasses import dataclass from datetime import datetime @dataclass class Read: epc: str # tag ID reader: str # e.g. "DOCK-3" antenna: int # antenna port on the reader rssi: float # signal strength, dBm ts: datetime Step 1: de-duplicate per tag and reader
Keep the first and last time a tag was seen at a reader within a short window. Everything in between is noise.
from datetime import timedelta WINDOW = timedelta(seconds=5) open_visits = {} # (epc, reader) -> [first_ts, last_ts, max_rssi] def ingest(r: Read): key = (r.epc, r.reader) v = open_visits.get(key) if v and r.ts - v[1] <= WINDOW: v[1] = r.ts v[2] = max(v[2], r.rssi) else: if v: emit_visit(key, v) open_visits[key] = [r.ts, r.ts, r.rssi] Step 2: work out direction
A single antenna cannot tell "in" from "out". Put one antenna on each side of the door and compare which one saw the tag first.
def direction(first_inside, first_outside): if first_inside and first_outside: return "OUT" if first_inside < first_outside else "IN" return "UNKNOWN" Step 3: ignore stray reads
Tags on pallets parked near the door are read constantly but never pass through. Drop visits that last too long or never reach a minimum signal strength.
MIN_RSSI = -65 MAX_DWELL = timedelta(minutes=2) def is_pass(v): first, last, max_rssi = v return max_rssi >= MIN_RSSI and (last - first) <= MAX_DWELL Step 4: map tag to asset
Only now look up the EPC in the asset register and emit a business event: ASSET_MOVED(asset_id, from_zone, to_zone, ts). Keep the mapping in a table, not in code; tags get replaced.
Lessons
- Log raw reads for a week before tuning thresholds.
- Sync reader clocks with NTP or direction logic breaks.
- An "UNKNOWN" direction is better than a wrong one.
For the hardware side (tag types, on-metal tags, reader placement), see this guide to RFID tracking devices for industrial sites.
