Skip to content

brobots-hub/ecobrobotsbackend

Repository files navigation

#brobots eco backend

GitHub release (latest by date) GitHub Workflow Status #brobots eco website

This is a new Python backend for #brobots eco. Previous version was written in PHP and had major flaws.

#brobots eco is a net of sensors that collect data about air quality in Brovary.

What's used

Server is based on Flask and few extensions:

  • Flask RESTful
  • Flask SQLAlchemy

Database: MySQL

Executing

First of all, create your virtual environment and activate it with: source venv/bin/activate

I highly recommend using virtualenv, not python -m venv, as it creates activate_this.py that is needed for CGI

Set the environment variables: export ENVIRONMENT={DEVELOPMENT or PRODUCTION} and export PYTHONPATH=/path/to/project/root

If ENVIRONMENT variable is set to DEVELOPMENT the .env.dev file will be used. Otherwise, the .env is used. PYTHONPATH is needed for loading config and AQICalculator.py to be executed on its own.

To start the server run: python run.py

To start tests run: python -m unittest tests

When deploying as CGI

Project permissions

Make sure app.cgi and project's have permissons set to 750. Also change path to your virtual environment in app.cgi.

CGI file

Sometimes after running git pull I get Internal Server Error. Removing the file and creating a new one natively on server can help. Don't foget to set its permissions to 750.

Helpful links

For WSL users

I use WSL as my working system and I spent lots of time debugging this small thing: cron isn't started on WSL startup. You have to run sudo service cron start before working.

For VS Code users

Don't use SSH connection feature in VS Code. It prevented my CGI app from working on server and made me spend hours of debugging.