Repository navigation
CLI Guide
rfid-cli 2.0.0 is the host tool for firmware 1.2.0. Most commands also work
with older firmware; the places where 1.2 is required are noted below. Install
it first, see Installation. The examples use COM5 on Windows,
/dev/ttyUSB0 on Linux and /dev/cu.usbserial-0001 on macOS.
With a subcommand, rfid-cli connects, runs the command and exits. With no
subcommand, it opens an interactive shell over one connection:
rfid-cli # interactive shell
rfid-cli status # one-shot
rfid-cli --port COM5 list # explicit port
rfid-cli list-ports # show what the OS reportsGlobal options can appear before or after the subcommand:
| Option | Meaning |
|---|---|
--port <PORT> |
Serial port. Default: auto-detect. Also RFID_PORT. |
--baud <N> |
Serial speed, default 2000000. Also RFID_BAUD. |
-v, --verbose
|
Print protocol lines. The outgoing Wi-Fi password is masked. |
--no-color |
Plain output. NO_COLOR and non-TTY output also disable colour. |
-V, --version
|
Print the CLI version. |
--baud is not checked against the firmware. The default matches
SERIAL_BAUD in Config.h; if you change one side, change the other too or
the link will fail at runtime.
Exit codes: 0 success, 1 command failure, 2 usage error, 130 when a
command is interrupted or a prompt is cancelled. scan and tag-renew treat
Ctrl+C as a normal finish and exit 0.
Offline commands (convert, list-ports, import --dry-run) never open a
port. sync --dry-run still needs the device, because the diff is built from
the device's manifest.
# Users
rfid-cli list # alias: ls
rfid-cli add --uid 04AABBCCDD --name "John Smith" --valid-days 30
rfid-cli add --uid 5AF73581 --name "Hyace" # admin badge (no --valid-days)
rfid-cli add # prompts for UID and name
rfid-cli remove --uid 04AABBCCDD # alias: rm
rfid-cli remove --force # delete ALL users (backup first)
rfid-cli remove --force --no-backup
rfid-cli remove --except 04AABBCCDD,5AF73581 # keep only these UIDs
rfid-cli rename --uid 04AABBCCDD --name "J. Smith"
rfid-cli find --uid 04AABBCCDD # device-side binary search
rfid-cli find --name smith # device-side substring search
# Bulk
rfid-cli export users.json # .json, .csv or .bin by extension
rfid-cli import users.csv # JSON, CSV or .bin
rfid-cli import users.json --dry-run # validate offline
rfid-cli import users.json --clear # backup, wipe, then import
rfid-cli sync users.json # make the device match the file
rfid-cli sync users.bin --dry-run # show the diff
rfid-cli sync users.json --stats # timing breakdown
rfid-cli convert users.json users.bin # offline conversion
# Badges
rfid-cli scan # print the next card UID
rfid-cli scan --infinite # keep scanning until Ctrl+C
rfid-cli scan --timeout 60
rfid-cli tag-renew 30 --quota 10 # renew 10 tags with 30 days
rfid-cli tag-renew 0.01 --quota none # renew until Ctrl+C
# Device, network, time
rfid-cli status # database, flash use, versions, checksum
rfid-cli netstatus # Wi-Fi state, SSID, IP, signal
rfid-cli configure -w "MyWiFi" # password prompt
rfid-cli ntp-time # device clock and drift warning
rfid-cli ntp-sync
rfid-cli timezone --offset 3600 # UTC+1
rfid-cli timezone --offset 3600 --dst 3600 # UTC+1 plus DST
rfid-cli timezone --offset -18000 # UTC-5rfid-cli <command> --help lists the flags for that command.
Run rfid-cli with no subcommand. It finds the board, connects, and then
accepts the same commands and command flags as one-shot mode. Global options
are set when the shell starts, not on individual lines.
$ rfid-cli
rfid(COM5)> list
rfid(COM5)> add --uid 04AABBCCDD --name "John Smith" --valid-days 30
rfid(COM5)> find --uid 04AABBCCDD
rfid(COM5)> disconnect
rfid(disconnected)> connect COM7
rfid(COM7)> exit
-
lsandrmare aliases forlistandremove. - Shell commands:
help(or?),history,version,clear,connect <port>,disconnect,reconnect, andexit/quit. -
versionprints the CLI, firmware and protocol versions.helpgroups the commands;<command> --helpshows flags. - TAB completes commands, flags and file paths.
- History is written to
~/.rfid_cli_historywhen the shell exits cleanly. - The shell asks for confirmation on
remove --force,remove --exceptandimport --clear. It does not prompt forsyncor a singleremove --uid. One-shot commands never prompt, so scripts should use--dry-runwhere available. - Ctrl+C clears the current prompt line. During a command it asks the command to stop; a second Ctrl+C force-quits.
- After a link failure, the shell tries to reconnect once. If that fails, it stays running but disconnected.
A user record has these fields:
{
"uid": "04A1B2C3",
"name": "Alice Martin",
"registered": "2026-01-15",
"valid_days": 365
}-
uid: 4 to 10 bytes, written as 8 to 20 hex digits.:,-and spaces are accepted as separators and removed. Output is upper case. -
name: at most 48 UTF-8 bytes, not characters. Control characters and blank names are rejected. -
registered:YYYY-MM-DD.adduses the computer's local date. -
valid_days: days fromregistered. Decimals are accepted;0.01is about 14 minutes.nan, negative values and dates outside 1970-01-01 through 2149-06-05 are rejected by the CLI.
The firmware checks expiry at local midnight on registered + valid_days.
Fractional days move the boundary within the day. Without NTP sync, normal
badges fail closed with "No Time Sync".
The device timezone should match the machine that stamps the dates. If they
differ, the absolute expiry time shifts by the difference. Set it with
rfid-cli timezone.
Leave out --valid-days to create an admin badge. Admin badges never expire
and work without NTP.
On the wire, firmware 1.2 sends admin records as "registered": "" and
"valid_days": -1.0. The CLI treats those sentinels as admin and prints -
in tables. In JSON, omit valid_days or set it to null for an admin badge.
In CSV, leave the cell empty. In the binary record, reg_days is 0xFFFF and
valid_days is -1.0.
import, export, sync and convert use one loader and writer. The format
comes from the extension: .json is JSON, .bin is binary, and anything else
is CSV.
JSON is a top-level array of objects with the fields above. A missing or
null valid_days means an admin badge. A missing or null registered with
valid_days still present is an undated expiring entry: import and convert
stamp it with today's date, and sync may keep the device date as described
below.
CSV uses this header:
uid,name,registered,valid_days
04A1B2C3,Alice Martin,2026-01-15,365
12345678,Admin Garage,,Text files are read as UTF-8 (a UTF-8 BOM is fine). If that fails, they are read as Windows-1252 and a warning is printed. Excel on Windows often writes CSV in that encoding.
BIN is the device file format: a 7-byte header (RUD1, version, record
size) followed by 74-byte records with a CRC32 each. See
Serial Protocol Specification.
Bad rows are reported and skipped during import and sync. convert is
stricter: an invalid row or duplicate UID in a JSON/CSV source aborts the whole
conversion. A .bin source may contain corrupt records; they are skipped with
a warning.
rfid-cli import users.json
rfid-cli import users.bin
rfid-cli import users.json --dry-run
rfid-cli import users.json --clear
rfid-cli import users.json --clear --no-backup
rfid-cli import users.json --json-transportimport is additive. It loads the file, encodes it in the binary record
format on the host, and sends one raw import. The device does not parse JSON on
that path. A .bin file's 7-byte header is stripped before transfer; corrupt
records and trailing partial bytes are dropped, so the file is not sent
verbatim.
Before sending, the CLI compares the file's canonical db_crc32 with the
device's. If they match, there are no duplicate UIDs, and --clear is not set,
the transfer is skipped. --clear wipes the database first, so the final data
is written in two saves: one for the clear and one at import_end.
Capacity is checked before --clear wipes anything. A file that would exceed
70,000 users is refused. Duplicate UIDs are reported; the device keeps the
first occurrence.
--json-transport uses the older batch_add path, about 100 users per round
trip. It is slower and exists for old firmware and debugging.
rfid-cli export backup.bin
rfid-cli export users.csv
rfid-cli export users.json --json-transportexport chooses JSON, CSV or binary by extension. A .bin export uses the
device's binary format and can be imported back. JSON/CSV exports skip corrupt
records with a warning. Files are written to <file>.part and renamed on
success, so an interrupted export does not leave a truncated file under the
final name.
remove --force and import --clear take a backup first. A failed backup
aborts the operation; --no-backup is the explicit opt-out. remove --except
does not take a backup.
-
--backup-format askis the default and asks whether to save JSON or.bin. Without a terminal it chooses.bin. -
--backup-format jsonand--backup-format binskip the question. - Backups go to
backups/pre_<reason>_<timestamp>.<ext>under the directory where you ran the command. The reasons areremove_forceandimport_clear. The repository's.gitignoreexcludes bothbackups/locations.
sync makes the device match a file exactly. It sends only the difference:
rfid-cli sync users.json
rfid-cli sync users.bin --dry-run
rfid-cli sync users.json --stats- The CLI asks for
sync_begin(the device'sdb_crc32and user count). If the file has no undated entries and the checksums match, it stops. - Otherwise it downloads the per-user manifest and builds three lists: remove (device only), add (file only), and replace (same UID, different record CRC32). Replacements swap the whole record.
- It sends the remove list, then the add records, then the replace records in one raw transfer.
- The device applies the changes in RAM, saves once, and returns the new
db_crc32. The CLI compares it with its own and reports a mismatch instead of trusting a bareok.
Duplicate UIDs in the file are collapsed first; the last occurrence wins. The
device has no backup step here and sync can delete users. Use --dry-run
first. An empty file is refused, and a file over 70,000 entries is rejected
before anything is sent.
Undated entries. A row with valid_days but no registered keeps the date
already on the device for an existing normal user. Without that rule, a daily
sync would renew every badge. Existing admin badges have no date, so an
undated entry that matches one becomes an expiring badge dated today. Use
explicit dates when that matters. --restamp stamps every undated entry with
today.
--dry-run shows the affected UIDs, up to 20 per category. --stats prints
timings for each stage. If the transfer stalls or the final save fails, the
board reloads the flash copy and reports the failure; re-running sync is safe.
rfid-cli tag-renew 30 --quota 10 # 10 successful renewals
rfid-cli tag-renew 0.01 --quota none # until Ctrl+CThe board enters renewal mode and shows "RENEWING NFC TAG / Present Card...".
Each badge presented has registered set to today and valid_days set to the
requested value. Only badges already in the database are renewed; admin badges
are skipped.
The clock is checked per card, not when the mode starts. If NTP is not synced,
the card is refused with "NTP time not synced -- cannot date the renewal".
Firmware 1.2 includes the UID in the failure; older firmware only reports the
message. --quota counts successful renewals, not attempts. Ctrl+C exits
cleanly and returns the board to idle.
-
rfid-cli configure -w "MyWiFi"stores the credentials in NVS and tries to connect. The password is hidden only when stdin is a terminal. The credentials are saved before the connection test, so a failed attempt stays configured and is retried at boot; run the command again to replace them.-pexists, but a password on the command line will end up in shell history. - The board attempts NTP at boot if Wi-Fi connects, then resyncs every six
hours (
NTP_RESYNC_INTERVAL_MS). A failed boot connection delays the next attempt, and an import can defer a resync. -
rfid-cli timezone --offset 3600sets the GMT offset (UTC+1) and stores it in NVS.--dst SECONDSadds daylight saving. When connected, the board resyncs NTP with the new offset and rolls back if that fails. Offline, it applies and stores the offset and syncs later. The CLI warns when the offset differs from the host's.
rfid-cli ntp-time # local time, UTC and drift warning
rfid-cli ntp-sync
rfid-cli timezone --offset 7200
rfid-cli timezone --offset 3600 --dst 3600ntp-time warns when the device clock differs from the host by more than five
seconds. ntp-sync forces an immediate resync.
The database holds at most 70,000 users (MAX_USERS). It lives in PSRAM
behind a custom allocator and is kept physically sorted by UID, so lookup is a
binary search. The file on flash is users.bin.
A corrupted record is skipped when the database is loaded. A pre-1.0.1
users.json is migrated on first boot and kept as users.json.bak.
| Operation | Save strategy |
|---|---|
rename, tag renewal |
Single-record seek and write |
add |
Rewrite from the insertion point onward |
remove, clear, import, sync |
Full rewrite |
remove --except |
Full rewrite after sorting the keep list |
Full rewrites use a temporary file and compare its CRC32 before replacing
users.bin. The firmware's LittleFS does not support truncating a file in
place.
GateCore · gatecore-firmware 1.2.0 · gatecore-cli 2.0.1 · ESP32-S3 + PN532
README · Changelog · Issues · MIT License