Skip to content

[IN PROGRESS] Measures values and display them on a Website (Uses Arduino, SQLite DB, FastAPI and Website)

License

Notifications You must be signed in to change notification settings

KiSki-Dev/MeasureDevice

Repository files navigation

Important

Unfinished -> Please note that this repository is not finished yet. Please wait until finished before usage.

"MeasureDevice" using Arduino, API, Database and Webpage

This is a small Project, I made during my two-week long student Internship at ████████.


Arduino SQLite FastAPI

  1. An Arduino attachted with multiple sensors reads multiple values like light, temperature and more.
  2. A FastAPI queries the Arduino every mintue for these values.
  3. 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.
  4. A webpage queries the FastAPI for the Values saved in the Database and shows them nice in Charts.
  5. The webpage also allows you to adjust settings from the Arduino.

If you dont understand this explanation, this Plan might help you understand:

alt text


Category Jump to Category
Arduino Arduino 1️⃣
SQLite Database 2️⃣
FastAPI Middleman-API 3️⃣
HTML5 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!

Arduino

Arduino Espressif PlatformIO C++

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?)

Parts used:

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

Circuit/Circuit Diagram/Schematic Diagram:

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.

How to install:

  1. Install VSCode and PlatformIO IDE
  2. Create a new Project and select these
    • Board: DOIT ESP32 DEVKIT V1
    • Framework: Arduino
  3. Install these libaries to your Project:
    • Adafruit BusIO
    • Adafruit GFX Libary
    • Adafruit SSD1306
    • Adafruit Unified Sensor
    • DHT sensor libary
  4. You can now insert the Code in ./src/main.cpp

Used Port for the Arduino API: 4719

Database

SQLite

I use SQLite as Database.

  • 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


Middleman-API

FastAPI Python

The Middleman-API is made in Python with FastAPI and APScheduler.

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.

Used Port for the Middleman-API: 8000


Webpage

HTML5 JavaScript CSS3 Chart.js

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.

Settings

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:

About

[IN PROGRESS] Measures values and display them on a Website (Uses Arduino, SQLite DB, FastAPI and Website)

Resources

License

Stars

Watchers

Forks