fablab-bergamo / Fab-O-matic

RFID machine access solution for a Fab Lab, based on ESP32. Uses modern C++ with Arduino framework. Hardware project is included.
https://www.fablabbergamo.it/2024/06/03/fabomatic1/
MIT License
2 stars 3 forks source link
arduino cpp20 esp32-arduino fab-o-matic fablab mqtt platformio platformio-arduino rfid-rc522

FAB-O-MATIC : RFID card access control for FabLab equipments

Build status : Build firmware images Test suite : Wokwi Documentation : Build docs with Doxygen

What is this project?

Assembly PCB
Assembly 3D PCB MODEL

Hardware components used

PCB and schematics

Firmware environment

Run a demo in the browser

image

Firmware test suite

  1. Use real hardware (esp32s3, esp32 wroverkit) connected over USB with Platform.io command
pio test --environment esp32-s3 --verbose

This is the method I am using whenever online tests fail (to narrow the run use -f test_which_failed)

  1. Use Wokwi-CLI with test images built by Platform.io. It requires a wokwi access token (free as per Jan 2024). The Github action "tests.yml" uses this mechanism.

  2. Run the BIN image generated by pio test --without-uploading --without-testing in VS Code Wokwi plugin.

Firmware configuration steps (/conf folder)

To add white-listed RFID cards, edit the tuples list whitelist. These RFID tags will be authorized when backend cannot be contacted.

  static constexpr WhiteList whitelist /* List of RFID tags whitelisted, regardless of connection */
      {
          std::make_tuple(0xAABBCCD1, FabUser::UserLevel::FABLAB_ADMIN, "ABCDEFG"),
          ...
          std::make_tuple(0xAABBCCDA, FabUser::UserLevel::FABLAB_USER, "USER1")
      };
Machine defaults:
        mqtt_server: fabpi.local
        mqtt_switch_topic: 
        machine_id: 1
        machine_name: MACHINE1
        machine_type: 1
        hostname: BOARD
Compilation settings
        MQTT_SIMULATION: 1
        RFID_SIMULATION: 1
        CORE_DEBUG_LEVEL: 4
        LANGUAGE: en-US
RFID tags:
        UID_BYTE_LEN: 4
        CACHE_LEN: 10
LCD config
        LCD ROWS: 2, COLS: 16
        SHORT_MESSAGE_DELAY: 1000ms
General settings:
        DEFAULT_AUTO_LOGOFF_DELAY: 12h
        BEEP_PERIOD: 120s
        DEFAULT_GRACE_PERIOD: 5min
        DELAY_BETWEEN_BEEPS: 30s
        MAINTENANCE_BLOCK: 1
        LONG_TAP_DURATION: 10s
Debug settings:
        ENABLE_LOGS: 1
        ENABLE_TASK_LOGS: 0
        SERIAL_SPEED_BDS: 115200
        FORCE_PORTAL: 0
        LOAD_EEPROM_DEFAULTS: 0
Buzzer settings:
        LEDC_PWM_CHANNEL: 2
        STANDARD_BEEP_DURATION: 250ms
        NB_BEEPS: 3
        BEEP_HZ: 660
Tasks settings:
        RFID_CHECK_PERIOD: 150ms
        RFID_SELFTEST_PERIOD: 60s
        MQTT_REFRESH_PERIOD: 30s
        WATCHDOG_TIMEOUT: 60s
        WATCHDOG_PERIOD: 1s
        PORTAL_CONFIG_TIMEOUT: 300s
        MQTT_ALIVE_PERIOD: 120s
MQTT settings:
        topic: machine
        response_topic: /reply
        MAX_TRIES: 2
        TIMEOUT_REPLY_SERVER: 2000ms
        PORT_NUMBER: 1883
Hardware settings:
        LED:
                Pin:20 (G:255, B:255)
                Type is neopixel:1, is rgb:0
                Neopixel config flags:82
        Mfrc522 chip:
                SPI settings: MISO: 33, MOSI: 26, SCK: 32, SDA: 27
                RESET pin:16
        LCD module:
                Parallel interface D0:2, D1:4, D2:5, D3:19
                Reset pin:15, Enable pin:18
                Backlight pin:255 (active low:0)
        Relay:
                Control pin:14 (active low:0)
        Buzzer:
                Pin:12
        Buttons:
                Factory defaults pin:21

Firmware debugging with Wokwi ESP32 emulator integrated with VSCode

This is a facultative but very helpful setup to shorten the development workflow.

Make sure ESP-IDF platform is esp32s2 (used by wokwi Platformio environment)

image

See files wokwi.toml and diagram.json

  {
    "name": "Wokwi GDB",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/.pio/build/wokwi/firmware.elf",
    "cwd": "${workspaceFolder}",
    "MIMode": "gdb",
    "miDebuggerPath": "${command:espIdf.getXtensaGdb}",
    "miDebuggerServerAddress": "localhost:3333"
  }

image

Firmware OTA procedure

wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/espota.py
./espota.py -i <board_ip> -d -r -f firmware.bin
upload_protocol = espota
upload_port = IP_ADDRESS_HERE or mDNS_NAME.local
{
  "disablePortal": false,
  "bootCount": 1,
  "ssid": "Wokwi-GUEST",
  "password": "",
  "mqtt_server": "fabpi2.local",
  "mqtt_user": "user",
  "mqtt_password": "password",
  "mqtt_switch_topic": "",
  "machine_id": "1",
  "magic_number": 80,
  "cached_cards": []
}

Firmware languages

PlatformIO environments list

Name Description Pins definition Part of releases?
esp32-s3 Release build for size statistics PINS_ESP32S3 No
hardware-base Base config, debug build on ESP32-S3, for hardware projects PINS_HARDWARE_REV0 No
hardware-rev0-it_IT Italian language for HW rev 0.x and 1.x as per hardware-base Yes
hardware-rev0-en_US English language for HW rev 0.x and 1.x as per hardware-base Yes
esp32-devboard Used by prototype with ESP32 module on breadboard PINS_ESP32 No
wokwi English version for demo and unit tests PINS_WOKWI Yes
wrover-kit-it_IT Version for testing with the official ESP-WROVER-KIT V4.1 with ESP32S3 PINS_ESP32_WROVERKIT No

Doxygen class documentation

Version history

Version Date Notable changes
none 2021 Initial version
0.1.x August 2023 Implemented MQTT communication with backend
0.1.x December 2023 Added test cases, mqtt broker simulation
0.2.x January 2024 Added over-the-air updates, WiFi portal for initial config, first deploy
0.3.x February 2024 Added factory defaults button, power grace period config from backend, PCB draft
0.4.x March 2024 1st PCB manufactured (rev0.2), FW +IP address announced over MQTT
0.5.x April 2024 Fully tested on PCB rev0.2 & rev 0.3
0.6.x April 2024 Added RFID cache for network interruptions, config portal now opens only by button push
0.7.x April 2024 Maintenance operation is displayed on LCD, JSON is now used for data persistence in Flash
0.8.x May 2024 Added localization with English & Italian language builds, sizes reports for firmware
0.9.x June 2024 Added buffering of important events when network is down. Espressif Arduino Core 3.0 testing.