The Arduino nano is expected to be connected to /dev/ttyUSB0 on the host machine
docker build -t rfid-controller .
./runit.shvirtualenv -p python3 venv
source venv/bin/activate
pip3 install -r requirements.txt
pip3 install .
WA_API_KEY=$(cat rfidreader.txt) rfidreader /dev/ttyUSB0Udev is the linux subsystem that maps events to devices, when the device
appears execute the following rules. The idVendor:1a86 and idProduct are
specific to the Quelab Arduino Nano used. They would have to be changed for a
different device. use lsusb -v to discover those values for a different
device. The following rule will also create a symlink /dev/rfidreader that points
to the newly attached usb serial port.
/etc/udev/rules.d/50-embedded_devices.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", GROUP="dialout", SYMLINK+="rfidreader", MODE="0666", TAG+="systemd", ENV{SYSTEMD_WANTS}="rfidreader.service"
sudo udevadm control --reload
# monitor device insertion
udevadm monitor --environmentSystemd will allow us to create a unit file that is run whenever the
rfidreader device appears to the system. By default for some reason Journald
does not persist logs accross boots, this can be changed by modifying
Storage=auto to Storage=persistent
/etc/systemd/journald.conf
[Journal]
#Storage=auto
Storage=persistentThere is a race condition associated with systemd that when logs are set to persistent, the log directory doesn't seem to have the correct permissions. After reboot I manually set the guid to of the system.joural to systemd-journal, set the group sticky bit for the parent directory.
sudo chgrp systemd-journal system.journal
sudo chmod g+s /var/log/journal/14a650e273914d2ba256bb1a4473ebf9/Next up is the unit file for the rfidreader:
[Unit]
Description=Quelab RFID Reader
BindsTo=dev-rfidreader.device
After=dev-rfidreader.device
[Service]
Type=idle
Restart=always
RestartSec=3
User=doorctrl
EnvironmentFile=/home/doorctrl/quelab-rfid-controller/rfidreader.env
ExecStart=/usr/local/bin/rfidreader /dev/rfidreader
[Install]
WantedBy=multi-user.targetWA_API_KEY=[your API key from WildApricot HERE]sudo cp rfidreader.service /lib/systemd/system/
# if the unit file has been modified it needs to be reloaded
sudo systemctl daemon-reload
sudo systemctl enable rfidreader.service
# add doorctrl to the journal group so it can view logs
usermod -a -G systemd-journal doorctrlTo check logs of the service use journalctl:
newgrp systemd-journal
journalctl -f -u rfidreader.service