The backend brains for the GEAR club's sustainable garden project. The server is written with the Django REST Framework. It implements the ability to periodically read sensors from an arduino and store the readings. As well, it supports live readings of sensors and retrieving past readings through HTTP requests/reponses to the REST API.
Installation and deployment of the backend has two components:
It is recommended to use Docker when deploying the Django backend and Docker Compose (included in Docker Desktop).
- Clone github repo:
$ git clone https://github.com/paxman101/sustainableGardenBackend.git
$ cd sustainableGardenBackend/sustainableGardenBackend
- Adjust Settings.py
- Docker Compose:
$ docker-compose up -d --build
- Initial Django Setup After Containers are Running:
$ docker-compose exec web python manage.py migrate
$ docker-compose exec web python manage.py crontab add
Use the Arduino IDE.
- Download the Required Libraries Through Library Manager:
Example video of how to use the Library Manager
Required Libraries:
ArduinoJson by Benoit Blanchon
DHT sensor library by Adafruit
- Upload the program to the arduino
- Connect arduino to server (Raspberry Pi) via USB
Currently, there are only two sensor types supported within the backend. To add support for a new sensor type requires two steps: Arduino Implementation and Django Implementation.
All logic should be implemented within an else if
statement within the readSensor
function. Simply add another else if (sensorName.equals("SensorName"))
statement where SensorName should be the name of your sensor. Add outputs by using the out
JsonDocument like so
out["output_name"] = output_value;
That should be all there is to it as the outputs will automatically be serialized as json to be sent to the server via serial.
Adding the new sensor type to Django will consist of updating the tuple list SENSOR_CHOICES
models.py. Add another tuple to the list with two elements like so:
SENSOR_CHOICES = [...,
('Serialized Sensor Name', 'Human Readable Name')
]
Where Serialized Sensor Name must be the same name as within the Arduino if else
statement. The Human Readable Name will be the name that shows up when registering the sensor and isn't restricted by anything.