Climate Monitoring IoT System With Raspberry Pi and ESP8266

by AIM Industries in Circuits > Raspberry Pi

20 Views, 1 Favorites, 0 Comments

Climate Monitoring IoT System With Raspberry Pi and ESP8266

Screenshot 2025-08-24 193742.png

My project started with a problem right in my own room. I live in an office-converted bedroom that has more windows than usual, which means it traps heat really easily. Even when the rest of the house feels fine, I'm quite literally experiencing the greenhouse effect as my room turns into an oven.

Instead of baking each night, I got to thinking. How is it possible that my room is so significantly hotter than others just from a few more windows? Shouldn’t the ventilation and cooling keep everything balanced? Does my house have a design flaw? And most importantly, how could I gather real data to prove this anomaly to my parents - so maybe, just maybe, I could win the argument for lowering the AC?

And so was born my first IoT project, one that periodically records climate (temperature and humidity) data from multiple devices, stores it over time, and generates 48-hour graphs accessible by any computer on the Wi-Fi.

This project uses a DHT22 sensor to collect the climate data, and ESP8266 microcontrollers for sending data via datagrams. The DHT takes multiple sensor readings and sends the median to eliminate outliers or bad readings. A Raspberry Pi serves as the main hub, running a Tomcat 10 server, receiving the datagrams, and using Charts.js to make a clear and interactive graph with points and timestamps - a surefire path to a good night's sleep.

While unexpectedly toiling for me to create (curse you Linux!), this is actually very simple to run and delivers useful results. I am aware of software such as HomeAssistant, which may be able to do the basic task of sensor monitoring and graph creation, but I chose not to use it for two reasons. First, customization and expansion are limited; with my custom solution fully open source on GitHub, this project can grow and thrive. Second, there isn't much learning to be done working with built-out software. Alternatively, with this project comes server deployment, microcontroller programming, deploying Web Apps, and so much more!

This isn't the final product, but just the beginning; I plan to expand and improve it in the future!

Supplies

1000006671.jpg

For this project, you’ll need the following components. The variable n represents the number of rooms or locations you want to monitor.


Hardware:

1 × Raspberry Pi (Model 3 or higher, with Raspberry Pi OS installed and updated)

n × ESP8266 microcontrollers

n × DHT22 digital temperature & humidity sensor boards

n × Male-to-Female jumper wires (3 per DHT22, usually included with sensor boards)

n + 1 × Micro-USB wall adapters (one for each ESP8266 plus one for the Raspberry Pi)

1 × USB drive (to transfer files to the Pi)

1 × Monitor (for using Raspberry Pi)

1 × USB/Bluetooth keyboard and mouse (for using Raspberry Pi)

1 × HDMI Cable (for connecting Raspberry Pi to monitor)

1 × Ethernet cable (to connect the Pi to your router)

1 × Computer

1 × Wi-Fi router and network


Software:

Arduino IDE

Install Tomcat and Java on the Raspberry Pi

20250824_19h46m51s_grim.png

First, we need to get Java and Tomcat running on the Raspberry Pi, since Tomcat is the server that will host the Climate Web App.


1. Update the Pi

Open a terminal on your Pi and run:

sudo apt update && sudo apt upgrade -y


2. Install Java

Tomcat 10 requires Java 11 or newer. This project uses Java 17. Install OpenJDK with:

sudo apt install openjdk-17-jdk

Now check if it's successful (it should show that Java 17 is installed):

java -version


3. Install Tomcat 10

sudo apt install tomcat10


4. Verify Tomcat is Running

After installation, Tomcat 10 should start automatically. Check with:

systemctl status tomcat10

Just to be sure, we can see if it shows up in a browser. Enter the following in the search bar:

http://localhost:8080


After this, you should see the Tomcat 10 welcome page. Congrats, you just set up the server! Now it's time to deploy the Web App.

Deploy the Climate Web App

20250824_20h03m16s_grim.png

Now that Tomcat 10 is running on the Pi, it’s time to deploy the Climate Web App.


1. Grab The Web App Folder

First, visit the GitHub repository for this project. All files and code that will be used are here:

https://github.com/AIM-Industries/Climate_IoT_System

Click the arrow on the green Code button, and download the .zip file. Unzip the file, and copy/paste just the folder named climate to the USB drive. This is the Web App to be deployed.


2. Stop Tomcat 10

To stop the Tomcat 10 server and prepare for deployment, enter:

sudo systemctl stop tomcat10


3. Copy The Web App Into Tomcat 10

Plug in your USB drive, and locate it in the files. It will be under /media. Remember its path, then enter:

sudo cp -r /media/{usb drive path}/climate /var/lib/tomcat10/webapps/


4. Start Tomcat 10

sudo systemctl start tomcat10


5. Verify Deployment

Just like last time, enter the following in the Pi's search bar:

http://localhost:8080/climate

If you don't see any graphs, find /var/lib/tomcat10/webapps/ and make sure climate is inside here next to a folder called ROOT. If only ROOT is found, climate was not successfully copied over.


After this, instead of the Tomcat 10 welcome page, you should see two empty graphs, one for temperature and one for humidity. If so, the Web App is successfully deployed! Now, we need to make sure the Pi creates a hotspot and starts it whenever it boots, so we don't have to do this manually each time.

Set Up Raspberry Pi As a Hotspot (with Auto-Start)

Screenshot 2025-08-24 202135.png

This step lets your ESP8266 boards connect directly to the Raspberry Pi, even if there’s no regular Wi-Fi. The Pi becomes its own Wi-Fi hotspot, and we’ll make sure it starts automatically every time the Pi boots.


Because this is the most confusing step, I included numbers in the order of clicking. While not absolute, it should give you a good idea of where to go next if you're stuck. After all, a picture is worth a thousand words!


1. Create The Hotspot

On the top right of the Pi interface, there is a Wi-Fi symbol (1). Click on it, click Advanced Options (2), then click Create Wi-Fi Hotspot (3).

You will now see a menu (4), fill it accordingly:

  1. For Connection, select New
  2. For Network name, type Climate or something similar if preferred
  3. For Wi-Fi security, select WPA & WPA2 Personal
  4. For Password, type cl!mate123 or one that you will remember

Finally, click Create, and you have made the hotspot.


2. Auto-Start The Hotspot

First, click the Wi-Fi symbol and Advanced Options again. Then, click Edit Connections (5). This pulls up a tab with all your Wi-Fi connections saved. Double-click on all networks (6) that are not Climate, and untick the option Connect Automatically With Priority (7, 8). Finally, tick the same setting on for Climate. Just to reiterate, Climate should be the only saved network with this option ticked on.


3. Test Auto-Start

Reboot the Pi and make sure that the hotspot is automatically the active Wi-Fi. If the Pi doesn’t start the hotspot, double-check that other Wi-Fi networks are unticked in priority or retrace your steps.


Now, the Pi is hosting its own hotspot and turning it on whenever it starts. At this point, the Pi is fully self-sufficient, and it's time to set up our sensors.

Wire the ESP8266 and DHT22

Screenshot 2025-08-22 223229.png
1000006669.jpg

Welcome to the easiest step! Before uploading code, let’s wire the DHT sensor to the ESP8266.


1. Wire The DHT22 To The ESP8266

Grab your jumper wires, and make the following connections:

  1. DHT VCC 3.3V pin on ESP8266
  2. DHT GND GND pin on ESP8266
  3. DHT DATA D5 pin on ESP8266

Double-check that you have done this correctly and that all wires are secure and fully inserted.


2. Power The ESP8266

Plug your USB to Micro-USB cable into your computer, and connect the micro-USB end to the one on the board. If powered correctly, an onboard blue light flashes briefly when plugged in. Note that only if the board already has running code on it, a faint blue light will show. However, don't expect this light to be super bright like seen on other microcontrollers.


Now the ESP8266 is wired and ready for programming.

Open the Code in Arduino IDE and Upload to ESP8266

Screenshot 2025-08-24 204225.png

With the wiring complete, it’s time to load the code onto the ESP8266.


1. Make Arduino IDE Compatible With ESP8266

Simply follow this Instructable up to step 11:

https://www.instructables.com/Steps-to-Setup-Arduino-IDE-for-NODEMCU-ESP8266-WiF/


2. Install The Necessary Libraries

In Arduino IDE's Library Manager (bookcase icon on the leftmost menu), install the latest version of the following libraries:

  1. Adafruit Unified Sensor by Adafruit
  2. DHT sensor library by Adafruit


3. Open the Code

In Arduino IDE, click on File, then Open. In the folder previously downloaded from the project's GitHub repository, navigate to the file named esp8266-climate.ino- select it and press enter. Just in case, here is the link to the repository again:

https://github.com/AIM-Industries/Climate_IoT_System


4. Change Values In Code

There are a few variables you need to change in the code. These values are the first 3 variables located underneath the library import statements. First, you need to set the ssid and password variables to the name of the Pi's hotspot and it's password set earlier, accordingly:

// ===== USER CONFIG (enter values in quotations) =====
const char* ssid = ""; // <-- enter wi-fi name from earlier (ex: Climate)
const char* password = ""; // <-- enter wi-fi password from earlier (ex: cl!mate123)

Next, you need to decide whether you want a reading every 1 or 5 minutes, and set the INTERVAL_MINUTES value accordingly:

// Minutes between sampling (replace number)
#define INTERVAL_MINUTES 1 // <-- set to 1 or 5


5. Upload Sketch

Click the arrow icon in the top left to upload the sketch. Once done, the ESP8266 should slow blink while it's trying to connect to Wi-Fi. You can also use the serial monitor at 115200 Baud for text updates. When connected to Wi-Fi, the light will fast blink 3 times. If this happens, that means the board is successfully connected to the Pi! If not, it's likely the password or SSID is incorrect. Additionally, the light will blink each time data is sent for visual confirmation.


6. Calibrate

This step only applies if you are reading data every 5 minutes. In order to get readings that are cleaner or on the 5-minute mark (4:00, 4:05, 4:10, etc.), you need to do this step. After finalizing placement of the board in your house, wait until just after the clock reaches a 5-minute mark (4:00:01 or 4:05:01) and then press the RST button on the board. This will ensure the internal clock will always send the data at these intervals.


Now your ESP8266 is actively sending temperature and humidity data to your Raspberry Pi server! You can now independently situate the boards anywhere in your house with the Micro-USB wall adapter. The final step is viewing the data on any device.

Plug in the Pi and View the Graph in Your Browser

Screenshot 2025-08-24 190637.png
Screenshot 2025-08-24 190223.png

With Tomcat running on the Raspberry Pi and your ESP8266 sending data, the final step is to connect everything and see the results.


1. Hook Up The Pi To The Router

Use your Ethernet cable and connect the Pi to your home Wi-Fi router. Make sure to also power the Pi separately, as done before.

Important note: If you have a firewall, make sure to allow access to ports 8080 and 8081, or else this project will not work!


2. Find The Pi’s IP Address

Every router or network has its own interface, but the process is generally the same. Log in to your router’s administration page and look for the section that lists all devices currently connected to your network. Locate your Raspberry Pi in the list (it may appear as “raspberrypi” or a similar name) and note its IP address.

To avoid issues in the future, configure your router to reserve this IP address for the Pi. This ensures that the Pi’s address will remain the same even after it disconnects or reboots.


3. Open the Web App In A Browser

You can now access the Web App from any device on the same network. To do this, enter the following in a browser search bar:

http://{pi-ip}:8080/climate

Note: If the page doesn’t load, check that Tomcat is running (systemctl status tomcat10) and that your firewall allows ports 8080 and 8081.


You should now see the same graphs from before pop up. If everything is correct, data points should begin to propagate to both graphs on a page refresh. Data points will disappear after 48 hours so as not to cause a data leak. With this, the project is concluded. Congrats! Now you have a fully functional live climate monitoring system.


After running it in my room, I found that the results were undeniable. On some nights, my room was a whole 8 degrees Fahrenheit warmer at night than the rest of the house, which was proof that the heat wasn't just "in my head". With this data, I easily secured a more rigorous running of the AC in the twilight hours. Mission accomplished.

Troubleshooting and Tips

Screenshot 2025-08-24 204510.png

Even if you follow all the steps carefully, things don’t always work the first time. A lot of these are mentioned throughout the steps, but it's good to have them all in one place for easier debugging. Thankfully, being a relatively simple project means that there aren't too many places things can go wrong. Here are a few common problems and quick fixes:


1. Tomcat Page Doesn’t Load

First, on the Pi, check that Tomcat is running:

systemctl status tomcat10

Tomcat runs as a service on the Raspberry Pi, so as long as you start it before shutting it down, it should restart automatically on boot. If it’s not active, start it with:

sudo systemctl start tomcat10

If you’re on another device, make sure you use the Pi’s IP address (not localhost). Example:

http://192.168.1.42:8080/climate


2. ESP8266 Won’t Connect To Wi-Fi

Double-check that the ssid and password in your Arduino code match exactly (case-sensitive) to what you set on the Pi. This is the most likely error.

First, start a hotspot from the Pi. See if it shows up and see if you can connect to it with a phone or computer. If this works, then reboot the Pi and try again. If these don't work, you have isolated the issue is with the Pi, so return to step 3 and try again.

Next, try connecting to your home Wi-Fi network using its credentials with the ESP8266 code. If it can't connect, it's likely the ESP8266 is defective. Try replacing and trying again.

It's also possible that using a cheap power source or adapter for either the ESP8266 or Pi will result in unstable power and a host of issues. However, the Low Voltage Warning on the Pi does not necessarily mean that powering is the issue; these devices are known to alert even when powered adequately or even with an official power supply.


3. Points Aren't Showing, Or Data Is Highly Inaccurate

The most common issue is a defective DHT22 sensor or wiring. The DHT22 itself is a pretty finicky board, but the wires that are included with it are extremely cheap and have been the issue for me before. The best solution is to try a new DHT22, then try new wires, then both. Also, make sure to use the Arduino serial monitor at 115200 to see if the DHT22 can be read and if the samples taken 2 seconds apart are vastly different. The serial monitor is one of the best tools for debugging.

Also consider placement; if the readings are not extremely variable but instead higher or lower than expected, there may be unwanted and unexpected influence. If kept near a computer or appliance, heat from radiance or a fan may warm up the module. If the temperature is high and the humidity is low, this is 100% the case. Likewise, air from a fan or vent may yield the opposite result and display much lower temperatures than expected.


4. Clear Data

If you want to remove all stored graph data and clear the charts, use the following command on the Pi:

sudo rm /var/cache/tomcat10/climate-data/data.json


Please leave any further problems in the comments; I will be active and helpful!

Future Improvements

Screenshot 2025-08-25 215503.png

This is only V1. I plan to keep developing this project; here are some improvements I have in mind in relative order:


1. Wall Socket Case

This involves a standard wall plug to Micro-USB, which will sit in a 3D printed case along with the DHT22 and ESP8266 boards. My goal is a sleek, seamless, and compact solution that will occupy a single outlet and shield the sensor from temperature interference, such as fans or airflow.


2. Friendlier Local URL

This would allow typing a keyword such as climate.local instead of using the Pi's IP to access the web page locally.


3. Device Naming

This would allow you to name your device and save your choices, giving the sensors a friendlier name on the graph.


4. No ESP8266 Calibration

The ESP8266s should be able to sync time with the Pi, and also the Pi should be able to sync time through the internet. The datagrams should also not all be sent at once, so as not to cause issues with receiving.


5. Long-Term Data Storage And Access

Right now, the climate data is written to a file private to the Tomcat user, making it hard to access. Additionally, data is deleted after 48 hours. I want to instead write the data to an external drive or the cloud so it is easily accessible, persistent, and usable for data processing or AI use cases.


6. Settings

With this, Fahrenheit, Celsius, and Kelvin (for the nerds) can be toggled in the webpage with persistent storage of the settings (remembering what you selected last time). Also, the data sending intervals should be able to be set from here too, and all ESP8266s updated live. This is definitely easier said then done.


7. Truly Live Data

Right now, the page has to be refreshed to show new data. I would like the page to automatically refresh the graphs as new data is found. This is more of a QOL (quality of life) change, but it would take the project's sophistication up a level.


Let me know what else you are looking for in the comments! If I like it and people agree, I will add it to this page.