In the rapidly evolving world of Internet of Things (IoT), innovative solutions are transforming how we collect and analyze environmental data. Our project demonstrates a simple yet powerful wireless sensor network "ESP-NOW" using ESP32 microcontrollers, showcasing the potential of low-power, efficient IoT systems with advanced visualization using Node-RED.
Project OverviewWe set out to create a wireless sensor network that could: - Collect temperature and humidity data - Transmit information wirelessly - Provide real-time data visualization - Maintain energy efficiency.
System ArchitectureOur network consists of four key components:
1.Slave Nodes (2 - ESP32s): Equipped with DHT11 sensors to collect environmental data.
2.Master Node (1 - ESP32): Acts as a bridge, receiving and forwarding sensor data.
3. Python Client (Laptop): Collects data from the Master node and publishes the MQTT topics to the MQTT broker.
4.MQTT Broker: Subscribes the temperature and Humidity topics from the python client and publishes to Node-RED.
5. Node-RED Dashboard: Connected via MQTT-In node and visualizes the sensor readings.
Communication Protocols:
ESP-Now: Lightweight Wireless Communication: ESP-Now enables direct, energy-efficient communication between ESP32 devices. Unlike traditional WiFi, it minimizes power consumption supports reliable peer-to-peer connections enables low-latency data transmissions.
MQTT: Efficient Data Publishing: The Message Queuing Telemetry Transport (MQTT) protocol allows to publish sensor data to a central broker enable easy subscription by multiple clients support real-time data updates with minimal overhead.
Data Visualization with Node-RED: Node-RED provides a powerful, visual approach to data processing and visualization. Receives data from four MQTT topics creates separate charts for temperature and humidity offers real-time interactive dashboards enables easy data manipulation without complex coding.
Hardware and Software Setup:Hardware Setup:
Node-RED Flow Diagram:
1. Program Slave nodes to collect sensor data.
2. Configure Master node to receive and forward data.
3. Create a python file to collect sensor readings from master node com-port.
4. Set up MQTT broker (broker.mqtt.cool).
5. Create Node-RED dashboard for visualization.
How It Works?The system is designed as a wireless sensor network for monitoring temperature and humidity. Comprising sensing nodes, a master node, a python client, and MQTT integration. Here’s a step-by-step explanation of the system's workflow:
1. Sensing Nodes (Node 1 and Node 2):
Components: Each sensing node consists of an ESP32 microcontroller and a DHT11 connection.
Functionality:
- The sensing nodes collects real-time temperature and humidity data using the DHT11 sensor.
- This data is packaged into a structured message that includes:
- The node ID (e.g., Node 1 or Node 2).
- Temperature and humidity values.
- The sensing nodes use the ESP-Now protocol to send this data wirelessly to the Master Node with a Communication interval of 3.5 secs.
Power Efficiency:
Sensing nodes enter deep sleep mode when not collecting or transmitting data, conserving battery power.
2. Master Node (ESP32):
The Master Node serves as the bridge between the sensing nodes.
Functionality:
- It receives data from the sensing nodes via ESP-Now.
- After processing and validating the received data, it prints the data to the serial monitor.
- The Master Node ensures reliable aggregation of data from multiple sensing nodes.
3. Python Client (Laptop)
Acts as the intermediary between the Master Node and the MQTT broker. It collects the sensor readings from the com-port where the master node is connected.
Functionality:
- The Python client collects the data forwarded by the Master Node via serial communication.
- It processes the data and publishes it to the MQTT broker
- Topics used include:
- - esp/now/slave1/temp for temperature data for Node 1
- - esp/now/slave1/humidity for humidity data for Node 1
- - esp/now/slave2/temp for temperature data for Node 2
- - esp/now/slave2/humidity for humidity data for Node 2
4. MQTT Broker:
Manages the communication between the Python client and any subscriber (e.g., Node-RED).
Functionality:
- The MQTT broker subscribes data from the Python client.
- It hosts the topics to clients, such as the Node-RED dashboard, which subscribes to retrieve real-time sensor data.
- This enables seamless data exchange and real-time updates.
5. Node-RED Dashboard
Provides a user-friendly interface for visualizing the sensor data real-time.
Functionality:
- Node-RED subscribes to the MQTT topics published by the broker (esp/now/slaves/temperature and humidity).
- It displays the temperature and humidity data on an interactive dashboard, allowing users to monitor the readings in real-time.
- Additional features, such as alerts for temperature or humidity thresholds, can be integrated into the dashboard.
- Node 1 measures a temperature and humidity, sends the data to the Master node via ESP-Now in real-time.
- Node 2 measures a temperature and humidity, sends the data similarly.
Temperature and Humidity Graph:
To extend battery life:
- Slave nodes enter deep sleep mode when not actively collecting or transmitting data.
- ESP-Now ensures low-power communication, optimizing energy use for long-term operation.
Let's See how our Energy efficiency is calculated:
1. Power Consumption Components.
- DHT11 Sensor: 0.5-1.5mA
- ESP32 Active Mode: 80-120mA
- ESP32 Deep Sleep: 5-10µA
- ESP-Now Transmission: 20-35mA
2. Detailed Energy Budget Calculation Formula: E = P*t
- Active Energy: 90mA * 0.5s = 45mWs
- Sleep Energy: 0.01mA * 3s = 0.03mWs
- Transmission Energy: 30mA * 0.1s = 3mWs
3.Current Consumption Calculation Formula: Iavg = (Iactive * Tactive + Isleep * Tsleep) /Ttotal
Given:
- Active Current (Iactive) = 90mA
- Sleep Current (Isleep) = 10µA = 0.01mA (time spent in low-power deep sleep mode)
- Active Time (Tactive) = 0.5s (time spent performing active tasks like sensor reading and processing)
- Sleep Time (Tsleep) = 3.5s
- Total Cycle Time (Ttotal) = Active Time + Sleep Time
=0.5s+3.5s
= 4.0seconds
Calculation:
Iavg = [(90mA * 0.5s) + (0.01mA*3.5s)]/4s
= [45+0.035]/4
= 11.25mA
4. Duty Cycle Calculation
Duty Cycle = (Tactive/Ttotal) * 100%
= (0.5s/4s) *100%
= 12.5%
5. Battery Life Estimation Assumptions:
- Battery Capacity = 2000mAh
- Average Current = 12.87mA
- Conversion Factor for years: 24 * 365 = 8760 hours
Battery Life = Battery Capacity / (Average Current * Hours per Year)
= 2000mAh/ (12.87mA * 8760)
= 0.0177 years
= 0.212 months
Battery Life (hours) = 2000 mAh / 12.87 mA
≈ 155.4 hours
Then convert hours to days:
Battery Life (days) = 155.4 / 24
≈ 6.475 days
Therefore, Energy Efficiency Metrics:
- Power Saving: 85.71%
- Daily Energy Consumption: 12.87 mA * 24h = 309.28mAh
- Theoretical Battery Lifespan: 2000 mAh / 309.28 mAh / day = 6.47 days
- Number of Cycles per Day = 24 * 60 * 60 / 4
= 21, 600 cycles per day
- Total Active Time per Day = 21, 600 * 0.5s
= 180 minutes
= 180 minutes
= 3 hours
- Total Active Time per Year = 3 hours /day * 365
= 1095 hours per year
≈ 65, 700 minutes per year
Challenges and Solutions:Throughout the project, we encountered and overcame several technical challenges:
1. ESP-Now Initialization: Resolved by carefully managing WiFi mode and implementing retry mechanisms.
2. Packet Loss: Mitigated through optimized packet size and checksums.
3. MQTT Connection Stability: Addressed by adding automatic reconnection logic.
4. Power Consumption: Implemented deep sleep mode on Slave nodes.
5. Data Visualization: Simplified through Node-RED’s intuitive interface.
Limitations:1. Deep Sleep Challenges- Delayed Data: Since the ESP32 spends most of its time in deep sleep to save power, it won't immediately detect or send data when an event (like a temperature spike) occurs. This delay can be problematic for time-sensitive alerts.
- Synchronization Issues: If the ESP32’s clock drifts, it might wake up at the wrong time and miss its transmission window, causing gaps in the data.
- Event Loss: Any significant environmental changes during sleep are missed until the node wakes up again.
- But in our setup, we didn't face this issue.
- Manual Setup Required: If you want to add another sensor node to the network, you’ll need to manually configure the master node to recognize the new device by its MAC address. This can become tedious.
- Limited Network Size: ESP-Now can only support a limited number of devices (typically around 10–20). Adding too many nodes may lead to communication issues like collisions or delays.
- Potential Bottleneck: As you increase the number of nodes, the master node could experience slower response times or difficulty managing all connections.
- No Plug-and-Play: Each time a new node is added, the master node must be reprogrammed or manually adjusted to include the new device. This isn’t automated, so it requires technical know-how.
- Scalability Issues: If you plan to expand your network, you’ll have to keep updating the master node configuration, which becomes cumbersome as the network grows.
- Manual Thresholds: Alert thresholds (e.g., for temperature or humidity) are predefined in the code or Node-RED. Adjusting these means diving into the code or dashboard configuration, which is time-consuming.
- Static Configuration: You can’t dynamically update thresholds or alert settings from a remote location without modifying the setup.
- Effort for Integration: Node-RED or similar tools require manual setup to link alerts to MQTT topics or other actions (like email notifications). This adds complexity for non-technical users.
- Manual Configuration for New Nodes: Every time a new node is added, you must manually create new MQTT topics and configure Node-RED workflows for the data. This becomes increasingly labor-intensive as the system grows.
- Lack of Automation: There's no built-in mechanism to automatically handle new nodes or topics, requiring repetitive effort for each addition.
- Scalability Issues: Managing a large number of nodes, topics, and dashboards manually can lead to errors and become overwhelming.
If you're working with a small number of sensor nodes, these issues might seem manageable. But as you scale up, the manual setup and reconfiguration required for each new node, alert, or topic can quickly become a bottleneck. Additionally, time-sensitive data might be delayed due to deep sleep, and maintaining an efficient communication network becomes harder as the number of devices grows.
Suggestions for Improvement:- Optimize Deep Sleep: Use event-driven wake-up mechanisms (like interrupts) so the ESP32 can wake up immediately when needed, rather than waiting for the timer.
- Automate Node Setup: Implement a way for the system to automatically detect and register new nodes, reducing the need for manual reconfiguration.
- Simplify Alerts: Allow remote updates to alert thresholds and configurations through MQTT or a web interface, so you don’t need to modify code or dashboards.
- Centralized Management: Use tools like Grafana or ThingsBoard to manage nodes, topics, and alerts from a single interface, making it easier to scale the system.
By addressing these challenges, you can make your system more efficient, scalable, and user-friendly, especially as you add more devices or adjust your network.
Future Work and Potential Expansions:Our project opens doors to exciting possibilities:
- - Cloud platform integration - Mobile application development.
- - Expanding sensor capabilities.
- - Exploring energy harvesting technologies.
- - Implementing advanced data logging.
- - Enhancing communication security.
- - Creating more complex Node-RED dashboards.
This project demonstrates the power of IoT in creating efficient, scalable sensor networks by combining ESP32 with ESP-Now, MQTT, and Node-RED, we’ve built a flexible system with applications in environmental monitoring, smart homes, and industrial IoT in real-time.
The journey highlights the importance of innovative design, problem-solving, and continuous learning in technology development.
Happy Exploring!
Comments
Please log in or sign up to comment.