Share:

IoT Climate Monitoring System Using Raspberry Pi and ESP8266

نظام إنترنت الأشياء (IoT) لمراقبة المناخ باستخدام Raspberry Pi و ESP8266

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:

  1. 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.
  2. 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.

  1. Update the operating system: Open the terminal on Raspberry Pi and execute the following command:sudo apt update && sudo apt upgrade -y
  2. Install Java: Tomcat 10 requires Java version 11 or higher; this project uses Java 17. Install OpenJDK using:sudo apt install openjdk-17-jdk Verify the installation succeeded by checking the version:java -version
  3. Install Tomcat 10: Install the application server:sudo apt install tomcat10
  4. Check if Tomcat is running: Tomcat 10 should start automatically after installation. Check its status with:systemctl status tomcat10 To confirm, open the browser and enter the address:http://localhost:8080 When 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:

  1. 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.
  2. Stop Tomcat 10: To prepare the server for deployment, temporarily stop the Tomcat 10 service using the command:sudo systemctl stop tomcat10
  3. 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/
  4. Start Tomcat 10: Restart the server to complete the deployment process: sudo systemctl start tomcat10
  5. Verify Successful Deployment: To ensure the application is available, enter the following address in the Raspberry Pi browser:http://localhost:8080/climate If 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:

  1. 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.
    • Click on Create to create the hotspot.
  2. 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 Climate network only, to ensure it connects automatically as a priority on startup.
  3. 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:

  1. 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.
  2. 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:

  1. 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.
  2. 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).
  3. Open the Code File: Open the file named esp8266-climate.ino located in the folder downloaded earlier from the GitHub repository.
  4. Adjust variables in the code: The first three variables located under the library import statements should be modified:
    • Set the value of the variable ssid to match the Raspberry Pi hotspot name created earlier.
    • Set the value of the variable password to match the Raspberry Pi hotspot password.
    • Set the value of the variable INTERVAL_MINUTES to either 1 or 5 to determine the time interval for each sampling and data sending.
  5. 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.
  6. 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:

  1. 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.
  2. 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.
  3. 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.

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:

  1. 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.
  2. Easy Local URL: Allow access to the web page locally by typing a simple name like climate.local instead of using an IP address.
  3. Device Naming: Develop a system that allows naming sensors on the graph with user-friendly names of the user’s choice.
  4. 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.
  5. 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.
  6. 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.
  7. 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


أكثر هواتف آيفون مبيعاً

إعلان الهاتف

آيفون 16 128 جيجابايت

آيفون 16 128 جيجابايت

يُقدم هاتف iPhone 16 تجربة ممتازة تجمع بين الأداء القوي والتصميم العملي، مدعوماً بمعالج A18 المصمم خصيصاً لدعم مهام الذكاء الاصطناعي (Apple Intelligence). ويأتي بشاشة Super Retina XDR زاهية، إلى جانب زر التحكم بالكاميرا الجديد (Camera Control) الذي يمنح المستخدمين وصولاً سريعاً وسلساً لالتقاط الصور والفيديوهات.

ملخص آراء أشهر المواقع التقنية

"معالج A18 القوي يوفر سرعة هائلة وأداءً سلساً للغاية في تشغيل التطبيقات والألعاب الحديثة دون أي تأخير."

TrustedReviews
★★★★★

"زر التحكم في الكاميرا الجديد يضيف لمسة عملية رائعة ومبتكرة تسرع من عملية التصوير باحترافية."

TechRadar
★★★★☆

"عمر البطارية شهد تحسناً ملحوظاً مقارنة بالأجيال السابقة ليصمد بكفاءة طوال اليوم."

The Verge
★★★★★

المميزات

  • معالج Apple A18 القوي الذي يضمن كفاءة عالية في استهلاك الطاقة ودعم كامل لتقنيات الذكاء الاصطناعي.
  • زر التحكم الجديد في الكاميرا (Camera Control) للوصول السريع والتحكم الدقيق بالإعدادات والتصوير.
  • شاشة Super Retina XDR ساطع وعالية الوضوح تقدم ألواناً دقيقة ورائعة.
  • نظام كاميرا خلفية مزدوج محسن بدقة 48 ميجابكسل مع عدسة فائقة الاتساع تدعم التصوير الماكرو.
  • زر الإجراءات (Action Button) القابل للتخصيص لتنفيذ المهام السريعة بضغطة واحدة.

العيوب

  • الشاشة لا تزال تقتصر على معدل تحديث 60 هرتز، وهو أمر مخيب للآمال مقارنة بالهواتف المنافسة في نفس الفئة السعرية.
  • سرعات الشحن السلكي واللاسلكي تعتبر بطيئة نسبياً مقارنة بما تقدمه الهواتف المنافسة في السوق.
  • التصميم الخارجي والشكل العام يشبهان إلى حد كبير الجيل السابق مع تغييرات طفيفة تتركز في تصميم الكاميرا الخلفية.

مواصفات الهاتف

اسم المنتج بالعربيآيفون 16
اسم المنتج بالإنجليزيiPhone 16
تاريخ التوفر20/09/2024
الشركة المصنعةapple
نظام التشغيلiOS 18, قابل للتحديث لـ iOS 26.5
المعالجApple A18 3 نانومتر Hexa-core (2x4.04 GHz + 4x2.20 GHz)
ذاكرة RAM8GB
سعة التخزين128GB
حجم الشاشة6.1 بوصة
الكاميرا الخلفية48 ميجابكسل f/1.6
الكاميرا الأمامية12 ميجابكسل f/1.9
الصوتستيريو
وصلة سماعة 3.5غيرمتوفر
البطاريةLi-Ion 3561 ميللي أمبير
الشحن اللاسلكيمدعوم 25W
الألوان المتوفرةأسود/أبيض/زهري/أخضر فاتح Teal/أزرق بحري Ultramarine

إعلان الهاتف

آيفون 17 برو ماكس

آيفون 17 برو ماكس

يُعد هاتف iPhone 17 Pro Max قمة ما توفره أبل في عالم الهواتف الذكية، حيث يجمع بين التصميم العصري الجذاب بلونه البرتقالي الكوني والأداء الفائق بفضل معالج A19 Pro. ويقدم الهاتف تجربة بصرية مذهلة عبر شاشة Super Retina XDR العملاقة بحجم 6.9 بوصة، مدعومة بمنظومة تصوير متطورة تلبي طموحات عشاق المحتوى الاحترافي.

ملخص آراء أشهر المواقع التقنية

"«الشاشة الكبيرة والساطعة بحجم 6.9 بوصة تجعل مشاهدة المحتويات والألعاب تجربة غامرة بحق.»"

TrustedReviews
★★★★☆

"«نظام الكاميرات الثلاثي بدقة 48 ميجابكسل يقدم تفاصيل مذهلة وثباتاً استثنائياً في تصوير الفيديو الاحترافي.»"

TechRadar
★★★★☆

"«البطارية القوية مع معالجة الحرارة المحسنة تضمن أداءً مستداماً وطويلاً طوال اليوم دون أي تباطؤ.»"

The Verge
★★★★☆

المميزات

  • شاشة LTPO OLED فائقة السطوع بحجم 6.9 بوصة تدعم معدل تحديث 120 هرتز وتقنية Dolby Vision.
  • معالج Apple A19 Pro القوي المصمم بدقة 3 نانومتر لتقديم أداء سلس ومعالجة متقدمة لمهام الذكاء الاصطناعي.
  • منظومة كاميرات خلفية ثلاثية بدقة 48 ميجابكسل مع تقريب بصري محسن وكاميرا أمامية مبتكرة.
  • نظام تبريد متطور (غرفة بخار) يحافظ على استقرار الأداء وثباته خلال الاستخدام المكثف والألعاب.
  • عمر بطارية طويل ودعم للشحن السريع واللاسلكي المطور عبر تقنية MagSafe.

العيوب

  • الوزن والحجم الكبيران قد يجعلا استخدام الهاتف بـيد واحدة أمراً شاقاً وغير مريح لبعض المستخدمين لفترات طويلة.
  • ارتفاع السعر بشكل ملحوظ لكونه الإصدار الرائد الأعلى في عائلة أبل.
  • غياب مفردات التخزين القابلة للتوسعة (لا يدعم بطاقات الذاكرة الخارجية MicroSD).
  • سرعات الشحن السلكي واللاسلكي -رغم تحسنها- لا تزال تتخلف عن بعض الهواتف المنافسة في الفئة الرائدة.
  • خيارات التقريب البصري ما زالت تحتاج لتطوير أكبر لتنافس بعض القدرات الفائقة الموجودة لدى المنافسين.

مواصفات الهاتف

العنصرالمواصفات
المعالجشريحة A19 Pro وحدة معالجة مركزية مع 6 نوى
الكاميرا الخلفية48 ميجابكسل
سعة التخزين256 جيجابايت
حجم الشاشة6.9 بوصة
دقة الشاشة2868 × 1320
اسم الموديلiPhone 17 Pro Max
شبكة الاتصالمفتوح لجميع شبكات الاتصال
تقنية الاتصال الخلوي5G
تقنيات الاتصالBluetooth، NFC، USB، Wi-Fi
اللونبرتقالي كوني (Cosmic Orange)
Shopping Cart
×