Contents
The idea for this technical project started from the need to solve an environmental problem, especially in living spaces designed in a way that causes unbalanced temperature rises, such as rooms with a large number of windows. This design leads to thermal retention (greenhouse effect) that makes the room much hotter than the rest of the building, raising questions about the effectiveness of ventilation and cooling systems.
Project Objective and Methodology
The primary goal was to gather accurate and reliable data to demonstrate this thermal variation, and thus provide a basis for taking action to adjust the air conditioning system. Accordingly, the first Internet of Things (IoT) project was created to perform the following tasks:
- Record climate data (temperature and humidity) periodically from several devices.
- Store the data for the long term.
- Generate interactive charts for 48 hours, accessible from any connected computer.
Components and Technology Used
This system relies on several main components:
- DHT22 Sensor: Used to collect climate data.
- ESP8266 Microcontrollers: Used to send data via data packets (Datagrams). These units take several readings from the sensor and send the median reading to eliminate outliers or inaccurate readings.
- Raspberry Pi: Operates as the main control hub for the system, running the Tomcat 10 server, receiving data packets, and using the Charts.js library to create a clear and interactive graph that includes time points and precise details.
Advantages of the Customized Solution
Although there are ready-made programs like HomeAssistant that can perform basic sensor monitoring tasks, this customized solution offers significant advantages:
- Customization and scalability flexibility: The solution is fully open-source and available on GitHub, allowing development and scaling without the constraints of off-the-shelf software.
- Opportunity for technical learning: This project provides hands-on experience in multiple fields including server deployment, microcontroller programming, and web application deployment.
This project is just a starting point, and there are future plans for expansion and improvement.
You may be interested in: How to Make a Simple Electric Circuit
Technical Requirements
To create this system, we need the following components. The variable n represents the number of locations or rooms to be monitored.
| Category | Component | Required Quantity |
| Hardware | Raspberry Pi (Model 3 or higher, with updated Raspberry Pi OS) | 1 |
| ESP8266 Microcontrollers | n | |
| DHT22 Digital Temperature and Humidity Sensors | n | |
| Connecting Wires (Male-Female) (3 for each DHT22) | n | |
| Micro-USB Wall Adapters | n+1 | |
| USB Drive (for transferring files to Pi) | 1 | |
| Display, Keyboard, and Mouse (USB/Bluetooth), HDMI Cable | 1 of each | |
| Ethernet Cable (to connect Pi to the router) | 1 | |
| Computer, and Wi-Fi Router | 1 of each | |
| Software | Arduino IDE Development Environment |
Step 1: Install Tomcat and Java on Raspberry Pi
This step requires setting up a Tomcat server that will host the climate monitoring web application.
- Update the operating system: Open the terminal on Raspberry Pi and execute the following command:
sudo apt update && sudo apt upgrade -y - Install Java: Tomcat 10 requires Java version 11 or higher; this project uses Java 17. Install OpenJDK using:
sudo apt install openjdk-17-jdkVerify the installation succeeded by checking the version:java -version - Install Tomcat 10: Install the application server:
sudo apt install tomcat10 - Check if Tomcat is running: Tomcat 10 should start automatically after installation. Check its status with:
systemctl status tomcat10To confirm, open the browser and enter the address:http://localhost:8080When the Tomcat 10 welcome page appears, the server is successfully set up.
Step 2: Deploy the Climate Web Application
Once Tomcat 10 is running on Raspberry Pi, the deployment of the web application is carried out according to the following steps:
- Obtain App Files: Visit the project GitHub repository to download the app files. (Repository link: https://github.com/AIM-Industries/Climate_IoT_System). Download the .zip file of the project and extract it. The folder named climate should be copied to the USB drive. This folder represents the web application ready for deployment.
- Stop Tomcat 10: To prepare the server for deployment, temporarily stop the Tomcat 10 service using the command:
sudo systemctl stop tomcat10 - Copy the App to the Tomcat Folder: After connecting the USB drive and determining its path (often within /media), copy the application folder to the Tomcat applications path:
sudo cp -r /media/{usb drive path}/climate /var/lib/tomcat10/webapps/ - Start Tomcat 10: Restart the server to complete the deployment process:
sudo systemctl start tomcat10 - Verify Successful Deployment: To ensure the application is available, enter the following address in the Raspberry Pi browser:
http://localhost:8080/climateIf two blank graph screens (one for temperature and another for humidity) appear instead of the Tomcat 10 welcome page, this means the web application has been successfully deployed.
Step 3: Set Up Raspberry Pi as a Hotspot with Autostart
This step is essential to allow the ESP8266 modules to connect directly to the Raspberry Pi, even in the absence of an external Wi-Fi network. The Pi device is transformed into a private Wi-Fi hotspot, set to automatically start working upon boot:
- Create the Hotspot:
- From the Raspberry Pi interface, click on the Wi-Fi icon in the top-right corner.
- Select Advanced Options then Create Wi-Fi Hotspot.
- In the displayed menu, fill out the options:
- Connection: select
New. - Network name: enter a name for the network (like
Climate). - Wi-Fi security: select
WPA & WPA2 Personal. - Password: enter a strong password to be remembered.
- Connection: select
- Click on Create to create the hotspot.
- Set Autostart:
- Return to Advanced Options and select Edit Connections.
- Double-click on all saved networks except the network named (
Climate). - Remove the check mark from the Connect Automatically With Priority option for all other networks.
- The same option (Connect Automatically With Priority) is checked for the
Climatenetwork only, to ensure it connects automatically as a priority on startup.
- Test Autostart: The Raspberry Pi should be restarted to ensure the created hotspot operates automatically as an active Wi-Fi network. If this step succeeds, the Pi will be capable of functioning independently as a server and hotspot.
Step 4: Connect ESP8266 and DHT22 Sensor
This is the physical connection step of the temperature and humidity sensor to the microcontroller, which is straightforward:
- Connect the sensor to the ESP8266 module: Using connection wires, make the following connections:
- VCC pin on DHT → 3.3V pin on ESP8266.
- GND pin on DHT → GND pin on ESP8266.
- DATA pin on DHT → D5 pin on ESP8266. Ensure firm connections.
- Power the ESP8266 unit: Connect the ESP8266 unit to a power source (via USB to Micro-USB cable connected to the computer at this stage). When the power is connected successfully, a blue light on the board briefly lights up.
Step 5: Upload Code to ESP8266 Using Arduino IDE
After completing the connections, upload the program for collecting and sending data to the ESP8266 unit:
- Set Up Arduino IDE for the ESP8266: The Arduino IDE development environment should first be made compatible with ESP8266 boards by following the available instructions to enable this feature.
- Install the necessary libraries: Through the Arduino IDE Library Manager, install the latest versions of the following libraries:
Adafruit Unified Sensor(by Adafruit).DHT sensor library(by Adafruit).
- Open the Code File: Open the file named esp8266-climate.ino located in the folder downloaded earlier from the GitHub repository.
- Adjust variables in the code: The first three variables located under the library import statements should be modified:
- Set the value of the variable
ssidto match the Raspberry Pi hotspot name created earlier. - Set the value of the variable
passwordto match the Raspberry Pi hotspot password. - Set the value of the variable
INTERVAL_MINUTESto either1or5to determine the time interval for each sampling and data sending.
- Set the value of the variable
- Upload Sketch: Click on the upload icon in the top left to upload the code to the ESP8266.
- When finished, the ESP8266 unit begins to slowly flash while attempting to connect to the Wi-Fi network.
- Upon successfully connecting to the Raspberry Pi, the unit flashes quickly three times. The light flashes each time data is sent, confirming the visual send.
- Calibration (optional for every 5-minute measurement): If readings are chosen to be taken every 5 minutes, it is advisable to perform calibration to ensure data is sent at the specified minutes (like 4:00, 4:05, etc.). After installing the unit in its final position, wait one second after the 5-minute mark (like 4:00:01) and then press the RST button (reset) located on the board.
Thus, the ESP8266 unit will be ready to effectively send temperature and humidity data to the Raspberry Pi server. The units can now be placed independently anywhere, supplied with a wall-mounted Micro-USB power adapter. The final step remains to display the data on any device connected to the network.
Step 6: Connect Raspberry Pi and Display Data
After starting the Tomcat server and confirming the ESP8266 units are sending data, the installation process is completed with the final connection and displaying the results:
- Connect Raspberry Pi to the network: Use an Ethernet cable to connect Raspberry Pi to the home Wi-Fi router, ensuring the device is powered separately.
- Important Note: If there is a firewall, ensure that access is allowed to ports 8080 and 8081 to ensure the project functions properly.
- Determine the IP address of Pi: Log into the router’s management page and locate Raspberry Pi within the list of connected devices (it may appear as raspberrypi). It is advisable to set the router to reserve this IP address for Pi to avoid future address changes after rebooting.
- Open the web application via the browser: The web application can be accessed from any device connected to the same network by entering the following address in the browser’s search bar:
http://{pi-ip}:8080/climate- Note: If the page does not load, verify that Tomcat is running (using
systemctl status tomcat10) and that ports 8080 and 8081 are open in the firewall.
- Note: If the page does not load, verify that Tomcat is running (using
If successful, the same graphs seen earlier will appear, and data points will begin to show and accumulate with each page refresh. Data points are deleted after 48 hours to prevent excessive accumulation. Thus, the live climate monitoring system is complete.
Step 7: Troubleshooting
Despite the project’s relative simplicity, some common issues may arise that can be addressed quickly:
| Problem | Proposed Solutions |
| Tomcat page does not load | 1. On Pi: Check the status of the Tomcat service using systemctl status tomcat10. If inactive, activate it with sudo systemctl start tomcat10. 2. From another device: Ensure the correct IP address for Pi is being used instead of localhost (e.g., http://192.168.1.42:8080/climate). |
| ESP8266 module not connecting to Wi-Fi | 1. Check code: Ensure the values of ssid and password in the Arduino code match precisely (case-sensitive) the Pi hotspot settings. 2. Isolate the problem: Attempt to connect to the Pi hotspot from a phone/computer. If successful, restart Pi and try again. If unsuccessful, the issue lies in the Pi hotspot settings (return to step 3). 3. Device inspection: Attempt to connect ESP8266 to a regular home Wi-Fi network; if it fails, the unit may be defective. |
| Data is inaccurate or not displayed | 1. Sensor/connections: The DHT22 sensor or its cheap wiring is the most common reason. It is advisable to try a new sensor or new wiring. 2. Debugging: Use the serial monitor in Arduino IDE at Baud Rate 115200 to check if the sensor is reading correctly and whether taken samples vary significantly. 3. Location: The sensor may be affected by heat emitted from nearby devices (if readings are too high and humidity is low), or by airflow from fans/vents (resulting in reading lower than expected). |
| Clear stored data | To delete all stored data and clear graphs, execute the following command on Pi: sudo rm /var/cache/tomcat10/climate-data/data.json |
Step 8: Future Improvements (V2)
This project is the first version, and there are plans to develop and enhance it. The proposed future improvements (ranked by priority) include:
- Wall Socket Case Design: Create a case to be 3D-printed to house the ESP8266 and DHT22 components directly connecting to a wall socket. The goal is to provide a compact and elegant solution that protects the sensor from external thermal interference.
- Easy Local URL: Allow access to the web page locally by typing a simple name like
climate.localinstead of using an IP address. - Device Naming: Develop a system that allows naming sensors on the graph with user-friendly names of the user’s choice.
- ESP8266 Calibration Removal: The system should be developed to enable ESP8266 units to sync time with Pi automatically, adjusting packet sending timing to avoid simultaneous sending and related issues.
- Long-term Data Storage: Instead of deleting data after 48 hours and storing it locally, plans are made to write data to an external drive or to the cloud for available and persistent use in data analysis or AI applications.
- Interactive Settings: Add options on the web page to switch measurement units (Fahrenheit, Celsius, Kelvin) while storing user preferences, and provide the ability to specify data sending intervals from the web and update all ESP8266 units directly.
- Truly Live Data: Develop the page to automatically update the graphs upon new data arrival without needing to refresh the page, enhancing the complexity and quality of the user experience.
Source: https://www.instructables.com/Climate-Monitoring-IoT-System-With-Raspberry-Pi-an/ by: AIM Industries












