Configure and flash
You’ll need an ESP32 board wired as described in Wiring and parts, a USB cable, and an Admin account on a running backend.
Register the scanner
Section titled “Register the scanner”Every gate gets its own credential. As an Admin, register the scanner by name:
POST /api/v1/scanner-devicesContent-Type: application/json
{ "name": "Gate-01" }The response includes the device’s id and a credential that looks like hhd1.<device-uuid>.<secret>. Copy the credential now. It’s only ever shown in this response. If you lose it, rotate it with POST /api/v1/scanner-devices/{id}/rotate-credential, which also kills the old one.
Then tell the backend which way this gate faces, IN for an entrance or OUT for an exit:
PUT /api/v1/scanner-devices/{id}/directionContent-Type: application/json
{ "direction": "IN" }Until it has a direction, every scan is refused with GATE NOT CONFIGURED. You can check a credential without scanning anything by calling GET /api/v1/device/check with it.
Put the credential in the firmware
Section titled “Put the credential in the firmware”-
Clone the firmware and copy the secrets template.
Terminal window git clone https://github.com/Hostel-Hive/hostelhive-hardware.gitcd hostelhive-hardwarecp include/secrets.example.h include/secrets.h -
Edit
include/secrets.h, which Git ignores. SetWIFI_SSIDandWIFI_PASSWORDfor the gate’s network. SetAPI_BASE_URLto the backend’shttps://address with no path. Paste the root certificate of the backend’s TLS chain intoAPI_ROOT_CAas PEM. Put thehhd1.credential inDEVICE_CREDENTIAL. If you’re not in Sri Lanka, changeGMT_OFFSET_SECtoo. -
Connect the ESP32 over USB, then build the firmware and flash it with the production profile:
Terminal window pio run -e esp32prodpio run -e esp32prod --target uploadpio device monitor --speed 115200
On boot the screen joins Wi-Fi, syncs the clock and then shows SCAN ID.
There are three build profiles. esp32prod is for real gates: HTTPS only, and no QR input from USB. esp32dev is for development. native_test runs the unit tests on your computer.
python test/run_tests.pypio test -e native_testThe first needs nothing installed. The second runs the Unity tests for QR parsing, the cooldown, and the open-or-stay-locked decision.
Looking after scanners
Section titled “Looking after scanners”GET /api/v1/scanner-devices lists them. POST /api/v1/scanner-devices/{id}/rotate-credential issues a new credential and POST /api/v1/scanner-devices/{id}/deactivate retires one. Only active Admins can do any of this, and a scanner credential only works on the two /api/v1/device/ routes.