diff --git a/README.md b/README.md index 73954df..46a577c 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,95 @@ This project implements a real-time temperature and humidity monitoring system u ## 🧠 System Architecture +The system is designed using a **layered architecture**, where each component has a specific responsibility. This separation improves maintainability and clarity. + +--- + +### πŸ”Ή 1. Hardware Layer (Sensor) + +The **HTU21D sensor** measures temperature and humidity and communicates using the **I2C protocol**. + +* The Raspberry Pi acts as the **master** +* The sensor acts as the **slave** +* Data is transmitted over SDA (data) and SCL (clock) + +--- + +### πŸ”Ή 2. Data Acquisition Layer (C Program) + +A program written in C interacts directly with the I2C interface: + +* Opens the I2C device (`/dev/i2c-1`) +* Sends commands to the sensor +* Reads raw data +* Converts it into human-readable values (Β°C and %) + +πŸ‘‰ Output is formatted as a JSON file: + +```json +{ "temperature": 23.9, "humidity": 57.4 } ``` -HTU21D Sensor β†’ I2C β†’ C Program β†’ JSON File β†’ Nginx β†’ Web Browser + +--- + +### πŸ”Ή 3. Data Persistence Layer (JSON File) + +The JSON file acts as an **intermediate data layer**: + +* Stores the latest sensor reading +* Decouples backend (C) from frontend (JavaScript) +* Enables simple data exchange without a database + +--- + +### πŸ”Ή 4. Web Server Layer (Nginx) + +Nginx serves static files: + +* HTML (interface) +* JavaScript (logic) +* JSON (sensor data) + +πŸ‘‰ It acts as the **bridge between the system and the user’s browser** + +--- + +### πŸ”Ή 5. Presentation Layer (Frontend) + +The browser executes JavaScript: + +* Uses `fetch()` to request the JSON file +* Updates the DOM dynamically +* Displays values in real time + +--- + +### πŸ”„ Data Flow Summary + +```text +Sensor β†’ I2C β†’ C Program β†’ JSON β†’ Nginx β†’ Browser β†’ User Interface ``` --- +### 🧠 Key Design Decisions + +* **Use of JSON:** lightweight and easy to parse +* **Polling (setInterval):** simple real-time updates +* **Separation of layers:** avoids tight coupling between components + +--- + +### βš™οΈ Why This Architecture Works + +* Modular β†’ each part can be modified independently +* Scalable β†’ can add database or APIs later +* Simple β†’ ideal for embedded + web integration + +--- + +--- + ## 🧰 Materials ### πŸ”§ Hardware