This utility is designed to interface with a USB QR code scanner and automatically set spool IDs in AFC.
Once the service is running, the utility will listen for events from the connected USB
2D barcode scanner. If a scanned code begins with the magic spoolman prefix web+spoolman:s-,
or the scanned code is a URL Base URL\spool\show\, it will send a SET_NEXT_SPOOL_ID SPOOL_ID=#
command to AFC for the next spool to be loaded.
Here's the scanner that I'm using, but it's expected that most of the 2D barcode scanners will work with this method: https://www.amazon.com/dp/B0DYY7GLSL
- Linux system with
evtestpackage installed. - User must be a member of the
inputgroup to access input devices.
-
Clone this repository to your home directory:
cd ~ git clone https://github.com/kekiefer/afc-spool-scan.git cd afc-spool-scan -
Modify the evdev path for your scanner, if necessary
My scanner doesn't have a unique serial number, and many others will not either, so by default the scanner path is
/dev/input/by-id/usb-TMS_HIDKeyBoard_1234567890abcd-event-kbd. You should plug in your scanner, and check this location to see if you need to fix up theEVENT_DEVvariable inusb-qr-scanner-read.sh.ls -la /dev/input/by-id/ -
Install the
evtestpackage:sudo apt update sudo apt install evtest -
Add your user to the
inputgroup:sudo usermod -aG input $(whoami)You must log out and log back in for group changes to take effect. Since a user service is used to run this, this might mean a reboot.
-
Symlink the systemd user service:
Assuming
usb-qr-scanner.serviceis in the project directory:mkdir -p ~/.config/systemd/user ln -s ~/afc-spool-scan/usb-qr-scanner.service ~/.config/systemd/user/usb-qr-scanner.service -
Enable and start the systemd user service:
The service will start automatically when the system is rebooted:
systemctl --user daemon-reload systemctl --user enable usb-qr-scanner.service systemctl --user start usb-qr-scanner.service
If you want to change the Moonraker connection at runtime by scanning a QR code, use the
included generate-moonraker-qr.sh script to generate one. The QR code encodes the
target with the web+moonraker: prefix, which the scanner service recognises and uses
to update its active Moonraker scheme, host, and port.
The scanned value after the prefix can be in any of these forms:
| Format | Example | Result |
|---|---|---|
hostname |
dragonforge |
host updated, scheme and port unchanged |
hostname:port |
dragonforge:1234 |
host and port updated, scheme unchanged |
scheme://hostname |
https://dragonforge |
scheme and host updated, port unchanged |
scheme://hostname:port |
https://dragonforge:8443 |
scheme, host, and port all updated |
The defaults are scheme http, host localhost, and port 7125.
Install qrencode if you haven't already:
sudo apt install qrencode
Generate a QR code:
# Default output filename (moonraker-host.png)
./generate-moonraker-qr.sh <target>
# Custom output filename
./generate-moonraker-qr.sh <target> output.png
Examples:
./generate-moonraker-qr.sh dragonforge
./generate-moonraker-qr.sh 192.168.1.100 my-printer.png
./generate-moonraker-qr.sh dragonforge:1234
./generate-moonraker-qr.sh https://dragonforge.localdomain:8443
Scan this code just before scanning your spool to direct subsequent spool scan commands to the new target.