Important
Unfinished -> Please note that this repository is not finished yet. Please wait until finished before usage.
- An Arduino attachted with multiple sensors reads multiple values like light, temperature and more.
- A FastAPI queries the Arduino every mintue for these values.
- The FastAPI saves them in a SQLite Database and checks the entire database for old values, which then get averaged and saved in a new table to decrease the Database Size.
- A webpage queries the FastAPI for the Values saved in the Database and shows them nice in Charts.
- The webpage also allows you to adjust settings from the Arduino.
| Category | Jump to Category | |
|---|---|---|
| Arduino | 1️⃣ | |
| Database | 2️⃣ | |
| Middleman-API | 3️⃣ | |
| Webpage | 4️⃣ | |
| Settings | 5️⃣ |
Please note: While creating the Project, I did not intend to make it very secrue. If you plan on making it publicly avaible or have the used ports open, please modify each code to make it secrue!
In this Section we will talk about how to set up the Arduino Side of the Project.
| This devices measures: |
|---|
| Temperature |
| Humidity |
| Heat Index |
| Brightness Percentage |
| Voltage (How?) |
| Item Name | Link to buy |
|---|---|
| ESP32 | az-delievery.de |
| Display | az-delievery.de |
| Temperature Sensor | az-delievery.de |
| Kabel | az-delievery.de |
| Light Sensor | Amazon |
| Buttons | Amazon |
This plan was translated to English from German.
For Full Image click this link
Please note that you can change the Pins (except for the Display) in the Arduino Code.
- Install VSCode and PlatformIO IDE
- Create a new Project and select these
- Board: DOIT ESP32 DEVKIT V1
- Framework: Arduino
- Install these libaries to your Project:
- Adafruit BusIO
- Adafruit GFX Libary
- Adafruit SSD1306
- Adafruit Unified Sensor
- DHT sensor libary
- You can now insert the Code in ./src/main.cpp
-
I have for each measured value each 3 tables: "minutes", "hours" and "days".
-
Each table normally shouldnt hold more then about 120 rows.
-
"Minutes" hold the values of every check by the Middleman-API.
-
If the saved values get older then 2 minutes, they get averaged and saved under "hours".
-
The old values get deleted from minutes.
-> This is to decrease Database size and space consumption.
-
-
Every time unit has the same process.
- Minutes after 2 minutes of age -> averaged into hours
- Hours after 2 days of age -> averaged into days
- Days after |TODO| -> averaged into |TODO|
I use SQLite Studio for a better Overview of the Database.
I made using their "Export" feature, a file which you can use to create your own Database.
The File is: db.sql
APScheduler uses a "AsyncIOScheduler" to schedule a event which every minute queries current values from the Arduino API. The interval can be changed. Right after recieving the new values it builds up a connection with the Database to average and delete old values and append the new values.
When the Webpage queries the values, the Python Script gets all the saved values from the requested type from the Database and returns it to the Webpage.
The Middleman could potentially quiery new values constantly from the Arduino. The Arduino refreshes his values constantly.
The Main part of the Site is split into 6 columms. One for each value being displayed.
On the left there is a yet almost empty Sidebar and on the top a Header.
The values recieved from the Middleman-API are getting displayed in a Line Chart using Chart.js.
Under each Chart are buttons to change the time unit.
Each Chart has a Min object for the X-Axis (time), so it wont display values older then a hour.
Using the Webpage you are able to adjust some settings on the Arduino.
With a POST request you can change them to the opposite (toggle) or with a GET you can see the current state.
The Webpage also allows easier control of them.
Here is a Overview of them:
