Django server and APIs for Openair surveys and errors registration.
Required packages:
- python3
- python3-pip
Optional packages:
- git (to clone the repository)
- python3-venv (to install into a virtual env)
In order to install the server into a virtual environment, to delete everything later, we use the following code:
# create the folder
python3 -m venv .venv
# activate the virtual environment
source .venv/bin/activate
First of all, we need to clone the repository, install dependencies, create the db (sqlite3) and then run the server. Optionally, we can add a super-user to access the Django admin site.
# clone the repository
git clone https://github.com/Nutria-LUG/OpenAir_Server openair-server
cd openair-server
# install dependencies
pip3 install -r requirements.txt
# create the db
python3 manage.py migrate
# add a super-user (optional)
python3 manage.py createsuperuser
# models registration
python3 manage.py makemigrations
python3 manage.py migrate
# run the server
python3 manage.py runserver
Following, models used for storing data from surveys and errors.
- name (string): name
- mac_address (string): MAC address
- ip_address (string): static IP assigned to the device
- enum (integer): enum to identify the device
- active (boolean): if disabled, API will reject requests
- name (string): name
- code (string): hexadecimal sensor code
- enum (integer): enum to identify the sensor
- active (boolean): unused
- inserted (datetime): set by the server, it's the timestamp of the inserted row
- timestamp (integer): timestamp of the survey (client detection)
- device (Device): set by the server, it's filled using the client ip, obtained by the request
- sensor (Sensor): set by the server, it's filled using the enum sent with the request
- value (float): value of the survey
- inserted (datetime): set by the server, it's the timestamp of the inserted row
- timestamp (integer): timestamp of the error (client detection)
- device (Device): set by the server, it's filled using the client ip, obtained by the request
- message (string): error message
Current project makes use of Django REST framework library.
The API method will refuse all requests sent by clients with IPs not defined into the Device table.
- address: /openair/api/survey
- method: POST
- accept: JSON
- responses: 201 (created), 400 (bad request)
- data: object, array of objects
- timestamp (timestamp)
- sensor (integer)
- value (float)
The API method will refuse all requests sent by clients with IPs not defined into the Device table.
- address: /openair/api/error
- method: POST
- accept: JSON
- responses: 201 (created), 400 (bad request)
- data: object, array of objects
- timestamp (timestamp)
- message (string)