- Python 3.x
- pip
- Arduino IDE
- MySQL Server
-
Clone the repository:
git clone https://github.com/your-repo/MRC_DJango.git cd MRC_DJango/mysite -
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install the dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the root of your project and add your database credentials:MYSQL_DATABASE=django MYSQL_USER=root MYSQL_PASSWORD=2023 MYSQL_HOST=localhost MYSQL_PORT=3306
-
Configure the database settings in
mysite/settings.py:import os from dotenv import load_dotenv # Load environment variables from .env file load_dotenv() DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "NAME": os.getenv("MYSQL_DATABASE"), "USER": os.getenv("MYSQL_USER"), "PASSWORD": os.getenv("MYSQL_PASSWORD"), "HOST": os.getenv("MYSQL_HOST"), "PORT": os.getenv("MYSQL_PORT"), } }
-
Run the migrations:
python3 manage.py makemigrations python3 manage.py migrate
-
Create a superuser for the Django admin:
python3 manage.py createsuperuser
-
Start the Django development server:
python3 manage.py runserver
-
Access the Django admin interface:
Open your browser and go to
http://localhost:8000/adminand log in with the superuser credentials.
-
Connect your Arduino to your computer and open the Arduino IDE.
-
Open the
arduino_side/arduino.inofile in the Arduino IDE. -
Upload the code to your Arduino.
-
Arduino collects sensor data and sends it via HTTP POST requests to the Django API.
-
Django's API receives the data and stores it in the database.
-
BlogPost API:
GET /api/blogposts/- List all blog postsPOST /api/blogposts/- Create a new blog postGET /api/blogposts/{id}/- Retrieve a blog postPUT /api/blogposts/{id}/- Update a blog postDELETE /api/blogposts/{id}/- Delete a blog post
-
Sensors API:
GET /api/sensors/- List all sensorsPOST /api/sensors/- Create a new sensorGET /api/sensors/{id}/- Retrieve a sensorPUT /api/sensors/{id}/- Update a sensorDELETE /api/sensors/{id}/- Delete a sensor
-
SensorData API:
GET /api/sensordata/- List all sensor dataPOST /api/sensordata/- Create new sensor dataGET /api/sensordata/{id}/- Retrieve sensor dataPUT /api/sensordata/{id}/- Update sensor dataDELETE /api/sensordata/{id}/- Delete sensor data
The database settings are configured to use MySQL and are defined in mysite/settings.py:
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": os.getenv("MYSQL_DATABASE"),
"USER": os.getenv("MYSQL_USER"),
"PASSWORD": os.getenv("MYSQL_PASSWORD"),
"HOST": os.getenv("MYSQL_HOST"),
"PORT": os.getenv("MYSQL_PORT"),
}
}