Backend server logo: Simplified representation of a server.

Realtimeplot Backend

This repository contains the source code for the Realtimeplot project implemented for the Fritz Haber Institute. This server software can be used together with the Realtimeplot Frontend.

GitHub issues GitHub license


Table of contents


How to run the backend server

This documentation assumes a GNU+Linux or macOS as host system. Individual commands may differ on Windows hosts.

Create and activate virtual development environment (GNU+Linux / macOS)

A current installation of Python 3.9 (GPL-compatible license) is required!

python3 -m venv venv
. venv/bin/activate

Install requirements

pip install Flask flask-sqlalchemy python-dotenv Flask-JWT bleach flask-cors arvpyf paho-mqtt

Configuration via .env file

Create a .env file in the root directory of this repository!

# General
SECRET_KEY=your_secret_key
FLASK_ENV=development # development or production
FLASK_APP=wsgi.py
FLASK_RUN_HOST=0.0.0.0

# SQLAlchemy
SQLALCHEMY_DATABASE_URI=sqlite:///../test.db  # path to database

# Auth
DEFAULT_ADMIN_NAME=admin_login_name
DEFAULT_ADMIN_PASSWORD=admin_login_password
PASSWORD_SALT=password_salt
ACCESS_TOKEN_VALIDITY_TIME=120 # in minutes

# Archive
ARCHIVER_URL=archiver_url
ARCHIVER_TIMEZONE=Europe/Berlin
DEFAULT_ARCHIVER_TIME_PERIOD=7

# MQTT
MQTT_SERVER_URL=mqtt_server_url
MQTT_CHANNEL_PREFIX=mqtt_channel_prefix

# THRESHOLD ALARMS
EMAIL_MQTT_CHANNEL=email_mqtt_channel
THRESHOLD_UNIT=mm

Replace the values ​​(after the = symbol) with your own values!

Start the server

flask run

Alternatively, python wsgi.py can also be used during development.

The server should be accessible at http://127.0.0.1:5000/. However, the configured URL (host + port) is also printed to the command line.

During the first flask run, the server will create an admin user with the user_id 0". Username (login_name) and password correspond to the values of DEFAULT_ADMIN_NAME and DEFAULT_ADMIN_PASSWORD defined in the .env file.

Endpoints documentation

Users and authentication

Authenticate, create, edit and delete users

Documentation in docs/users_and_authentication.md

Experiments and Process variables

Create, get, edit and delete experiments and process variables

Documentation in docs/experiments_and_process_variables.md

Get data from experiments and process variables

Receive experiment data from the archiver

Documentation in docs/experiment_pv_data.md

Setting variables via MQTT Publish

Set new values for process variables

Documentation in docs/mqtt_publish.md

Email threshold subscriptions

Subscribe to email alerts for breached process variable thresholds

Documentation in docs/email_threshold_subscription.md

Import and export of experiment configurations

Import and export database entries

Documentation in docs/file_import_export.md

Cross-endpoint responses

Documentation in docs/cross_endpoint_responses.md

Contribute

Feedback and contributions are always welcome.

To ensure a consistent code style, please install pre-commit (MIT License).

pip install pre-commit
pre-commit install