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.
Server is based on Flask and few extensions:
- Flask RESTful
- Flask SQLAlchemy
Database: MySQL
First of all, create your virtual environment and activate it with:
source venv/bin/activate
I highly recommend using
virtualenv
, notpython -m venv
, as it createsactivate_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
Make sure app.cgi
and project's have permissons set to 750. Also change path to your virtual environment in app.cgi
.
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.
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.
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.