This shows you the differences between two versions of the page.
iothings:proiecte:2023:sleepenvironmentmonitor [2024/01/09 15:47] taddeo.dadamo [Software] arduino code description |
iothings:proiecte:2023:sleepenvironmentmonitor [2024/01/13 13:05] (current) taddeo.dadamo [Introduction] |
||
---|---|---|---|
Line 14: | Line 14: | ||
The values will be collected through sensors managed by an ESP32 and stored in a Firebase database. The user can initiate the recording from a web interface at bedtime and can visualize the progression of measurements throughout the night on the same interface. This will also allow the evaluation of whether certain periods during the night are better than others. An overall score for the surrounding environment's quality, derived from the five metrics, will be displayed by the web interface. | The values will be collected through sensors managed by an ESP32 and stored in a Firebase database. The user can initiate the recording from a web interface at bedtime and can visualize the progression of measurements throughout the night on the same interface. This will also allow the evaluation of whether certain periods during the night are better than others. An overall score for the surrounding environment's quality, derived from the five metrics, will be displayed by the web interface. | ||
- | TODO : change the links | ||
- | * [[http://example.com|Demo]] | ||
- | * [[http://example.com|Presentation slides]] | ||
+ | * [[https://drive.usercontent.google.com/download?id=1Re7nz4044o_TYP70lAKlgvJ8HnbbWI90&export=download&authuser=0|Video Demo]] | ||
+ | * {{:iothings:proiecte:2023:sem_source_code.zip|Source Code}} | ||
+ | * {{:iothings:proiecte:2023:sem-presentation.pdf|Presentation slides}} | ||
=====Architecture===== | =====Architecture===== | ||
Line 35: | Line 35: | ||
* **CCS811**: an ultra-low power digital gas sensor solution which integrates a metal oxide (MOX) gas sensor to detect a wide range of Volatile Organic Compounds (VOCs) for indoor air quality monitoring (I2C interface) | * **CCS811**: an ultra-low power digital gas sensor solution which integrates a metal oxide (MOX) gas sensor to detect a wide range of Volatile Organic Compounds (VOCs) for indoor air quality monitoring (I2C interface) | ||
* **HDC2010**: a low power and high accuracy integrated humidity and temperature sensor (I2C interface) | * **HDC2010**: a low power and high accuracy integrated humidity and temperature sensor (I2C interface) | ||
- | * **Dablle soundmeter**: Dabble is a Smartphone app that offers modules to control hardware via Bluetooth and especially to access Smartphone sensors. Used in this project to connect to a smartphone's microphone and get a soundmeter. | + | * **Dabble soundmeter**: Dabble is a Smartphone app that offers modules to control hardware via Bluetooth and especially to access Smartphone sensors. Used in this project to connect to a smartphone's microphone and get a soundmeter. |
===Circuit Diagram=== | ===Circuit Diagram=== | ||
{{:iothings:proiecte:2023:schema.jpg?700|}} | {{:iothings:proiecte:2023:schema.jpg?700|}} | ||
===Real-life view=== | ===Real-life view=== | ||
- | TODO : insert a photo here | + | {{ :iothings:proiecte:2023:sem_real_view_annotated.png?400 }} |
====Software==== | ====Software==== | ||
===Used methods for quality rating=== | ===Used methods for quality rating=== | ||
Line 79: | Line 79: | ||
The code is separated into two files: //config.h// and //main.cpp//. The configuration file contains //#define// directives to associate identifiers with tokens that are often used and necessary for the code. This can be, for example, the pin numbers of the board, the paths in the database, the user identifiers for Firebase, or the Wi-Fi codes to which the ESP must connect. Then, the Arduino code is located in the main.cpp file, which is divided into 5 parts: | The code is separated into two files: //config.h// and //main.cpp//. The configuration file contains //#define// directives to associate identifiers with tokens that are often used and necessary for the code. This can be, for example, the pin numbers of the board, the paths in the database, the user identifiers for Firebase, or the Wi-Fi codes to which the ESP must connect. Then, the Arduino code is located in the main.cpp file, which is divided into 5 parts: | ||
- | * Unordered List ItemThe inclusion of libraries and files | + | * The inclusion of libraries and files |
- | * Unordered List ItemThe definition of global variables | + | * The definition of global variables |
- | * Unordered List ItemThe definition of helper functions which are the init functions, the functions specific to Firebase and the structure of our data, the other functions to operate the actions specific to our code. | + | * The definition of helper functions which are the init functions, the functions specific to Firebase and the structure of our data, the other functions to operate the actions specific to our code. |
<code> | <code> | ||
Line 170: | Line 170: | ||
==Web app== | ==Web app== | ||
- | TODO : same for the web app | + | The web project is organized as follows: |
+ | |||
+ | Two files specific to Firebase: | ||
+ | |||
+ | * firebase.json which determines the necessary configuration to host the app | ||
+ | * database.rules.json which contains the access rights rules described above in the Firebase section | ||
+ | |||
+ | The source code is located in the public directory. It includes: | ||
+ | |||
+ | * index.html: The HTML code of the application | ||
+ | * 404.html: What should be displayed in case of a bad URL | ||
+ | * style.css: The CSS stylesheet for formatting HTML elements | ||
+ | * A scripts folder that contains JavaScript files to make the page dynamic | ||
+ | * auth.js: Script specific to managing Firebase user authentication | ||
+ | * chart-definition.js: Script to define the charts displaying the values (the charts are then manipulated in index.js) | ||
+ | * index.js: All the rest of the script used to control the index.html page. | ||
+ | {{ :iothings:proiecte:2023:web_app_structure.jpg }} | ||
+ | |||
+ | The index.html file is constructed as follows: | ||
+ | |||
+ | First, the header which contains notably the inclusion of external references and scripts, the inclusion of the stylesheet, or the initialization of the Firebase config. | ||
+ | |||
+ | Then a topbar that will always be displayed: | ||
+ | <code> | ||
+ | <!--TOP BAR--> | ||
+ | <div class="topnav"> | ||
+ | <h1 class="topnav-item">Sleep Environment Monitor</h1> | ||
+ | <!--AUTHENTICATION BAR (USER DETAILS/LOGOUT BUTTON)--> | ||
+ | <div class="topnav-item" id="authentication-bar" style="display: none;"> | ||
+ | ... | ||
+ | </div> | ||
+ | </div> | ||
+ | </code> | ||
+ | |||
+ | Then, depending on the connection status, there will either be the login form: | ||
+ | <code> | ||
+ | <!--LOGIN FORM--> | ||
+ | <form id="login-form" style="display: none;"> | ||
+ | ... | ||
+ | </form> | ||
+ | </code> | ||
+ | |||
+ | or the user interface: | ||
+ | |||
+ | <code> | ||
+ | <!--CONTENT--> | ||
+ | <div class="content-sign-in" id="content-sign-in" style="display: none;"> | ||
+ | <!--RECORDS SELECT--> | ||
+ | <div> | ||
+ | ... | ||
+ | </div> | ||
+ | |||
+ | <!-- AVERAGES --> | ||
+ | <div id="average-measures"> | ||
+ | <!--GLOBAL SCORE--> | ||
+ | <div id="global-grade-div"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--GLOBAL-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | |||
+ | <!--VALUES AVG--> | ||
+ | <div id="avg-div"> | ||
+ | <div class="avgs"> | ||
+ | <!--LIGHT--> | ||
+ | <div class="avg"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--NOISE--> | ||
+ | <div class="avg"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--TEMPERATURE--> | ||
+ | <div class="avg"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--HUMIDITY--> | ||
+ | <div class="avg"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--CO2--> | ||
+ | <div class="avg"> | ||
+ | ... | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | |||
+ | <!--CHARTS--> | ||
+ | <div id="charts-div"> | ||
+ | <div class="charts"> | ||
+ | <!--LIGHT-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--SOUND-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--TEMPERATURE-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--HUMIDITY-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | <!--CO2-CHART--> | ||
+ | <div class="chart"> | ||
+ | ... | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </code> | ||
+ | |||
+ | In the end, we include the three scripts that we have defined: | ||
+ | |||
+ | <code> | ||
+ | <!--INCLUDE JS FILES--> | ||
+ | <script src="scripts/auth.js"></script> | ||
+ | <script src="scripts/charts-definition.js"></script> | ||
+ | <script src="scripts/index.js"></script> | ||
+ | </code> | ||
=====Results===== | =====Results===== | ||
- | TODO: show a result example and explain how to interpret it | + | This is what the final interface looks like: |
+ | |||
+ | First, a login page: | ||
+ | |||
+ | {{ :iothings:proiecte:2023:sem_login_interface.png?700 }} | ||
+ | |||
+ | Then, the interface on which the user can see the latest recording and view the results, select previous recordings or start a new one. | ||
+ | |||
+ | They can see the average rating given, and the average values of each magnitude as well as the evolution during the recording. | ||
+ | |||
+ | {{ :iothings:proiecte:2023:sem_web_interface.png?700 }} | ||
+ | |||
+ | {{ :iothings:proiecte:2023:sem_charts.png?700 }} | ||
=====Conclusion===== | =====Conclusion===== | ||
- | TODO: conclude | + | This system provides a user-friendly interface for users to gather information on factors that can influence the quality of their sleep, without having to worry about manually measuring light, noise, temperature, humidity, and CO2 concentration. |
+ | |||
+ | This project aimed at controlling the quality of the sleep environment has resulted in an initial draft of a system capable of assessing external factors that influence sleep quality. | ||
+ | |||
+ | Although this project has laid the groundwork for thorough monitoring of the sleep environment, it is important to note that it is not comprehensive and does not hold medical values. The results obtained are estimations, and the scientific rigor of the evaluation remains to be improved by closely working, for example, with sleep specialists. Furthermore, for a more comprehensive project, improvements could include integrating new sensors or displaying recommendations to improve sleep based on the measured parameters. | ||
+ | |||
+ | The main objective remained to build an end-to-end IoT project and become familiar with the technical and organizational challenges in this field. In this regard, this project seems to have fulfilled its role, as I feel I have progressed and had the opportunity to go further than what the module's labs proposed. | ||
=====References===== | =====References===== | ||