**Air Quality Monitor** is a lightweight web interface that displays real-time data from two environmental sensors: **HTU21D** and **BMP180**. The system uses **NGINX** to serve an HTML page that reads live data from JSON files.
**Air Quality Monitor** is a lightweight web interface that displays real-time data from two environmental sensors: **HTU21D** and **BMP180**. The system uses **NGINX** to serve an HTML page that reads live data from JSON files.
All the system is runing on a beagle bone black.
## Project Description
## Project Description
This project was designed to visualize environmental parameters in a simple, fast, and efficient way using an embedded graphical interface. The data is obtained from the following sensors:
This project was designed to visualize environmental parameters in a simple, fast, and efficient way using an embedded graphical interface. The data is obtained from the following sensors:
@ -14,18 +14,20 @@ The data is stored in two JSON files, updated by the embedded system and display
---
---
## Project Structure
## Project Structure
air-quality-monitor/
UI directory
│
- BMP180.json # Pressure and temperature data from BMP180
├── BMP180.json # Pressure and temperature data from BMP180
- HTU21D.json # Temperature and humidity data from HTU21D
├── HTU21D.json # Temperature and humidity data from HTU21D
- index.html # Main web interface
├── index.html # Main web interface
- index.js # JavaScript logic to fetch and display JSON data
├── index.js # JavaScript logic to fetch and display JSON data
- style.css # Custom CSS styles
├── style.css # Custom CSS styles
> The `.json` files are automatically updated by C programs that communicate with the sensors via I2C.
> The `.json` files are automatically updated by C programs that communicate with the sensors via I2C witch the librarys integrated on the repository.
---
---
##
Both sensors that we are using are conected to the I2C port 2 of the beagle bone
## 🚀 Installation & Deployment with NGINX
## 🚀 Installation & Deployment with NGINX
### Requirements
### Requirements
@ -63,8 +65,8 @@ sudo systemctl restart nginx
## User interface
## User interface
This is a simple web page that displays real-time sensor data from two devices:
This is a simple web page that displays real-time sensor data from two devices:
• BMP180: Shows temperature and pressure.
- BMP180: Shows temperature and pressure.
• HTU21D: Shows humidity and temperature.
- HTU21D: Shows humidity and temperature.
It’s styled with a separate CSS file (style.css) and fetches live data using JavaScript (index.js), which likely reads values from two JSON files (BMP180.json and HTU21D.json).
It’s styled with a separate CSS file (style.css) and fetches live data using JavaScript (index.js), which likely reads values from two JSON files (BMP180.json and HTU21D.json).
### HTML
### HTML
@ -111,8 +113,8 @@ It’s styled with a separate CSS file (style.css) and fetches live data using J
<!DOCTYPE html>
<!DOCTYPE html>
<htmllang="en">
<htmllang="en">
```
```
• Declares this document as HTML5.
- Declares this document as HTML5.
• lang="en" sets the document language to English, which is useful for accessibility and SEO.
- lang="en" sets the document language to English, which is useful for accessibility and SEO.
##### HEAD
##### HEAD
```html
```html
<head>
<head>
@ -122,10 +124,10 @@ It’s styled with a separate CSS file (style.css) and fetches live data using J
<linkrel="stylesheet"href="style.css"/>
<linkrel="stylesheet"href="style.css"/>
</head>
</head>
```
```
• charset="UTF-8" ensures proper text encoding.
- charset="UTF-8" ensures proper text encoding.
• viewport makes the layout responsive on mobile devices.
- viewport makes the layout responsive on mobile devices.
• title is what appears in the browser tab.
- title is what appears in the browser tab.
• link imports the external CSS file (style.css) for styling.
- link imports the external CSS file (style.css) for styling.
##### BODY
##### BODY
```html
```html
<body>
<body>
@ -136,14 +138,14 @@ It’s styled with a separate CSS file (style.css) and fetches live data using J
<scriptsrc="index.js"></script>
<scriptsrc="index.js"></script>
</body>
</body>
```
```
• The background div might be used for a visual effect like a background image or color gradient (defined in your CSS).
- The background div might be used for a visual effect like a background image or color gradient (defined in your CSS).
• container holds the main content (dashboard).
- container holds the main content (dashboard).
• index.js is loaded at the end to ensure the DOM is ready before scripts run.
- index.js is loaded at the end to ensure the DOM is ready before scripts run.
##### Dashboard Title
##### Dashboard Title
```html
```html
<h1>Sensor Dashboard</h1>
<h1>Sensor Dashboard</h1>
```
```
• This is the main heading of your web page.
- This is the main heading of your web page.
##### Sensor Card: BMP180
##### Sensor Card: BMP180
```hmtl
```hmtl
<divclass="sensor-card">
<divclass="sensor-card">
@ -155,9 +157,9 @@ It’s styled with a separate CSS file (style.css) and fetches live data using J
</div>
</div>
</div>
</div>
```
```
• This block represents the BMP180 sensor.
- This block represents the BMP180 sensor.
• The icon (from flaticon.com) visually represents pressure/temperature.
- The icon (from flaticon.com) visually represents pressure/temperature.
• The id attributes (temperature, pressure) are hooks used by JavaScript to insert real values from BMP180.json.
- The id attributes (temperature, pressure) are hooks used by JavaScript to insert real values from BMP180.json.
##### Sensor Card: HTU21D
##### Sensor Card: HTU21D
```html
```html
<divclass="sensor-card">
<divclass="sensor-card">
@ -169,22 +171,22 @@ It’s styled with a separate CSS file (style.css) and fetches live data using J
</div>
</div>
</div>
</div>
```
```
• This block represents the HTU21D sensor.
- This block represents the HTU21D sensor.
• The image is a humidity icon.
- The image is a humidity icon.
• The id attributes (humidity, tempHTU) are also updated by JavaScript using HTU21D.json.
- The id attributes (humidity, tempHTU) are also updated by JavaScript using HTU21D.json.
##### JavaScript Integration
##### JavaScript Integration
```hmtl
```hmtl
<scriptsrc="index.js"></script>
<scriptsrc="index.js"></script>
```
```
• This line loads your script, which is responsible for:
- This line loads your script, which is responsible for:
• Fetching the JSON files.
- Fetching the JSON files.
• Parsing their content.
- Parsing their content.
• Replacing the placeholder values (-- °C, -- hPa, etc.) with live sensor data.
- Replacing the placeholder values (-- °C, -- hPa, etc.) with live sensor data.
### Index.js
### Index.js
The script fetches data from two local JSON files:
The script fetches data from two local JSON files:
• BMP180.json — contains temperature and pressure.
- BMP180.json — contains temperature and pressure.
• HTU21D.json — contains temperature and humidity.
- HTU21D.json — contains temperature and humidity.
Then it updates the HTML every 3 seconds so the page always shows live sensor values.
Then it updates the HTML every 3 seconds so the page always shows live sensor values.
#### Full code
#### Full code
@ -445,8 +447,9 @@ int getHum(int fd, double *hum);
//RESET
//RESET
int getReset(int fd);
int getReset(int fd);
#endif
#endif
```
```
##### Explanation
- HTU21D_ADDR: The I2C address of the sensor (0x40).
- HTU21D_ADDR: The I2C address of the sensor (0x40).
- HTU21D_TEMP: Command to read temperature (0xE3).
- HTU21D_TEMP: Command to read temperature (0xE3).