The simplest possible web interface for remote control and automation of work with experimental stands of the O-125 laboratory. It can be launched both in the cloud and on a local machine, for example Raspberry Pi. It does not have any protection during data transfer or authorization mechanisms, so it is assumed that you are running the server STRICTLY on a laboratory VPN network. Tested only on Linux.
The central element of the entire system is the redis database, which stores all the current data about the state of the experimental setup, as well as data about the current state of the backend processes.
The frontend is implemented using the Flask framework, the bootstrap library and the gunicorn wsgi server. gunicorn manages the flask server processes, which draws a web page using bootstrap primitives. The frontend is completely stateless, it simply renders the control interface and the state of the devices using data from the database. Due to this, you can run as many flask processes as you like in parallel.
The backend is implemented using the redis-queue framework. When a user clicks on a button on a web page, the javascript creates a request to the server, the server processes it and creates a task in the redis-queue. The server itself does not have any access to the hardware; it only creates tasks and waits for them to be completed. Redis-queue workers perform tasks from the queue and directly interact with the equipment. They are handled through systemd services, and can work without web-page launched.
We are using AJAX polling from user browser to server to get updates from db without manual reloading web-page. It is old method but very simple. May be in future we will migrate to web-sockets technology. All js scripts stored in flaskr/templates folder. They are very simple
- install python3, pip, venv;
- install redis link
sudo mkdir /opt/claysudo chown -R <your_user>:<your_user> /opt/clay- clone project from github to /opt/clay so it will be in /opt/clay/clay_golem
- create new venv inside /opt/clay/clay_golem and activate it
python3 -m venv venv
then usesource /opt/clay/clay_golem/venv/bin/activate - install requirements via pip -r
pip install -r requirements.txt mkdir instance
and create or copy config.py with hardware configuration to ./instance file- manually copy systemd service files for
- web-server with gunicorn wsgi
sudo cp ./deploy/clay_golem.service /etc/systemd/system/clay_golem.service - rq-scheduler
sudo cp ./deploy/clay_golem_scheduler.service /etc/systemd/system/clay_golem_scheduler.service - rq-workers (via template)
sudo cp ./deploy/[email protected] /etc/systemd/system/[email protected]
- web-server with gunicorn wsgi
- reload systemd
sudo systemctl daemon-reload - enable all needed services
sudo systemctl enable clay_golem_scheduler.servicesudo systemctl enable clay_golem.servicesudo systemctl enable [email protected]sudo systemctl enable [email protected]sudo systemctl enable [email protected]- ... enable as many workers as you need (look at config.py to check your current num of rq workers)
- allow selected app host and port in firewall if there is such
All hardware configuration, database, all app paths, network addresses stores in default flask config in same format
All console commands related to app can be run with flask click wrapper to store unified config file and app context in all operations related to app
- go to app folder, init venv
- run
flask --app flaskr init-dbto create or clean existing db (if you need to fully remove all previous state of devices from redis) - run
flask --app flaskr start-tasksto create rq-tasks corresponded to config - run
flask --app flaskr start-workers - run
flask --app flaskr start-app
- go to app folder, init venv
- run
flask --app flaskr clear-queueto remove jobs of all types from rq queue - run
flask --app flaskr stop-workersto stop all workers from systemd - run
flask --app flaskr stop-app
- manually remove systemd services
- manually remove app directory
- uninstall redis using apt