This shows you the differences between two versions of the page.
iothings:proiecte:2023:tempandmonitorsystem [2023/12/12 15:17] andrei.ulmamei add software |
iothings:proiecte:2023:tempandmonitorsystem [2024/01/08 14:57] (current) andrei.ulmamei added presentation |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===Temperature monitoring and control system for Server Room=== | + | ======Temperature monitoring and control system for Server Room====== |
Student: Andrei-Alexandru Ulmamei \\ | Student: Andrei-Alexandru Ulmamei \\ | ||
Master: ACES II \\ | Master: ACES II \\ | ||
Git repository: https://gitlab.upb.ro/aulmamei/iot-project \\ | Git repository: https://gitlab.upb.ro/aulmamei/iot-project \\ | ||
- | Demo link: To be added \\ | + | Demo link: [[https://drive.google.com/file/d/1Cp1NUnDxHuX82SSxTeIZHgxlJRuXop-W/view?usp=sharing|Demo]] \\ |
+ | Presentation: {{:iothings:proiecte:2023:iot_au.pdf|Presentation}} | ||
- | ==Project Description== | + | ======Project Description====== |
This goal of this project is to create a temperature monitoring and control system, intended to be used in a server room, that consists of a Web Application, a microcontroller that communicates with the Web App, a sensor for monitoring temperature and an IR transmitter, used for controlling an air conditioning unit. | This goal of this project is to create a temperature monitoring and control system, intended to be used in a server room, that consists of a Web Application, a microcontroller that communicates with the Web App, a sensor for monitoring temperature and an IR transmitter, used for controlling an air conditioning unit. | ||
- | ==Hardware Description== | + | ======Hardware Description====== |
The hardware components needed for the project are: | The hardware components needed for the project are: | ||
Line 31: | Line 31: | ||
The following electric schematic represents the project’s hardware. \\ | The following electric schematic represents the project’s hardware. \\ | ||
- | {{:iothings:proiecte:2023:schematic_iot.png?670x350}} | + | {{:iothings:proiecte:2023:schematic_iot.png?700x400}} |
The schematic was realized using KiCad (https://www.kicad.org/). | The schematic was realized using KiCad (https://www.kicad.org/). | ||
- | ==Software architecture== | + | The hardware with all the components connected can be seen below: \\ |
+ | |||
+ | {{:iothings:proiecte:2023:hw.jpeg?700x400}} | ||
+ | |||
+ | |||
+ | ======Software architecture====== | ||
The code is composed of 4 elements: the embedded software, written in Arduino IDE for the ESP32 board, the Web Component, which was written in HTML and Javascript for the frontend functionality, the Firebase Realtime Database configuration and the Grafana dashboard configuration. | The code is composed of 4 elements: the embedded software, written in Arduino IDE for the ESP32 board, the Web Component, which was written in HTML and Javascript for the frontend functionality, the Firebase Realtime Database configuration and the Grafana dashboard configuration. | ||
Line 113: | Line 118: | ||
#define FAN_AUTO_CMD 0xFD | #define FAN_AUTO_CMD 0xFD | ||
</code> | </code> | ||
+ | The flow chart of the embedded software can be below: \\ | ||
+ | {{:iothings:proiecte:2023:flow_chart.png}} \\ | ||
+ | |||
+ | **Web Application** \\ | ||
+ | |||
+ | The web application's purpose is to create a user friendly graphical user interface for analyzing the temperature samples taken from the ESP32 board, and for controlling the A/C unit inside the room. The Web Application is created based on a Firebase example that creates all the necessary configuration for the project to connect to the database. It even has a login module, which takes the credentials from the Firebase website authentication settings. | ||
+ | |||
+ | {{:iothings:proiecte:2023:login.png?700x400}} | ||
+ | |||
+ | After logging in with the credentials, the data page is shown. In this page, one can see the real time updated Grafana dashboard temperature graph, the last read temperature and the possibility of seeing and deleting all the data written to the database. | ||
+ | |||
+ | {{:iothings:proiecte:2023:data_page.png?700x526}} | ||
+ | |||
+ | On the upper navbar, the control button is shown, button which will change the page to the main control panel, where settings for the A/C state, A/C fan speed and A/C temperature control will be shown. | ||
+ | |||
+ | {{:iothings:proiecte:2023:control_page.png?700x400}} | ||
+ | |||
+ | After selecting all the settings for the A/C a write is made to the database, in the control fields. | ||
+ | |||
+ | **Database configuration** \\ | ||
+ | |||
+ | The database used is the Realtime Database from Firebase, with the following configuration: | ||
+ | |||
+ | {{:iothings:proiecte:2023:database_format.png}} | ||
+ | |||
+ | The data is stored under the node UsersData, which has a child node named using the user id. After that, two children nodes, one for control and the other for readings is created. The control node contains three data: the ac_status (which indicates if the A/C unit has been requested to turn on/off), the ac_temp (which indicated the temperature the A/C system should be set to) and the fan_speed (the fan speed the A/C should be set to). The readings section contains multiple nodes, each node's name being the timestamp at which the data has been acquired. This node contains both the temperature and the timestamp of acquisition. | ||
+ | |||
+ | **Grafana Dashboard** \\ | ||
+ | |||
+ | The Grafana Dashboard was used to create the temperature graph that is shown in the Web Application. Because the Grafana API doesn't support Firebase Realtime database connection, a further step was created using the Google Sheets API with Google Script. The Realtime database was connected to the Google Sheets API, and a Google Script was created which synchronizes the sheets document to the database. This was done by creating a trigger in the Google Scripts environment. | ||
+ | |||
+ | <code> | ||
+ | var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret); | ||
+ | var dataSet = [base.getData()]; | ||
+ | var readings = dataSet[0]["UsersData"][db_uid]["readings"]; | ||
+ | var temps = []; | ||
+ | var timestamps = []; | ||
+ | for (var obj in readings) { | ||
+ | var timestamp_str = readings[obj]["timestamp"]; | ||
+ | var timestamp_int = parseInt(timestamp_str); | ||
+ | temps.push(readings[obj]["temperature"]); | ||
+ | timestamps.push(new Date(timestamp_int * 1000).toLocaleString("en-US")); | ||
+ | } | ||
+ | |||
+ | var rows = []; | ||
+ | for(i = 0; i < temps.length; i++) { | ||
+ | rows.push([timestamps[i], temps[i]]); | ||
+ | } | ||
+ | |||
+ | dataRange = sheet.getRange(2, 1, rows.length, 2); | ||
+ | dataRange.setValues(rows); | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ======Conclusion====== | ||
+ | In conclusion, the ESP32 is a very suited hardware component for IoT applications, due to it's hardware integration of Wi-Fi and Bluetooth. The usage of Firebase was really facile, due to the multitude of internet examples. \\ | ||
+ | The most difficult task while creating this project was to understand the infrared commands that were coming from the remote control of the A/C unit. | ||
+ | ======Bibliography====== | ||
- | **Web Application** | + | https://randomnerdtutorials.com/esp32-data-logging-firebase-realtime-database/ \\ |
+ | https://firebase.google.com/ \\ | ||
+ | https://github.com/grafana/google-sheets-datasource/ \\ | ||
+ | https://firebase.google.com/docs/database/web/read-and-write#web-namespaced-api_3 \\ | ||
- | ==Conclusion== |