fablab-bergamo / fabomatic-backend

A RaspberryPi Zero-friendly backend, for managing FabLab machines access. This is the server-side of the Fab-O-Matic board project. Works in Python with MQTT broker + Database Engine.
https://www.fablabbergamo.it/2024/06/03/fabomatic1/
MIT License
0 stars 1 forks source link
fab-o-matic fablab mqtt python raspberry-pi sqlalchemy

Fab-O-Matic back-end

Build, test and package

What is this project?

image

Features

Backend runtime requirements

Pre-requisites for Raspberry Pi Zero

wget -qO - https://raw.githubusercontent.com/tvdsluijs/sh-python-installer/main/python.sh | sudo bash -s 3.10.9
sudo apt remove python3-apt
sudo apt install python3-apt
sudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt install mosquitto

Pre-requisites for Linux machines

sudo apt install python3-apt
sudo apt install rustc
sudo apt install mosquitto
sudo apt install dbus-user-session

Pre-requisites for firmware updates

wget https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/espota.py

Installation instructions

pip install FabOMatic
python -m FabOMatic 5

Default URL is https://HOSTNAME:23336/

See sample configuration example in doc/systemd

How to upgrade release

pip install FabOMatic --upgrade

Configuration file defaults

[database]
url = "sqlite:///machines.sqldb"
name = "fablab"

[MQTT]
broker = "127.0.0.1"
port = 1883
client_id = "backend"
topic = "machine/"        # root topic. Subtopics will be /machine/<ID> will be subscribed
reply_subtopic = "/reply"  # appended to the machine topics for replies by backend. E.g. machine/1/reply
stats_topic = "stats/"

[web]
secret_key = "some_long_hex_string_1234gs"  # Used for encryption
default_admin_email = "admin@fablag.org"    # Used for initial login

[email]
server = "smtp.google.com"
port = 587
use_tls = true
username = ""
password = ""

Developper notes

pytest -v
pip install -e . 
python ./run.py
pip install --upgrade build
pip install --upgrade twine

To update distribution

python -m build
python -m twine upload dist/*
alembic check
alembic revision --autogenerate -m "Description of change"
alembic upgrade head

Initial extract (run from src/FabOMatic folder)

pybabel extract -F babel.cfg -o messages.pot ./

Update merging the changes the translations files

pybabel update -i messages.pot -d translations

Adding a new locale

pybabel init -i messages.pot -d translations -l <locale>

Compile the changes

pybabel compile -d translations

GDPR compliance ⚖️

Members' RFID card will be tied to a physical person and therefore, you must collect written consent of this person as part of membership agreement.

Suggested GDPR agreement

What you need to do

python -m FabOMatic --purge
journalctl --vacuum-time=1y

Main revision log

Version When Release notes
0.0.18 January 2024 first revision with Alembic for database version tracking to handle graceful updates
0.1.15 February 2024 improved UI on mobile, fixed duplicated uses, added grace period definition on machine types, added system page
0.2.0 February 2024 UI translations with flask-babel (IT, EN), added boards details in system page
0.3.0 May 2024 User authorizations can be disabled by Machine type, Maintenance URL field added, System page improvements (DB reload, log files)
0.4.0 June 2024 Buffered messages sent by Fab-O-Matic boards are flagged with a clock icon.
0.5.0 June 2024 First release on PyPi. Renamed to FabOMatic. Added GDPR compliance (purge function)