SlideShare a Scribd company logo
4
Most read
13
Most read
14
Most read
Department of Electrical Engineering and Information
Technology
Chair of Measurement and Sensor Technology
Project Documentation
„Project Lab Embedded Systems “
Member: Lavanya Loganathan (455840)
Project: WIFI MESH NETWORK
Date: 2017-06-26
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 2 of 20	
	
TABLE OF CONTENT
1. Objective…..…………………….………………………………...................3
2. Members Responsibility……………….………………………………….….3
3. Introduction...………………………………………………….......................3
4. Hardware…......…………………………………….……………………...…4
4.1.ESP32 Features…………………………………………………...4
5. Software for Development……………………………………..…………….5
5.1.Arduino Installation…………………………………………...….5
5.2.Installing Python 2.7.x…………………………………………5
5.3.Gitbash…………………………………………………………5
5.4.Preparing the ESP32 board in in Arduino IDE………………………7
5.5.Uploading Codes into ESP-WROOM-32……………………….8
6. MQTT Protocol……………….……………………………………………..9
7. Development Flow Chart…...………………………………………………10
8. Used Keys and Syntaxes……………………………………………………11
9. Implemented Network Topology using cloud service…...…………………13
9.1.Star Topology …………………………………………………13
9.2.Mesh Topology………………………………………………...14
10.Conclusion…………………………………………………………………..15
11.References…………………………………………………………………..15
12.Arduino Software Codes……………………………………………………..16
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 3 of 20	
	
Figure1: ESP32 WROOM
1. Objective
Create a WiFi Network with ESP-WROOM-32 and Share data with different network
Topologies (Mesh and Star) using cloud service via MQTT protocol.
2. Member Responsibilities
Lavanya Loganathan Mac address detection, Receive Packets
Raziuddin Khazi Mqtt, Star network topology
Vivek Anand WiFi scan, Send Packets
3. Introduction
The project WiFi mesh network is aimed to build a platform for wireless communication
between multiple ESP32 devices. ESP32 is dual core high performance, low cost.
Integrated WiFi dual mode Bluetooth microcontroller device. Each Esp32 device can
interface with sensors (Like
temperature, humidity, pressure etc.)
and the sensors data are shared
among them via different network
topologies (Star, mesh etc.).
In this project, devices communicate
via a server called MQTT (Message
Queue Telemetry Transport) which is a light weight machine-machine protocol built over
TCP/IP. The sensor information is shared through a broker via publish and subscribe
messaging pattern. Here Broker is mediator which receives message packet from one
ESP device(publishing) and send/forward it to the other subscribed devices. The
advantage of using MQTT is its lightweight and auto reconnecting feature when
disconnected. MQTT is popular in many educational institutions and the Facebook
messenger app also uses some features of MQTT.
This portable device (wireless communication in such a small size) can be purchased for
less than €15. The Open source Arduino software compatibility for ESP32 setup makes it
more interesting and attractive. Wifi device at this price is a completely satisfying
reward!
There are many possibilities when it comes to building projects with ESP-WROOM-02.
It can be deployed in Home and Industrial automation, also can be integrated with IoT
devices.
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 4 of 20	
	
Figure 2: Pin Layout of ESP32
4. Hardware
ESP-WROOM-32
ESP32 is a 2.4 GHz dual-core with inbuilt Tensilica LX6 microprocessor with a
performance of 600 DMIPS (Dhrystone million instruction per second). In addition; this
small device comprises 520 KB of SRAM, 16 MB of flash on board memory. This chip
can be operated between -40° C to 125° C temperature with operating voltage around 2.2
to 3.6 V hence makes it more suitable for industrial use. In deep sleep mode, the ESP32
consumes 2.5 µA according to the manufacturer which is quite good for industrial
purpose.
4.1 ESP32 Features
• 2.2V to 3.6V operating voltage
• 32 GPIO pins:
o 3x UARTs, including hardware flow control
o 3x SPI
o 2x I2S
o 12x ADC input channels
o 2x DAC
o 2x I2C
o PWM/timer input/output available on every GPIO pin
o Supports external SPI flash up to 16 MB
o SD-card interface support
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 5 of 20	
	
5. Software for Development
5.1 Arduino Installation
5.2 Installing Python 2.7.x
5.2.1 Go to Python website and download the 2.7.x version
https://www.python.org/downloads
5.2.2 Open the downloaded file and follow the installation instructions
5.2.3 Select the option “Install for all users”
5.2.4 In Customize Python 2.7.X, enable the last option “Add python.exe to Path”
5.2.5 Complete the further installation
5.3 Gitbash
5.3.1 Download and install Git and
Git GUI git-scm.com
https://git-
scm.com/download/win
5.3.2 Install Git GUI and select the
Clone Existing Repository
option.
Figure 3: Python Installation
Figure 4: GUI Clone
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 6 of 20	
	
5.3.3 Then, choose the source and destination:
Source Location: https://github.com/espressif/arduino-esp32.git
Target Directory: Your_Arduino_IDE_Folder_Path/hardware/espressif/esp32
(in my case, it looks like:
C:Program Files (x86) Arduino hardware espressifarduino-esp32)
5.3.4 Press the “Clone” button	
5.3.5 Open the folder:
Your_Arduino_IDE_Folder_Path/hardware/espressif/esp32/tools
5.3.6 Open the “get.exe” file and wait for it to download/prepare the files
Figure 5: GUI Source and destination selection
Figure 6: get.exe download window
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 7 of 20	
	
5.4 Preparing the ESP32 board in Arduino IDE
5.4.1 Adding Libraries to Arduino
Download ESP-32 Library: https://github.com/espressif/arduino-esp32 and
copy to the following path C:Program FilesArduinohardwareespressif
5.4.2 Libraries are available to use for Arduino and ESP32 separately, but both are
not much suitable for ESP32 operation, so download a combined library
from GitHub to execute further.
Issue: When we used separate libraries, and tried to run some example codes
of arduino with ESP32, we found an error of “Wifi mode class not defined”.
Reason: The Class Wifi is defined in both libraries (arduino and esp32) and
Figure 7: ESP32 Library Download
	
Figure 8: Aurduino- ESP32 Library issue
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 8 of 20	
	
while executing default Arduino library was selected not the ESP 32.
Solution: Rename Wifi.h to any other name (eg. Wifi_arr.h) and execute
again and this time it selects ESP32 WiFi class.
5.4.3 Run any available sample program and analyze
5.5 Uploading Codes into ESP-WROOM-32
To write Arduino programs to the ESP-WROOM, we need an USB serial adapter to
connect it to a PC. For the Arduino UNO we’ve been using, a normal USB cable is
fine but the ESP-WROOM-02 requires serial conversion to connect to a PC. There
are several types of this adapter: 3.3v only, 5v only, and a 3.3v/5v jumper select
type. The ESP-WROOM requires 3.3v supply so we need either the 3.3v or the
3.3/5v selection jumper.
5.5.1 Select your board in Tools > Board menu (in my case it’s the ESP32 Dev
Module) 	
5.5.2 Select the COM port
5.5.3 To make your ESP32 go into
Downloading/uploading mode:
hold the BOOT button and
press the EN button to reboot
your ESP32
Figure 9: USB Serial Communicator
Figure 9: COM port selection
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 9 of 20	
	
Publish (Topic, Data)
Publish (Topic, Data)
Subscribe (Topic, Data)
5.5.4 Press the Upload button in the Arduino IDE and wait a few seconds while the
code compiles and uploads to your board.
5.5.5 If everything goes right this what you should see:
5.5.6 Restart your ESP32 to run the newly uploaded code
6. MQTT protocol
MQTT stands for Message Queue Telemetry Transfer protocol which is
developed by IBM. It’s a light weight message publish/subscribe protocol that is
built on top of TCP/IP which send/receive data over a broker.
The MQTT client library for arduino can be added from the GIT hub, after
installation it can be seen in the example libraries.
Figure 10: ESP WROOM 32
Figure 12: MQTT Protocol
Figure 11: Uploading Codes to ESP32
Publisher SubscriberBroker
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 10 of 20	
	
No
Yes
Yes
No
No
Yes
ReceiveSend
No
Yes
7. Development Chart
publish „Topic“ Send
Send
	
Decode Packet with MAC Address
and data
Send
	 Display data information
nd
Print connected network
SSID
	
Form Packet with MAC Address
and sensor data
Client
Connected
MQTT ?
Publish to “topic”
Client
Connected
MQTT ?
Detect and Display MAC
	
Start
Connect to local Wifi network
(ssid & password)
Subscribe to „Topic“ Receive
Define MQTT and Wifi Client	
Wifi	&	MQTT	Client	
Serial print
„connecting..“
SSID			
	
Client
Connected to
Server
?
Wifi.status ()
= Connected
?
Client connect to server "iot.eclipse.org"
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 11 of 20	
	
8. 	Used	Keys and Syntaxes
8.1 Client:
ESP32 modules are used as a MQTT client, it can be configured as a publishing or
subscribing node or both to a broker/network. However, in real time, MQTT client can
be any microcontroller with TCP/IP protocol to a fully-fledged server that has a
MQTT library running.
Arduino syntax: MQTTClient <space> <client name>;
Example: MQTTClient client;
This command defines the ‘client’ as a MQTTClient name which communicates
with MQTT server.
8.2 Broker
A MQTT protocols, which handle publish and subscribe commands of clients. A
broker is primarily responsible for client authentications, authorizations and
integration to the backend systems also receiving the entire message and filtering them
accordingly to the clients.
• ESP32 microcontroller acts as a client and iot.eclipse.org as a broker. The
MQTT connection is between ESP32 microcontroller and eclipse broker.
Multiple ESP32 modules are subscribed and publish to broker.
• Always the connection is initiated by the client ESP32 by sending
“CONNECT” message and upon receiving the “CONNACK” back from the
eclipse the connection gets established. Once the connection establishes it
cannot be disconnected unless the client disconnects itself.
• After establishing the WiFi network, begin the WiFi client connection with
MQTT broker using the arduno command.
Arduino syntax : <client name> .begin(“MQTT broke ”, WiFiClient name);
Example : client. begin("iot.eclipse.org", net);
Figure 13: MQTT Protocol
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 12 of 20	
	
This will begin communicating once the WiFi is established. After connecting WiFi
client to MQTT broker, thereafter it checks wifi status. If status is connected then
proceed, otherwise reconnect the WiFi network and also reconnect WiFiClient to the
MQTT broker.
Arduino syntax: <client name> .connect(Client ID, username, password);
Example : client. Connect(“arduino_tx”, "try", "try");
[Note: Here username and password are optional.]
• Username and password (optional): This is an optional parameter but it is
recommended to use them to authenticate and authorize the client.
8.3 Client ID
An Identifier for each MQTT client, connecting to MQTT broker. It is unique per
broker.
8.4 Clean Sessions(optional)
It is the optional part, setting the clean session to true (1) means that the broker will
not store any information of the client, and setting it to false (0) will store all the
missed messages of the client.
8.5 TOPICS
A topic is a UTF-8 string which is used by broker to filter the message for each
connected client. A topic can have one or more levels which define the depth of the
communication.
Example: Sensor/Temp_node1/Temp_node2
Here Temp_node2 is second layer that can be accessed by first layerTemp_node1
only.A ‘+’ operator also called as wildcard is used to create a single layer whereas ‘#’
is used to create multilayered topics.
8.6 PUBLISH
Publish is a keyword using which an ESP32 can send its message to the broker in
string format.
Arduino syntax- Publish (Topic name, Payload)
Example: Publish (Temprature_sensor, 100);
8.7 SUBSCRIBE
An ESP32 can subscribe to a single layer to multiple layered topics such that any
changes/ updated information can be received to the subscribed client.
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 13 of 20	
	
Publish Publish
PublishPublish Subscribe
Arduino syntax: Subscribe(Topic_name);
Example: Subscribe(Temprature_sensor);
8.8 Message Received
The message Received will be in string format hence ESP32 decodes the string packet
and take appropriate actions.
Arduino syntax: messageReceived(String <Topic name>, String <payload>, char
*<size>, unsigned int <length>)
Example: void messageReceived(String Temprature_sensor, String payload, char
* bytes, unsigned int length)
• String Topic compares the topic name with the subscribed topic, if topic
matches then it accepts the payload otherwise not.
• String payload contains the string data received over the MQTT broker which
can be extracted later.
• Char *bytes contains the data received in bytes.
• Length contains the length of the string.
9. Implemented Network Topology
9.1 STAR Topology
In star topology, multiple ESP slave devices publish to the broker (iot.eclipse.org)
using “/esp_star” ID and one master ESP hub is subscribed to the same broker by
“/esp_star” ID. The ESP hub is the central node and all other ESP slave nodes are
connected to the central hub node.
.
Figure 14: WiFi Star Connection of ESP32 Modules via MQTT
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 14 of 20	
	
Note: Here all the nodes
Publish & Subscribe both
Whenever sensor packet is published by the slave ESP to the broker, the subscribed
ESP hub receives the message.
Features of Star Topology
• Every node publishes withthe same client ID but at different time.
• Hub is subscribed to the same Client ID and receives message at different time.
Advantages of Star Topology
• Adding slave nodes is easier
• Easy to setup and modify
• Only that node is affected which has failed, rest of the nodes can work smoothly
Disadvantages of Star Topology
• Expensive to use
• If the hub fails then the whole network is stopped because all the nodes depend
on the hub.
9.2 MESH Topology
In the mesh topology, every ESP device has a direct point-to-point connection to
every other node. Because all connections are direct, the network can handle very
high-volume traffic. It is also robust because if one connection fails, the others remain
intact. Security is also high since data travels along a dedicated connection
Figure 15: WiFi Mesh Connection of ESP32 Modules via MQTT
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 15 of 20	
	
In Mesh topology, each node publishes and subscribe to “/esp_mesh” ID, when a
device sends the sensor packet it is received by all other nodes. In other words, every
node acts as a star node. All nodes subscribe and publish to the same client ID.
Features of Mesh Topology	
• Fully connected.
• Data routing is possible.
Advantages of Mesh Topology
• Each connection can carry its own data load.
• Provides security and privacy.
• Data routing can extend to multiple nodes.
Disadvantages of Mesh Topology
• Installation and configuration is difficult.
• Complex design
10. Conclusion
Implementation of Star and Mesh network topologies using ESP32 via MQTT
communication protocol is successful and data packets are shared among the devices.
11. References
• Kolban-ESP32, Neilkoblan book on Esp-32, May 2017
• esp32_datasheet (www.esp32.net)
• http://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-
windows-instructions/
• https://espressif.com/en/esp-wroom-32
• http://www.hivemq.com/blog/mqtt-essentials-part-3-client-broker-connection-
establishment
• http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices
• http://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-
windows-instructions
• https://github.com
• https://espressif.com
• https://www.arduino.cc
• https://www.python.org
• https://iot.eclipse.org
• http://mqtt.org
• https://www.sparkfun.com
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 16 of 20	
	
12. Arduino Software Codes
#include<WiFi.h>
#include<MQTTClient.h>
const char ssid[] = "TP-LINK_KHAZI";
const char pass[] = "khazi1234";
byte mac[6];
WiFiClient net;
MQTTClient client;
unsigned long lastMillis = 0;
void connect();
void setup()
{
// select the baudrate and begin the wifi communication
Serial.begin(115200);
WiFi.begin(ssid,pass);
delay(100);
// Connect WiFi client to the MQTT broker
client.begin("iot.eclipse.org",net);
connect();
}
void connect(){
// Check WiFi status,if not connected the try reconnecting
Serial.print("Connecting.. ");
while(WiFi.status()!=WL_CONNECTED){
Serial.print(".");
delay(1000);
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 17 of 20	
	
}
// Displays connected access point name(SSID name)
Serial.println("");
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
// Connecing from local server to the IoT.eclipse.org
// If not connected to the MQTT server then wait till reconnects
Serial.print("nConnecting....");
while(!client.connect("arduino_rx","try","try")){
Serial.print(".");
}
// Displays the MAC address of the device
WiFi.macAddress(mac);
Serial.println("");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 18 of 20	
	
Serial.print(mac[0],HEX);
//client subscribes to the topic name "esp_star"
client.subscribe("/esp_star");
}
void loop()
{
// this should always be in loop, to keep MQTT active/alive
client.loop();
delay(10);
if(!client.connected())
{
connect();
}
}
void messageReceived(String topic, String payload , char *bytes, unsigned int length)
{
// Predefined MAC address of the devices for decoding the incomming messages
String sub_temp,sub_temp1;
String esp_r1 = "64";
String esp_r2 = "72";
String esp_r3 = "244";
String esp_r4 = "252";
String esp_green = "156";
// Extraction of 2 digit or 3 digit MAC address into temporary variables
sub_temp = payload.substring(0,2);
sub_temp1 = payload.substring(0,3);
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 19 of 20	
	
// Decoding the Message and segregating based on the MAC ID of the device
// If MAC ID match the predefined MAC ID then displays the information on the screen
// Its prior known tha,
// Temperature sensor is connected to esp_r1,
// Pressure sensor is connected esp_r2
// Humidity sensor is connected to esp_r3
// Hall effect sensor connected to esp_green
if(sub_temp == esp_r1){
Serial.print("Temp : ");
Serial.println(payload.substring(2));
}
else if(sub_temp == esp_r2){
Serial.print("Pressure : ");
Serial.println(payload.substring(2));
}
else if((sub_temp == esp_r3)||(sub_temp1 == esp_r3)){
Serial.print("Humidity : ");
Serial.println(payload.substring(3));
}
else if((sub_temp == esp_r4)||(sub_temp1 == esp_r4)){
Serial.print("Accelerometer : ");
Serial.println(payload.substring(3));
}
else if((sub_temp == esp_green)||(sub_temp1 == esp_green)){
Serial.print("Halleffect sensor : ");
Serial.println(payload.substring(3));
Technische	Universität	Chemnitz	
Chair	of	Measurement	and	Sensor	Technology	
Prof.	Dr.-Ing.	Olfa	Kanoun	 	
	
Group	18:	Wi-Fi	Mesh	Network	 	 Page 20 of 20	
	
}
//If any MAC ID did not match then display "some problem"
else{
Serial.println("Some problem..");
}
}
To Send data from nodes to hub in star topology:
void loop()
{
client.loop();
delay(10);// <- fixes some issues with WiFi stability
String pld = "";
pld += mac[5];
if (!client.connected()) {
connect();
}
// publish a message roughly every second.
if (millis() - lastMillis > 2000) {
lastMillis = millis();
//float sen_val = analogRead(5);
float x = 19.45;
pld += x;
//publish sensor packet(pld)to the mqtt broker
client.publish("/esp_star",pld);
}
}
Note: Rest of the code remain same as previous code, only change in void loop() function.

More Related Content

PDF
ESP8266 and IOT
PPTX
VLSI Technology
DOCX
Light Fidelity ( Li-Fi ) Seminar Report
PDF
Traffic light controller with verilog
PDF
ZigBee Technology
PPTX
IEEE 80211 ah
PDF
Li Fi Technology
PPT
Introduction to VLSI
ESP8266 and IOT
VLSI Technology
Light Fidelity ( Li-Fi ) Seminar Report
Traffic light controller with verilog
ZigBee Technology
IEEE 80211 ah
Li Fi Technology
Introduction to VLSI

What's hot (20)

PDF
HART COMMUNICATION
PDF
Mentor vlsi lab btech_4_1
PDF
Ultrasonic based distance measurement system
PPTX
ppt on accident detection system based on Iot
ODP
VLSI TECHNOLOGY
PPT
Vlsi technology-dinesh
PDF
dwdm
 
PPT
Presentation on Vowifi
PDF
Silicon Photonics 2021
PPTX
electronics seminar ppt
PDF
Taiyo Yuden SAW and BAW Band 7 Duplexer integrated into Skyworks’ System in P...
PDF
Introduction to VLSI
PPTX
RFID attendance system
PPTX
Volte ppt
PDF
Introduction to VLSI Design
PDF
W04 Profinet in process automation - Pete Brown, Siemens
PPT
Scope of electronics and communication engineering.ppt
PPT
VLSI
DOCX
Otn maintenance signal interaction
PPT
Digital network lecturer1
HART COMMUNICATION
Mentor vlsi lab btech_4_1
Ultrasonic based distance measurement system
ppt on accident detection system based on Iot
VLSI TECHNOLOGY
Vlsi technology-dinesh
dwdm
 
Presentation on Vowifi
Silicon Photonics 2021
electronics seminar ppt
Taiyo Yuden SAW and BAW Band 7 Duplexer integrated into Skyworks’ System in P...
Introduction to VLSI
RFID attendance system
Volte ppt
Introduction to VLSI Design
W04 Profinet in process automation - Pete Brown, Siemens
Scope of electronics and communication engineering.ppt
VLSI
Otn maintenance signal interaction
Digital network lecturer1
Ad

Similar to WiFi mesh network(ESP32 mStar and mesh topology) (20)

PDF
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
PDF
IoT Intro and Demo
PDF
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
PDF
Rapid IoT prototyping with mruby
PPTX
IOT Talking to Webserver - how to
PPTX
Lecture23_Home automation where we talk how iot can be used for home automation
PDF
Road to Republic of IoT - ESP32 Programming and LoRa
PDF
Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2
PPTX
New Microsoft PowerPoint Presentation.pptx
PPTX
Esp8266 NodeMCU
PDF
Road to Republic of IoT - IoT Technologies & Machine Learning
PDF
Ijecet 06 08_002
PPT
Arduino and Internet of Thinks: ShareIT TM: march 2010, TM
PPTX
Build WiFi gadgets using esp8266
PDF
IOT REPORT a Report on subject of IOT under VTU curriculum
PPTX
IoT and Digitization with Arduino and Raspberry Pi.pptx
PDF
Cassiopeia Ltd - ESP8266+Arduino workshop
PPTX
Esp8266 - Intro for dummies
PPTX
Simple Introduction about ESP32 Presentation
PDF
Smart Projects With Arduino And Esp32 Integrating Artificial Intelligence Abd...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT Intro and Demo
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
Rapid IoT prototyping with mruby
IOT Talking to Webserver - how to
Lecture23_Home automation where we talk how iot can be used for home automation
Road to Republic of IoT - ESP32 Programming and LoRa
Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2
New Microsoft PowerPoint Presentation.pptx
Esp8266 NodeMCU
Road to Republic of IoT - IoT Technologies & Machine Learning
Ijecet 06 08_002
Arduino and Internet of Thinks: ShareIT TM: march 2010, TM
Build WiFi gadgets using esp8266
IOT REPORT a Report on subject of IOT under VTU curriculum
IoT and Digitization with Arduino and Raspberry Pi.pptx
Cassiopeia Ltd - ESP8266+Arduino workshop
Esp8266 - Intro for dummies
Simple Introduction about ESP32 Presentation
Smart Projects With Arduino And Esp32 Integrating Artificial Intelligence Abd...
Ad

Recently uploaded (20)

PPTX
Lecture Notes Electrical Wiring System Components
PDF
composite construction of structures.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
additive manufacturing of ss316l using mig welding
PPT
Project quality management in manufacturing
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Construction Project Organization Group 2.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Digital Logic Computer Design lecture notes
DOCX
573137875-Attendance-Management-System-original
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Sustainable Sites - Green Building Construction
Lecture Notes Electrical Wiring System Components
composite construction of structures.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Operating System & Kernel Study Guide-1 - converted.pdf
UNIT 4 Total Quality Management .pptx
bas. eng. economics group 4 presentation 1.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
additive manufacturing of ss316l using mig welding
Project quality management in manufacturing
Embodied AI: Ushering in the Next Era of Intelligent Systems
Construction Project Organization Group 2.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Digital Logic Computer Design lecture notes
573137875-Attendance-Management-System-original
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Sustainable Sites - Green Building Construction

WiFi mesh network(ESP32 mStar and mesh topology)

  • 1. Department of Electrical Engineering and Information Technology Chair of Measurement and Sensor Technology Project Documentation „Project Lab Embedded Systems “ Member: Lavanya Loganathan (455840) Project: WIFI MESH NETWORK Date: 2017-06-26
  • 2. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 2 of 20 TABLE OF CONTENT 1. Objective…..…………………….………………………………...................3 2. Members Responsibility……………….………………………………….….3 3. Introduction...………………………………………………….......................3 4. Hardware…......…………………………………….……………………...…4 4.1.ESP32 Features…………………………………………………...4 5. Software for Development……………………………………..…………….5 5.1.Arduino Installation…………………………………………...….5 5.2.Installing Python 2.7.x…………………………………………5 5.3.Gitbash…………………………………………………………5 5.4.Preparing the ESP32 board in in Arduino IDE………………………7 5.5.Uploading Codes into ESP-WROOM-32……………………….8 6. MQTT Protocol……………….……………………………………………..9 7. Development Flow Chart…...………………………………………………10 8. Used Keys and Syntaxes……………………………………………………11 9. Implemented Network Topology using cloud service…...…………………13 9.1.Star Topology …………………………………………………13 9.2.Mesh Topology………………………………………………...14 10.Conclusion…………………………………………………………………..15 11.References…………………………………………………………………..15 12.Arduino Software Codes……………………………………………………..16
  • 3. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 3 of 20 Figure1: ESP32 WROOM 1. Objective Create a WiFi Network with ESP-WROOM-32 and Share data with different network Topologies (Mesh and Star) using cloud service via MQTT protocol. 2. Member Responsibilities Lavanya Loganathan Mac address detection, Receive Packets Raziuddin Khazi Mqtt, Star network topology Vivek Anand WiFi scan, Send Packets 3. Introduction The project WiFi mesh network is aimed to build a platform for wireless communication between multiple ESP32 devices. ESP32 is dual core high performance, low cost. Integrated WiFi dual mode Bluetooth microcontroller device. Each Esp32 device can interface with sensors (Like temperature, humidity, pressure etc.) and the sensors data are shared among them via different network topologies (Star, mesh etc.). In this project, devices communicate via a server called MQTT (Message Queue Telemetry Transport) which is a light weight machine-machine protocol built over TCP/IP. The sensor information is shared through a broker via publish and subscribe messaging pattern. Here Broker is mediator which receives message packet from one ESP device(publishing) and send/forward it to the other subscribed devices. The advantage of using MQTT is its lightweight and auto reconnecting feature when disconnected. MQTT is popular in many educational institutions and the Facebook messenger app also uses some features of MQTT. This portable device (wireless communication in such a small size) can be purchased for less than €15. The Open source Arduino software compatibility for ESP32 setup makes it more interesting and attractive. Wifi device at this price is a completely satisfying reward! There are many possibilities when it comes to building projects with ESP-WROOM-02. It can be deployed in Home and Industrial automation, also can be integrated with IoT devices.
  • 4. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 4 of 20 Figure 2: Pin Layout of ESP32 4. Hardware ESP-WROOM-32 ESP32 is a 2.4 GHz dual-core with inbuilt Tensilica LX6 microprocessor with a performance of 600 DMIPS (Dhrystone million instruction per second). In addition; this small device comprises 520 KB of SRAM, 16 MB of flash on board memory. This chip can be operated between -40° C to 125° C temperature with operating voltage around 2.2 to 3.6 V hence makes it more suitable for industrial use. In deep sleep mode, the ESP32 consumes 2.5 µA according to the manufacturer which is quite good for industrial purpose. 4.1 ESP32 Features • 2.2V to 3.6V operating voltage • 32 GPIO pins: o 3x UARTs, including hardware flow control o 3x SPI o 2x I2S o 12x ADC input channels o 2x DAC o 2x I2C o PWM/timer input/output available on every GPIO pin o Supports external SPI flash up to 16 MB o SD-card interface support
  • 5. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 5 of 20 5. Software for Development 5.1 Arduino Installation 5.2 Installing Python 2.7.x 5.2.1 Go to Python website and download the 2.7.x version https://www.python.org/downloads 5.2.2 Open the downloaded file and follow the installation instructions 5.2.3 Select the option “Install for all users” 5.2.4 In Customize Python 2.7.X, enable the last option “Add python.exe to Path” 5.2.5 Complete the further installation 5.3 Gitbash 5.3.1 Download and install Git and Git GUI git-scm.com https://git- scm.com/download/win 5.3.2 Install Git GUI and select the Clone Existing Repository option. Figure 3: Python Installation Figure 4: GUI Clone
  • 6. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 6 of 20 5.3.3 Then, choose the source and destination: Source Location: https://github.com/espressif/arduino-esp32.git Target Directory: Your_Arduino_IDE_Folder_Path/hardware/espressif/esp32 (in my case, it looks like: C:Program Files (x86) Arduino hardware espressifarduino-esp32) 5.3.4 Press the “Clone” button 5.3.5 Open the folder: Your_Arduino_IDE_Folder_Path/hardware/espressif/esp32/tools 5.3.6 Open the “get.exe” file and wait for it to download/prepare the files Figure 5: GUI Source and destination selection Figure 6: get.exe download window
  • 7. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 7 of 20 5.4 Preparing the ESP32 board in Arduino IDE 5.4.1 Adding Libraries to Arduino Download ESP-32 Library: https://github.com/espressif/arduino-esp32 and copy to the following path C:Program FilesArduinohardwareespressif 5.4.2 Libraries are available to use for Arduino and ESP32 separately, but both are not much suitable for ESP32 operation, so download a combined library from GitHub to execute further. Issue: When we used separate libraries, and tried to run some example codes of arduino with ESP32, we found an error of “Wifi mode class not defined”. Reason: The Class Wifi is defined in both libraries (arduino and esp32) and Figure 7: ESP32 Library Download Figure 8: Aurduino- ESP32 Library issue
  • 8. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 8 of 20 while executing default Arduino library was selected not the ESP 32. Solution: Rename Wifi.h to any other name (eg. Wifi_arr.h) and execute again and this time it selects ESP32 WiFi class. 5.4.3 Run any available sample program and analyze 5.5 Uploading Codes into ESP-WROOM-32 To write Arduino programs to the ESP-WROOM, we need an USB serial adapter to connect it to a PC. For the Arduino UNO we’ve been using, a normal USB cable is fine but the ESP-WROOM-02 requires serial conversion to connect to a PC. There are several types of this adapter: 3.3v only, 5v only, and a 3.3v/5v jumper select type. The ESP-WROOM requires 3.3v supply so we need either the 3.3v or the 3.3/5v selection jumper. 5.5.1 Select your board in Tools > Board menu (in my case it’s the ESP32 Dev Module) 5.5.2 Select the COM port 5.5.3 To make your ESP32 go into Downloading/uploading mode: hold the BOOT button and press the EN button to reboot your ESP32 Figure 9: USB Serial Communicator Figure 9: COM port selection
  • 9. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 9 of 20 Publish (Topic, Data) Publish (Topic, Data) Subscribe (Topic, Data) 5.5.4 Press the Upload button in the Arduino IDE and wait a few seconds while the code compiles and uploads to your board. 5.5.5 If everything goes right this what you should see: 5.5.6 Restart your ESP32 to run the newly uploaded code 6. MQTT protocol MQTT stands for Message Queue Telemetry Transfer protocol which is developed by IBM. It’s a light weight message publish/subscribe protocol that is built on top of TCP/IP which send/receive data over a broker. The MQTT client library for arduino can be added from the GIT hub, after installation it can be seen in the example libraries. Figure 10: ESP WROOM 32 Figure 12: MQTT Protocol Figure 11: Uploading Codes to ESP32 Publisher SubscriberBroker
  • 10. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 10 of 20 No Yes Yes No No Yes ReceiveSend No Yes 7. Development Chart publish „Topic“ Send Send Decode Packet with MAC Address and data Send Display data information nd Print connected network SSID Form Packet with MAC Address and sensor data Client Connected MQTT ? Publish to “topic” Client Connected MQTT ? Detect and Display MAC Start Connect to local Wifi network (ssid & password) Subscribe to „Topic“ Receive Define MQTT and Wifi Client Wifi & MQTT Client Serial print „connecting..“ SSID Client Connected to Server ? Wifi.status () = Connected ? Client connect to server "iot.eclipse.org"
  • 11. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 11 of 20 8. Used Keys and Syntaxes 8.1 Client: ESP32 modules are used as a MQTT client, it can be configured as a publishing or subscribing node or both to a broker/network. However, in real time, MQTT client can be any microcontroller with TCP/IP protocol to a fully-fledged server that has a MQTT library running. Arduino syntax: MQTTClient <space> <client name>; Example: MQTTClient client; This command defines the ‘client’ as a MQTTClient name which communicates with MQTT server. 8.2 Broker A MQTT protocols, which handle publish and subscribe commands of clients. A broker is primarily responsible for client authentications, authorizations and integration to the backend systems also receiving the entire message and filtering them accordingly to the clients. • ESP32 microcontroller acts as a client and iot.eclipse.org as a broker. The MQTT connection is between ESP32 microcontroller and eclipse broker. Multiple ESP32 modules are subscribed and publish to broker. • Always the connection is initiated by the client ESP32 by sending “CONNECT” message and upon receiving the “CONNACK” back from the eclipse the connection gets established. Once the connection establishes it cannot be disconnected unless the client disconnects itself. • After establishing the WiFi network, begin the WiFi client connection with MQTT broker using the arduno command. Arduino syntax : <client name> .begin(“MQTT broke ”, WiFiClient name); Example : client. begin("iot.eclipse.org", net); Figure 13: MQTT Protocol
  • 12. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 12 of 20 This will begin communicating once the WiFi is established. After connecting WiFi client to MQTT broker, thereafter it checks wifi status. If status is connected then proceed, otherwise reconnect the WiFi network and also reconnect WiFiClient to the MQTT broker. Arduino syntax: <client name> .connect(Client ID, username, password); Example : client. Connect(“arduino_tx”, "try", "try"); [Note: Here username and password are optional.] • Username and password (optional): This is an optional parameter but it is recommended to use them to authenticate and authorize the client. 8.3 Client ID An Identifier for each MQTT client, connecting to MQTT broker. It is unique per broker. 8.4 Clean Sessions(optional) It is the optional part, setting the clean session to true (1) means that the broker will not store any information of the client, and setting it to false (0) will store all the missed messages of the client. 8.5 TOPICS A topic is a UTF-8 string which is used by broker to filter the message for each connected client. A topic can have one or more levels which define the depth of the communication. Example: Sensor/Temp_node1/Temp_node2 Here Temp_node2 is second layer that can be accessed by first layerTemp_node1 only.A ‘+’ operator also called as wildcard is used to create a single layer whereas ‘#’ is used to create multilayered topics. 8.6 PUBLISH Publish is a keyword using which an ESP32 can send its message to the broker in string format. Arduino syntax- Publish (Topic name, Payload) Example: Publish (Temprature_sensor, 100); 8.7 SUBSCRIBE An ESP32 can subscribe to a single layer to multiple layered topics such that any changes/ updated information can be received to the subscribed client.
  • 13. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 13 of 20 Publish Publish PublishPublish Subscribe Arduino syntax: Subscribe(Topic_name); Example: Subscribe(Temprature_sensor); 8.8 Message Received The message Received will be in string format hence ESP32 decodes the string packet and take appropriate actions. Arduino syntax: messageReceived(String <Topic name>, String <payload>, char *<size>, unsigned int <length>) Example: void messageReceived(String Temprature_sensor, String payload, char * bytes, unsigned int length) • String Topic compares the topic name with the subscribed topic, if topic matches then it accepts the payload otherwise not. • String payload contains the string data received over the MQTT broker which can be extracted later. • Char *bytes contains the data received in bytes. • Length contains the length of the string. 9. Implemented Network Topology 9.1 STAR Topology In star topology, multiple ESP slave devices publish to the broker (iot.eclipse.org) using “/esp_star” ID and one master ESP hub is subscribed to the same broker by “/esp_star” ID. The ESP hub is the central node and all other ESP slave nodes are connected to the central hub node. . Figure 14: WiFi Star Connection of ESP32 Modules via MQTT
  • 14. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 14 of 20 Note: Here all the nodes Publish & Subscribe both Whenever sensor packet is published by the slave ESP to the broker, the subscribed ESP hub receives the message. Features of Star Topology • Every node publishes withthe same client ID but at different time. • Hub is subscribed to the same Client ID and receives message at different time. Advantages of Star Topology • Adding slave nodes is easier • Easy to setup and modify • Only that node is affected which has failed, rest of the nodes can work smoothly Disadvantages of Star Topology • Expensive to use • If the hub fails then the whole network is stopped because all the nodes depend on the hub. 9.2 MESH Topology In the mesh topology, every ESP device has a direct point-to-point connection to every other node. Because all connections are direct, the network can handle very high-volume traffic. It is also robust because if one connection fails, the others remain intact. Security is also high since data travels along a dedicated connection Figure 15: WiFi Mesh Connection of ESP32 Modules via MQTT
  • 15. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 15 of 20 In Mesh topology, each node publishes and subscribe to “/esp_mesh” ID, when a device sends the sensor packet it is received by all other nodes. In other words, every node acts as a star node. All nodes subscribe and publish to the same client ID. Features of Mesh Topology • Fully connected. • Data routing is possible. Advantages of Mesh Topology • Each connection can carry its own data load. • Provides security and privacy. • Data routing can extend to multiple nodes. Disadvantages of Mesh Topology • Installation and configuration is difficult. • Complex design 10. Conclusion Implementation of Star and Mesh network topologies using ESP32 via MQTT communication protocol is successful and data packets are shared among the devices. 11. References • Kolban-ESP32, Neilkoblan book on Esp-32, May 2017 • esp32_datasheet (www.esp32.net) • http://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide- windows-instructions/ • https://espressif.com/en/esp-wroom-32 • http://www.hivemq.com/blog/mqtt-essentials-part-3-client-broker-connection- establishment • http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices • http://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide- windows-instructions • https://github.com • https://espressif.com • https://www.arduino.cc • https://www.python.org • https://iot.eclipse.org • http://mqtt.org • https://www.sparkfun.com
  • 16. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 16 of 20 12. Arduino Software Codes #include<WiFi.h> #include<MQTTClient.h> const char ssid[] = "TP-LINK_KHAZI"; const char pass[] = "khazi1234"; byte mac[6]; WiFiClient net; MQTTClient client; unsigned long lastMillis = 0; void connect(); void setup() { // select the baudrate and begin the wifi communication Serial.begin(115200); WiFi.begin(ssid,pass); delay(100); // Connect WiFi client to the MQTT broker client.begin("iot.eclipse.org",net); connect(); } void connect(){ // Check WiFi status,if not connected the try reconnecting Serial.print("Connecting.. "); while(WiFi.status()!=WL_CONNECTED){ Serial.print("."); delay(1000);
  • 17. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 17 of 20 } // Displays connected access point name(SSID name) Serial.println(""); Serial.print("Connected to "); Serial.println(WiFi.SSID()); // Connecing from local server to the IoT.eclipse.org // If not connected to the MQTT server then wait till reconnects Serial.print("nConnecting...."); while(!client.connect("arduino_rx","try","try")){ Serial.print("."); } // Displays the MAC address of the device WiFi.macAddress(mac); Serial.println(""); Serial.print(mac[5],HEX); Serial.print(":"); Serial.print(mac[5],HEX); Serial.print(":"); Serial.print(mac[4],HEX); Serial.print(":"); Serial.print(mac[3],HEX); Serial.print(":"); Serial.print(mac[2],HEX); Serial.print(":"); Serial.print(mac[1],HEX); Serial.print(":");
  • 18. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 18 of 20 Serial.print(mac[0],HEX); //client subscribes to the topic name "esp_star" client.subscribe("/esp_star"); } void loop() { // this should always be in loop, to keep MQTT active/alive client.loop(); delay(10); if(!client.connected()) { connect(); } } void messageReceived(String topic, String payload , char *bytes, unsigned int length) { // Predefined MAC address of the devices for decoding the incomming messages String sub_temp,sub_temp1; String esp_r1 = "64"; String esp_r2 = "72"; String esp_r3 = "244"; String esp_r4 = "252"; String esp_green = "156"; // Extraction of 2 digit or 3 digit MAC address into temporary variables sub_temp = payload.substring(0,2); sub_temp1 = payload.substring(0,3);
  • 19. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 19 of 20 // Decoding the Message and segregating based on the MAC ID of the device // If MAC ID match the predefined MAC ID then displays the information on the screen // Its prior known tha, // Temperature sensor is connected to esp_r1, // Pressure sensor is connected esp_r2 // Humidity sensor is connected to esp_r3 // Hall effect sensor connected to esp_green if(sub_temp == esp_r1){ Serial.print("Temp : "); Serial.println(payload.substring(2)); } else if(sub_temp == esp_r2){ Serial.print("Pressure : "); Serial.println(payload.substring(2)); } else if((sub_temp == esp_r3)||(sub_temp1 == esp_r3)){ Serial.print("Humidity : "); Serial.println(payload.substring(3)); } else if((sub_temp == esp_r4)||(sub_temp1 == esp_r4)){ Serial.print("Accelerometer : "); Serial.println(payload.substring(3)); } else if((sub_temp == esp_green)||(sub_temp1 == esp_green)){ Serial.print("Halleffect sensor : "); Serial.println(payload.substring(3));
  • 20. Technische Universität Chemnitz Chair of Measurement and Sensor Technology Prof. Dr.-Ing. Olfa Kanoun Group 18: Wi-Fi Mesh Network Page 20 of 20 } //If any MAC ID did not match then display "some problem" else{ Serial.println("Some problem.."); } } To Send data from nodes to hub in star topology: void loop() { client.loop(); delay(10);// <- fixes some issues with WiFi stability String pld = ""; pld += mac[5]; if (!client.connected()) { connect(); } // publish a message roughly every second. if (millis() - lastMillis > 2000) { lastMillis = millis(); //float sen_val = analogRead(5); float x = 19.45; pld += x; //publish sensor packet(pld)to the mqtt broker client.publish("/esp_star",pld); } } Note: Rest of the code remain same as previous code, only change in void loop() function.