MDM331AID/Experiment 5: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
= Experiment: Wi-Fi Connectivity and TCP/IP-Based Sensor Data Transmission Using ESP32 = | |||
= Experiment: Wi-Fi Connectivity and TCP/IP-Based Sensor Data Transmission Using ESP32 | |||
== Aim == | == Aim == | ||
To configure and implement an IoT device using ESP32 | To configure and implement an IoT device using ESP32 to connect to a Wi-Fi network and transmit temperature and humidity data from a DHT11 sensor to a remote computer using TCP/IP communication. | ||
== Objectives == | == Objectives == | ||
* To understand Wi-Fi connectivity in IoT devices. | * To understand Wi-Fi connectivity in IoT devices. | ||
* To interface a DHT11 temperature and humidity sensor with ESP32 | * To interface a DHT11 temperature and humidity sensor with ESP32. | ||
* To understand TCP/IP communication and socket programming. | * To understand TCP/IP communication and socket programming. | ||
* To establish a TCP connection between an | * To establish a TCP connection between an ESP32 and a remote computer. | ||
* To transmit and receive sensor data over a Wi-Fi network. | * To transmit and receive sensor data over a Wi-Fi network. | ||
| Line 23: | Line 22: | ||
|- | |- | ||
| 1 | | 1 | ||
| ESP32 Development Board (COG-E32 | | ESP32 Development Board (COG-E32) | ||
| 1 | | 1 | ||
|- | |- | ||
| Line 31: | Line 30: | ||
|- | |- | ||
| 3 | | 3 | ||
| USB | | USB Data Cable | ||
| 1 | | 1 | ||
|- | |- | ||
| 4 | | 4 | ||
| Patch | | Patch Cords | ||
| As required | | As required | ||
|- | |- | ||
| 5 | | 5 | ||
| Computer with Arduino IDE | | Computer with Arduino IDE | ||
| 1 | | 1 | ||
|- | |- | ||
| 6 | | 6 | ||
| Remote | | Remote Computer connected to the same Wi-Fi network | ||
| 1 | | 1 | ||
|- | |- | ||
| 7 | | 7 | ||
| Wi-Fi | | Wi-Fi Network | ||
| 1 | | 1 | ||
|} | |} | ||
| Line 57: | Line 56: | ||
An IoT device is a physical device equipped with sensors, processing capabilities, and communication interfaces. It collects data from its surroundings and transmits the information to another device or a remote server. | An IoT device is a physical device equipped with sensors, processing capabilities, and communication interfaces. It collects data from its surroundings and transmits the information to another device or a remote server. | ||
In this experiment, the ESP32 | In this experiment, the ESP32 acts as the IoT device. The DHT11 sensor collects temperature and humidity readings, which are transmitted to a remote computer. | ||
=== Wi-Fi Connectivity === | === Wi-Fi Connectivity === | ||
| Line 63: | Line 62: | ||
Wi-Fi is a wireless networking technology based on IEEE 802.11 standards. It allows IoT devices to connect to a local wireless network and exchange information with other devices. | Wi-Fi is a wireless networking technology based on IEEE 802.11 standards. It allows IoT devices to connect to a local wireless network and exchange information with other devices. | ||
The ESP32 has built-in Wi-Fi connectivity | The ESP32 has built-in Wi-Fi connectivity, making it suitable for IoT communication experiments without requiring an additional Wi-Fi module. | ||
=== TCP/IP Communication === | === TCP/IP Communication === | ||
| Line 73: | Line 72: | ||
* '''Socket:''' A software interface used by applications to send and receive data over a network. | * '''Socket:''' A software interface used by applications to send and receive data over a network. | ||
In this experiment, the remote computer runs a TCP server that listens for incoming connections. The ESP32 | In this experiment, the remote computer runs a TCP server that listens for incoming connections. The ESP32 acts as a TCP client and sends sensor readings to the server. | ||
The basic communication flow is: | |||
<pre> | |||
DHT11 Sensor | |||
| | |||
v | |||
ESP32 | |||
| | |||
v | |||
Wi-Fi Network | |||
| | |||
v | |||
Remote Computer | |||
| | |||
v | |||
TCP Server | |||
</pre> | |||
=== DHT11 Sensor === | === DHT11 Sensor === | ||
| Line 81: | Line 98: | ||
Typical measurement ranges are: | Typical measurement ranges are: | ||
* Temperature: | * Temperature: 0 C to 50 C. | ||
* Relative humidity: 20 | * Relative humidity: 20 percent to 90 percent. | ||
The DHT11 is suitable for basic environmental monitoring demonstrations. Its accuracy and measurement range are limited compared with more advanced sensors. | The DHT11 is suitable for basic environmental monitoring demonstrations. Its accuracy and measurement range are limited compared with more advanced sensors. | ||
| Line 93: | Line 110: | ||
v | v | ||
+----------------+ | +----------------+ | ||
| ESP32 | | ESP32 | | ||
| | | TCP Client | | ||
+----------------+ | +----------------+ | ||
| | | | ||
| Line 102: | Line 119: | ||
+----------------+ | +----------------+ | ||
| Remote Computer| | | Remote Computer| | ||
| TCP Server | | TCP Server | | ||
+----------------+ | +----------------+ | ||
| | | | ||
v | v | ||
Display Sensor | |||
Data | |||
</pre> | </pre> | ||
== Pin Connections == | == Pin Connections == | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 132: | Line 148: | ||
|} | |} | ||
'''Note:''' The connections assume a compatible DHT11 module with clearly identified VCC, DATA, and GND pins. Verify the actual sensor-board pinout before making the connections. | |||
'''Note:''' The connections assume a compatible DHT11 module with clearly identified VCC, DATA, and GND pins. Verify the actual sensor-board pinout | |||
== Software Requirements == | == Software Requirements == | ||
| Line 163: | Line 158: | ||
* DHT sensor library | * DHT sensor library | ||
* Wi-Fi library included with the ESP32 board package | * Wi-Fi library included with the ESP32 board package | ||
=== Remote Computer === | === Remote Computer === | ||
| Line 176: | Line 163: | ||
* Python 3 | * Python 3 | ||
* TCP server program | * TCP server program | ||
* Network access from the | * Wi-Fi connection | ||
* Network access from the ESP32 | |||
== Program 1: TCP Server on Remote Computer == | |||
The remote computer acts as a TCP server. It listens on port 5000 and displays the temperature and humidity data received from the ESP32. | |||
Download the program: | |||
[[Media:IoT_TCP_DHT11_Programs.zip|TCP Server and ESP32 Client Programs ZIP]] | |||
== Program 2: ESP32 TCP Client == | == Program 2: ESP32 TCP Client == | ||
| Line 189: | Line 178: | ||
The ESP32 connects to the Wi-Fi network, reads the DHT11 sensor values, and sends the readings to the remote computer using TCP. | The ESP32 connects to the Wi-Fi network, reads the DHT11 sensor values, and sends the readings to the remote computer using TCP. | ||
Download the program: | Download the program: | ||
[[Media:IoT_TCP_DHT11_Programs.zip|ESP32 TCP Client Program]] | |||
== Procedure == | == Procedure == | ||
| Line 201: | Line 187: | ||
# Connect the remote computer to the Wi-Fi network. | # Connect the remote computer to the Wi-Fi network. | ||
# Find | # Find the local IP address of the remote computer using the appropriate network command. | ||
# Replace the example IP address in the | # Replace the example IP address in the ESP32 client program with the remote computer's actual IP address. | ||
# Save the TCP server program as tcp_server.py. | # Save the TCP server program as tcp_server.py. | ||
# Run the server using Python: | # Run the server using Python: | ||
| Line 211: | Line 197: | ||
# Ensure that the firewall allows incoming TCP connections on port 5000. | # Ensure that the firewall allows incoming TCP connections on port 5000. | ||
# Keep the TCP server running while testing the ESP32. | |||
=== Step 2: Configure ESP32 === | === Step 2: Configure ESP32 === | ||
| Line 217: | Line 204: | ||
# Open Arduino IDE. | # Open Arduino IDE. | ||
# Install the DHT sensor library if it is not already installed. | # Install the DHT sensor library if it is not already installed. | ||
# Enter the Wi-Fi SSID | # Enter the Wi-Fi SSID and password in the ESP32 program. | ||
# Enter the remote computer's IP address in the ESP32 program. | |||
# Enter the TCP server port number in the ESP32 program. | |||
# Select the appropriate ESP32 board and COM port. | # Select the appropriate ESP32 board and COM port. | ||
# Upload the program. | # Upload the program. | ||
# Open the Serial Monitor at 115200 baud. | # Open the Serial Monitor at 115200 baud. | ||
# Observe the Wi-Fi connection status | # Observe the Wi-Fi connection status. | ||
# Observe the TCP connection status. | |||
# Observe the temperature and humidity values being transmitted. | |||
# | |||
# Observe the | |||
=== Step | === Step 3: Verify TCP/IP Communication === | ||
# Check that the remote computer reports an incoming TCP connection. | # Check that the remote computer reports an incoming TCP connection. | ||
# Observe the temperature and humidity data received by the server. | # Observe the temperature and humidity data received by the TCP server. | ||
# Compare the transmitted values with the sensor readings displayed by the | # Compare the transmitted values with the sensor readings displayed by the ESP32. | ||
# Stop the | # Verify that multiple sensor readings are received by the server. | ||
# Stop the ESP32 program or disconnect the device. | |||
# Observe the disconnection message on the TCP server. | |||
== Observations == | == Observations == | ||
| Line 249: | Line 228: | ||
|- | |- | ||
! Sr. No. | ! Sr. No. | ||
! Temperature ( | ! Temperature (C) | ||
! Relative Humidity ( | ! Relative Humidity (percent) | ||
! Transmission Status | ! Transmission Status | ||
|- | |- | ||
| Line 273: | Line 252: | ||
<pre> | <pre> | ||
TCP Server started | TCP Server started | ||
Waiting for | Waiting for ESP32 connection... | ||
Connected by: ('192.168.1.105', 54321) | Connected by: ('192.168.1.105', 54321) | ||
Received: Temperature: 28.0 C, Humidity: 65.0 % | Received: Temperature: 28.0 C, Humidity: 65.0 % | ||
| Line 284: | Line 263: | ||
== Result == | == Result == | ||
An IoT application was implemented using an ESP32 | An IoT application was implemented using an ESP32 and DHT11 sensor. The ESP32 successfully connected to a Wi-Fi network and transmitted temperature and humidity readings to a remote computer using TCP/IP socket communication. | ||
== Viva Questions == | == Viva Questions == | ||
# What is the role of Wi-Fi in an IoT application? | # What is the role of Wi-Fi in an IoT application? | ||
# What is TCP? | |||
# What is the difference between TCP and UDP? | # What is the difference between TCP and UDP? | ||
# What is an IP address? | # What is an IP address? | ||
| Line 295: | Line 275: | ||
# Why is TCP considered a reliable communication protocol? | # Why is TCP considered a reliable communication protocol? | ||
# What is the function of the bind() function in Python socket programming? | # What is the function of the bind() function in Python socket programming? | ||
# What is the purpose of the listen() | # What is the purpose of the listen() function? | ||
# What is the purpose of the accept() function? | |||
# What is the function of sendall() in Python? | # What is the function of sendall() in Python? | ||
# Why should the remote computer's IP address be configured in the | # Why should the remote computer's IP address be configured in the ESP32? | ||
# What is the difference between local and public IP | # What is the difference between a local IP address and a public IP address? | ||
# Why is port 5000 used in this experiment? | |||
# How can the application be extended to store sensor readings in a database or cloud platform? | # How can the application be extended to store sensor readings in a database or cloud platform? | ||
Revision as of 16:27, 7 October 2026
Experiment: Wi-Fi Connectivity and TCP/IP-Based Sensor Data Transmission Using ESP32
Aim
To configure and implement an IoT device using ESP32 to connect to a Wi-Fi network and transmit temperature and humidity data from a DHT11 sensor to a remote computer using TCP/IP communication.
Objectives
- To understand Wi-Fi connectivity in IoT devices.
- To interface a DHT11 temperature and humidity sensor with ESP32.
- To understand TCP/IP communication and socket programming.
- To establish a TCP connection between an ESP32 and a remote computer.
- To transmit and receive sensor data over a Wi-Fi network.
Components Required
| Sr. No. | Component | Quantity |
|---|---|---|
| 1 | ESP32 Development Board (COG-E32) | 1 |
| 2 | DHT11 Temperature and Humidity Sensor (COG-MSBA) | 1 |
| 3 | USB Data Cable | 1 |
| 4 | Patch Cords | As required |
| 5 | Computer with Arduino IDE | 1 |
| 6 | Remote Computer connected to the same Wi-Fi network | 1 |
| 7 | Wi-Fi Network | 1 |
Theory
Internet of Things (IoT) Device
An IoT device is a physical device equipped with sensors, processing capabilities, and communication interfaces. It collects data from its surroundings and transmits the information to another device or a remote server.
In this experiment, the ESP32 acts as the IoT device. The DHT11 sensor collects temperature and humidity readings, which are transmitted to a remote computer.
Wi-Fi Connectivity
Wi-Fi is a wireless networking technology based on IEEE 802.11 standards. It allows IoT devices to connect to a local wireless network and exchange information with other devices.
The ESP32 has built-in Wi-Fi connectivity, making it suitable for IoT communication experiments without requiring an additional Wi-Fi module.
TCP/IP Communication
TCP/IP is a protocol suite used for communication between devices over a network.
- IP (Internet Protocol): Provides addressing and routing of data packets between devices.
- TCP (Transmission Control Protocol): Provides reliable, ordered, connection-oriented data delivery.
- Socket: A software interface used by applications to send and receive data over a network.
In this experiment, the remote computer runs a TCP server that listens for incoming connections. The ESP32 acts as a TCP client and sends sensor readings to the server.
The basic communication flow is:
DHT11 Sensor
|
v
ESP32
|
v
Wi-Fi Network
|
v
Remote Computer
|
v
TCP Server
DHT11 Sensor
The DHT11 is a digital temperature and humidity sensor. It provides temperature and relative humidity readings through a single digital data interface.
Typical measurement ranges are:
- Temperature: 0 C to 50 C.
- Relative humidity: 20 percent to 90 percent.
The DHT11 is suitable for basic environmental monitoring demonstrations. Its accuracy and measurement range are limited compared with more advanced sensors.
System Architecture
DHT11 Sensor
|
v
+----------------+
| ESP32 |
| TCP Client |
+----------------+
|
Wi-Fi Network
|
v
+----------------+
| Remote Computer|
| TCP Server |
+----------------+
|
v
Display Sensor
Data
Pin Connections
| ESP32 Pin | DHT11 Pin | Description |
|---|---|---|
| 3V3 | VCC | Sensor power supply |
| GPIO 4 | DATA | Digital data interface |
| GND | GND | Common ground |
Note: The connections assume a compatible DHT11 module with clearly identified VCC, DATA, and GND pins. Verify the actual sensor-board pinout before making the connections.
Software Requirements
ESP32
- Arduino IDE
- ESP32 board support package
- DHT sensor library
- Wi-Fi library included with the ESP32 board package
Remote Computer
- Python 3
- TCP server program
- Wi-Fi connection
- Network access from the ESP32
Program 1: TCP Server on Remote Computer
The remote computer acts as a TCP server. It listens on port 5000 and displays the temperature and humidity data received from the ESP32.
Download the program:
TCP Server and ESP32 Client Programs ZIP
Program 2: ESP32 TCP Client
The ESP32 connects to the Wi-Fi network, reads the DHT11 sensor values, and sends the readings to the remote computer using TCP.
Download the program:
Procedure
Step 1: Configure the Remote Computer
- Connect the remote computer to the Wi-Fi network.
- Find the local IP address of the remote computer using the appropriate network command.
- Replace the example IP address in the ESP32 client program with the remote computer's actual IP address.
- Save the TCP server program as tcp_server.py.
- Run the server using Python:
<syntaxhighlight lang="bash"> python tcp_server.py </syntaxhighlight>
- Ensure that the firewall allows incoming TCP connections on port 5000.
- Keep the TCP server running while testing the ESP32.
Step 2: Configure ESP32
- Connect the DHT11 sensor to the ESP32 using the specified pin connections.
- Open Arduino IDE.
- Install the DHT sensor library if it is not already installed.
- Enter the Wi-Fi SSID and password in the ESP32 program.
- Enter the remote computer's IP address in the ESP32 program.
- Enter the TCP server port number in the ESP32 program.
- Select the appropriate ESP32 board and COM port.
- Upload the program.
- Open the Serial Monitor at 115200 baud.
- Observe the Wi-Fi connection status.
- Observe the TCP connection status.
- Observe the temperature and humidity values being transmitted.
Step 3: Verify TCP/IP Communication
- Check that the remote computer reports an incoming TCP connection.
- Observe the temperature and humidity data received by the TCP server.
- Compare the transmitted values with the sensor readings displayed by the ESP32.
- Verify that multiple sensor readings are received by the server.
- Stop the ESP32 program or disconnect the device.
- Observe the disconnection message on the TCP server.
Observations
| Sr. No. | Temperature (C) | Relative Humidity (percent) | Transmission Status |
|---|---|---|---|
| 1 | Record measured value | Record measured value | Successful / Failed |
| 2 | Record measured value | Record measured value | Successful / Failed |
| 3 | Record measured value | Record measured value | Successful / Failed |
Expected output on the remote computer:
TCP Server started
Waiting for ESP32 connection...
Connected by: ('192.168.1.105', 54321)
Received: Temperature: 28.0 C, Humidity: 65.0 %
Received: Temperature: 28.0 C, Humidity: 64.0 %
Received: Temperature: 29.0 C, Humidity: 64.0 %
The above values and IP addresses are illustrative examples, not actual measurements.
Result
An IoT application was implemented using an ESP32 and DHT11 sensor. The ESP32 successfully connected to a Wi-Fi network and transmitted temperature and humidity readings to a remote computer using TCP/IP socket communication.
Viva Questions
- What is the role of Wi-Fi in an IoT application?
- What is TCP?
- What is the difference between TCP and UDP?
- What is an IP address?
- What is a TCP socket?
- What is the difference between a TCP client and a TCP server?
- Why is TCP considered a reliable communication protocol?
- What is the function of the bind() function in Python socket programming?
- What is the purpose of the listen() function?
- What is the purpose of the accept() function?
- What is the function of sendall() in Python?
- Why should the remote computer's IP address be configured in the ESP32?
- What is the difference between a local IP address and a public IP address?
- Why is port 5000 used in this experiment?
- How can the application be extended to store sensor readings in a database or cloud platform?