Learn how to use ESP-MESH networking protocol to build a mesh network with the ESP32 and ESP8266 NodeMCU boards. ESP-MESH allows multiple devices (nodes) to communicate with each other under a single wireless local area network. It is supported on the ESP32 and ESP8266 boards. In this guide, we’ll show you how to get started with ESP-MESH using the Arduino core.
This article covers the following topics:
- Introducing ESP-MESH
- ESP-MESH Basic Example (Broadcast messages)
- Exchange Sensor Readings using ESP-MESH (broadcast)
Arduino IDE
If you want to program the ESP32 and ESP8266 boards using Arduino IDE, you should have the ESP32 or ESP8266 add-ons installed. Follow the next guides:
- Installing ESP32 Board in Arduino IDE (Windows, Mac OS X, and Linux)
- Installing ESP8266 Board in Arduino IDE (Windows, Mac OS X, Linux)
If you want to program the ESP32/ESP8266 using VS Code + PlatformIO, follow the next tutorial:
Introducing ESP-MESH
Accordingly to the Espressif documentation:
“ESP-MESH is a networking protocol built atop the Wi-Fi protocol. ESP-MESH allows numerous devices (referred to as nodes) spread over a large physical area (both indoors and outdoors) to be interconnected under a single WLAN (Wireless Local-Area Network).
ESP-MESH is self-organizing and self-healing meaning the network can be built and maintained autonomously.” For more information, visit the ESP-MESH official documentation.
Traditional Wi-Fi Network Architecture
In a traditional Wi-Fi network architecture, a single node (access point – usually the router) is connected to all other nodes (stations). Each node can communicate with each other using the access point. However, this is limited to the access point wi-fi coverage. Every station must be in the range to connect directly to the access point. This doesn’t happen with ESP-MESH.
ESP-MESH Network Architecture
With ESP-MESH, the nodes don’t need to connect to a central node. Nodes are responsible for relaying each others transmissions. This allows multiple devices to spread over a large physical area. The Nodes can self-organize and dynamically talk to each other to ensure that the packet reaches its final node destination. If any node is removed from the network, it is able to self-organize to make sure that the packets reach their destination.
painlessMesh Library
The painlessMesh library allows us to create a mesh network with the ESP8266 or/and ESP32 boards in an easy way.
“painlessMesh is a true ad-hoc network, meaning that no-planning, central controller, or router is required. Any system of 1 or more nodes will self-organize into fully functional mesh. The maximum size of the mesh is limited (we think) by the amount of memory in the heap that can be allocated to the sub-connections buffer and so should be really quite high.” More information about the painlessMesh library.
Installing painlessMesh Library
You can install painlessMesh through the Arduino Library manager. Go to Tools > Manage Libraries. The Library Manager should open.
Search for “painlessmesh” and install the library. We’re using Version 1.4.5
This library needs some other library dependencies. A new window should pop up asking you to install any missing dependencies. Select “Install all”.
If this window doesn’t show up, you’ll need to install the following library dependencies:
- ArduinoJson (by bblanchon)
- TaskScheduler
- ESPAsyncTCP (ESP8266)
- AsyncTCP (ESP32)
If you’re using PlatformIO, add the following lines to the platformio.ini file to add the libraries and change the monitor speed.
For the ESP32:
monitor_speed = 115200
lib_deps = painlessmesh/painlessMesh @ ^1.4.5
ArduinoJson
arduinoUnity
TaskScheduler
AsyncTCP
For the ESP8266:
monitor_speed = 115200
lib_deps = painlessmesh/painlessMesh @ ^1.4.5
ArduinoJson
TaskScheduler
ESPAsyncTCP
ESP-MESH Basic Example (Broadcast messages)
To get started with ESP-MESH, we’ll first experiment with the library’s basic example. This example creates a mesh network in which all boards broadcast messages to all the other boards.
We’ve experimented this example with four boards (two ESP32 and two ESP8266). You can add or remove boards. The code is compatible with both the ESP32 and ESP8266 boards.
Code – painlessMesh Library Basic Example
Copy the following code to your Arduino IDE (code from the library examples). The code is compatible with both the ESP32 and ESP8266 boards.
If you’re using an ESP32, you need to downgrade your ESP32 boards’ add-on to version 2.0.X. At the moment, the painlessMesh library is not compatible with version 3.X.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-mesh-esp32-esp8266-painlessmesh/
This is a simple example that uses the painlessMesh library: https://github.com/gmag11/painlessMesh/blob/master/examples/basic/basic.ino
*/
#include "painlessMesh.h"
#define MESH_PREFIX "whateverYouLike"
#define MESH_PASSWORD "somethingSneaky"
#define MESH_PORT 5555
Scheduler userScheduler; // to control your personal task
painlessMesh mesh;
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
Task taskSendMessage( TASK_SECOND * 1 , TASK_FOREVER, &sendMessage );
void sendMessage() {
String msg = "Hi from node1";
msg += mesh.getNodeId();
mesh.sendBroadcast( msg );
taskSendMessage.setInterval( random( TASK_SECOND * 1, TASK_SECOND * 5 ));
}
// Needed for painless library
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
void setup() {
Serial.begin(115200);
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
userScheduler.addTask( taskSendMessage );
taskSendMessage.enable();
}
void loop() {
// it will run the user scheduler as well
mesh.update();
}
Before uploading the code, you can set up the MESH_PREFIX (it’s like the name of the MESH network) and the MESH_PASSWORD variables (you can set it to whatever you like).
Then, we recommend that you change the following line for each board to easily identify the node that sent the message. For example, for node 1, change the message as follows:
String msg = "Hi from node 1 ";
How the Code Works
Start by including the painlessMesh library.
#include "painlessMesh.h"
MESH Details
Then, add the mesh details. The MESH_PREFIX refers to the name of the mesh. You can change it to whatever you like.
#define MESH_PREFIX "whateverYouLike"
The MESH_PASSWORD, as the name suggests is the mesh password. You can change it to whatever you like.
#define MESH_PASSWORD "somethingSneaky"
All nodes in the mesh should use the same MESH_PREFIX and MESH_PASSWORD.
The MESH_PORT refers to the the TCP port that you want the mesh server to run on. The default is 5555.
#define MESH_PORT 5555
Scheduler
It is recommended to avoid using delay() in the mesh network code. To maintain the mesh, some tasks need to be performed in the background. Using delay() will stop these tasks from happening and can cause the mesh to lose stability/fall apart.
Instead, it is recommended to use TaskScheduler to run your tasks which is used in painlessMesh itself.
The following line creates a new Scheduler called userScheduler.
Scheduler userScheduler; // to control your personal task
painlessMesh
Create a painlessMesh object called mesh to handle the mesh network.
Create tasks
Create a task called taskSendMessage responsible for calling the sendMessage() function every second as long as the program is running.
Task taskSendMessage(TASK_SECOND * 1 , TASK_FOREVER, &sendMessage);
Send a Message to the Mesh
The sendMessage() function sends a message to all nodes in the message network (broadcast).
void sendMessage() {
String msg = "Hi from node 1";
msg += mesh.getNodeId();
mesh.sendBroadcast( msg );
taskSendMessage.setInterval(random(TASK_SECOND * 1, TASK_SECOND * 5));
}
The message contains the “Hi from node 1” text followed by the board chip ID.
String msg = "Hi from node 1";
msg += mesh.getNodeId();
To broadcast a message, simply use the sendBroadcast() method on the mesh object and pass as argument the message (msg) you want to send.
mesh.sendBroadcast(msg);
Every time a new message is sent, the code changes the interval between messages (one to five seconds).
taskSendMessage.setInterval(random(TASK_SECOND * 1, TASK_SECOND * 5));
Mesh Callback Functions
Next, several callback functions are created that will be called when specific events happen on the mesh.
The receivedCallback() function prints the message sender (from) and the content of the message (msg.c_str()).
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
The newConnectionCallback() function runs whenever a new node joins the network. This function simply prints the chip ID of the new node. You can modify the function to do any other task.
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
The changedConnectionCallback() function runs whenever a connection changes on the network (when a node joins or leaves the network).
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
The nodeTimeAdjustedCallback() function runs when the network adjusts the time, so that all nodes are synchronized. It prints the offset.
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
setup()
In the setup(), initialize the serial monitor.
void setup() {
Serial.begin(115200);
Choose the desired debug message types:
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
Initialize the mesh with the details defined earlier.
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
Assign all the callback functions to their corresponding events.
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
Finally, add the taskSendMessage function to the userScheduler. The scheduler is responsible for handling and running the tasks at the right time.
userScheduler.addTask(taskSendMessage);
Finally, enable the taskSendMessage, so that the program starts sending the messages to the mesh.
taskSendMessage.enable();
To keep the mesh running, add mesh.update() to the loop().
void loop() {
// it will run the user scheduler as well
mesh.update();
}
Demonstration
Upload the code provided to all your boards. Don’t forget to modify the message to easily identify the sender node
With the boards connected to your computer, open a serial connection with each board. You can use the Serial Monitor, or you can use a software like PuTTY and open multiple windows for all the boards.
You should see that all boards receive each others messages. For example, these are the messages received by Node 1. It receives the messages from Node 2, 3 and 4.
You should also see other messages when there are changes on the mesh: when a board leaves or joins the network.
Exchange Sensor Readings using ESP-MESH
In this next example, we’ll exchange sensor readings between 4 boards (you can use a different number of boards). Every board receives the other boards’ readings.
As an example, we’ll exchange sensor readings from a BME280 sensor, but you can use any other sensor.
Parts Required
Here’s the parts required for this example:
- 4x ESP boards (ESP32 or ESP8266)
- 4x BME280
- Breadboard
- Jumper wires
Arduino_JSON library
In this example, we’ll exchange the sensor readings in JSON format. To make it easier to handle JSON variables, we’ll use the Arduino_JSON library.
You can install this library in the Arduino IDE Library Manager. Just go to Sketch > Include Library > Manage Libraries and search for the library name as follows:
If you’re using VS Code with PlatformIO, include the libraries in the platformio.ini file as follows:
ESP32
monitor_speed = 115200
lib_deps = painlessmesh/painlessMesh @ ^1.4.5
ArduinoJson
arduinoUnity
AsyncTCP
TaskScheduler
adafruit/Adafruit Unified Sensor @ ^1.1.4
adafruit/Adafruit BME280 Library @ ^2.1.2
arduino-libraries/Arduino_JSON @ ^0.1.0
ESP8266
monitor_speed = 115200
lib_deps = painlessmesh/painlessMesh @ ^1.4.5
ArduinoJson
TaskScheduler
ESPAsyncTCP
adafruit/Adafruit Unified Sensor @ ^1.1.4
adafruit/Adafruit BME280 Library @ ^2.1.2
arduino-libraries/Arduino_JSON @ ^0.1.0
Circuit Diagram
Wire the BME280 sensor to the ESP32 or ESP8266 default I2C pins as shown in the following schematic diagrams.
ESP32
Recommended reading: ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)
ESP8266 NodeMCU
Recommended reading: ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)
Code – ESP-MESH Broadcast Sensor Readings
Upload the following code to each of your boards. This code reads and broadcasts the current temperature, humidity and pressure readings to all boards on the mesh network. The readings are sent as a JSON string that also contains the node number to identify the sender board.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-mesh-esp32-esp8266-painlessmesh/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "painlessMesh.h"
#include <Arduino_JSON.h>
// MESH Details
#define MESH_PREFIX "RNTMESH" //name for your MESH
#define MESH_PASSWORD "MESHpassword" //password for your MESH
#define MESH_PORT 5555 //default port
//BME object on the default I2C pins
Adafruit_BME280 bme;
//Number for this node
int nodeNumber = 2;
//String to send to other nodes with sensor readings
String readings;
Scheduler userScheduler; // to control your personal task
painlessMesh mesh;
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
String getReadings(); // Prototype for sending sensor readings
//Create tasks: to send messages and get readings;
Task taskSendMessage(TASK_SECOND * 5 , TASK_FOREVER, &sendMessage);
String getReadings () {
JSONVar jsonReadings;
jsonReadings["node"] = nodeNumber;
jsonReadings["temp"] = bme.readTemperature();
jsonReadings["hum"] = bme.readHumidity();
jsonReadings["pres"] = bme.readPressure()/100.0F;
readings = JSON.stringify(jsonReadings);
return readings;
}
void sendMessage () {
String msg = getReadings();
mesh.sendBroadcast(msg);
}
//Init BME280
void initBME(){
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
// Needed for painless library
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("Received from %u msg=%s\n", from, msg.c_str());
JSONVar myObject = JSON.parse(msg.c_str());
int node = myObject["node"];
double temp = myObject["temp"];
double hum = myObject["hum"];
double pres = myObject["pres"];
Serial.print("Node: ");
Serial.println(node);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(hum);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pres);
Serial.println(" hpa");
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
void setup() {
Serial.begin(115200);
initBME();
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
userScheduler.addTask(taskSendMessage);
taskSendMessage.enable();
}
void loop() {
// it will run the user scheduler as well
mesh.update();
}
The code is compatible with both the ESP32 and ESP8266 boards.
How the Code Works
Continue reading this section to learn how the code works.
Libraries
Start by including the required libraries: the Adafruit_Sensor and Adafruit_BME280 to interface with the BME280 sensor; the painlessMesh library to handle the mesh network and the Arduino_JSON to create and handle JSON strings easily.
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "painlessMesh.h"
#include <Arduino_JSON.h>
Mesh details
Insert the mesh details in the following lines.
#define MESH_PREFIX "RNTMESH" //name for your MESH
#define MESH_PASSWORD "MESHpassword" //password for your MESH
#define MESH_PORT 5555 //default port
The MESH_PREFIX refers to the name of the mesh. You can change it to whatever you like. The MESH_PASSWORD, as the name suggests is the mesh password. You can change it to whatever you like. All nodes in the mesh should use the same MESH_PREFIX and MESH_PASSWORD.
The MESH_PORT refers to the the TCP port that you want the mesh server to run on. The default is 5555.
BME280
Create an Adafruit_BME280 object called bme on the default ESP32 or ESP8266 pins.
Adafruit_BME280 bme;
In the nodeNumber variable insert the node number for your board. It must be a different number for each board.
int nodeNumber = 2;
The readings variable will be used to save the readings to be sent to the other boards.
String readings;
Scheduler
The following line creates a new Scheduler called userScheduler.
Scheduler userScheduler; // to control your personal task
painlessMesh
Create a painlessMesh object called mesh to handle the mesh network.
Create tasks
Create a task called taskSendMessage responsible for calling the sendMessage() function every five seconds as long as the program is running.
Task taskSendMessage(TASK_SECOND * 5 , TASK_FOREVER, &sendMessage);
getReadings()
The getReadings() function gets temperature, humidity and pressure readings from the BME280 sensor and concatenates all the information, including the node number on a JSON variable called jsonReadings.
JSONVar jsonReadings;
jsonReadings["node"] = nodeNumber;
jsonReadings["temp"] = bme.readTemperature();
jsonReadings["hum"] = bme.readHumidity();
jsonReadings["pres"] = bme.readPressure()/100.0F;
The following line shows the structure of the jsonReadings variable with arbitrary values.
{
"node":2,
"temperature":24.51,
"humidity":52.01,
"pressure":1005.21
}
The jsonReadings variable is then converted into a JSON string using the stringify() method and saved on the readings variable.
readings = JSON.stringify(jsonReadings);
This variable is then returned by the function.
return readings;
Send a Message to the Mesh
The sendMessage() function sends the JSON string with the readings and node number (getReadings()) to all nodes in the network (broadcast).
void sendMessage () {
String msg = getReadings();
mesh.sendBroadcast(msg);
}
Init BME280 sensor
The initBME() function initializes the BME280 sensor.
void initBME(){
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
Mesh Callback Functions
Next, several callback functions are created that will be called when some event on the mesh happens.
The receivedCallback() function prints the message sender (from) and the content of the message (msg.c_str()).
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
The message comes in JSON format, so, we can access the variables as follows:
JSONVar myObject = JSON.parse(msg.c_str());
int node = myObject["node"];
double temp = myObject["temp"];
double hum = myObject["hum"];
double pres = myObject["pres"];
Finally, print all the information on the Serial Monitor.
Serial.print("Node: ");
Serial.println(node);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(hum);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pres);
Serial.println(" hpa");
The newConnectionCallback() function runs whenever a new node joins the network. This function simply prints the chip ID of the new node. You can modify the function to do any other task.
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
The changedConnectionCallback() function runs whenever a connection changes on the network (when a node joins or leaves the network).
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
The nodeTimeAdjustedCallback() function runs when the network adjusts the time, so that all nodes are synchronized. It prints the offset.
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
setup()
In the setup(), initialize the serial monitor.
void setup() {
Serial.begin(115200);
Call the initBME() function to initialize the BME280 sensor.
initBME();
Choose the desired debug message types:
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
Initialize the mesh with the details defined earlier.
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
Assign all the callback functions to their corresponding events.
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
Finally, add the taskSendMessage function to the userScheduler. The scheduler is responsible for handling and running the tasks at the right time.
userScheduler.addTask(taskSendMessage);
Finally, enable the taskSendMessage, so that the program starts sending the messages to the mesh.
taskSendMessage.enable();
To keep the mesh running, add mesh.update() to the loop().
void loop() {
// it will run the user scheduler as well
mesh.update();
}
Demonstration
After uploading the code to all your boards (each board with a different node number), you should see that each board is receiving the other boards’ messages.
The following screenshot shows the messages received by node 1. It receives the sensor readings from node 2, 3 and 4.
Wrapping Up
We hope you liked this quick introduction to the ESP-MESH networking protocol. You can take a look at the painlessMesh library for more examples.
We intend to create more tutorials about this subject on a near future. So, write your suggestions on the comments’ section.
You may also like the following articles:
- Getting Started with ESP-NOW (ESP32 with Arduino IDE)
- Getting Started with ESP-NOW (ESP8266 NodeMCU with Arduino IDE)
- ESP32: ESP-NOW Web Server Sensor Dashboard (ESP-NOW + Wi-Fi)
Learn more about the ESP32 and ESP8266 with our resources:
- Learn ESP32 with Arduino IDE
- Home Automation using ESP8266
- More ESP32 Projects and Tutorials
- More ESP8266 Projects and Tutorials
Thanks for reading.
Hi Sara, incredible stuff you can do with these “IoT” devices!
Just wondering: if you would like to forward the temperature readings (eg with that PHP2MySQL you wrote earlier), would you advice to include that code in each of the nodes in your Mesh (because any of them may or may not be in reach of the actual “working” network with the LAMP server on it – caveat: lots of failed attempt plus if all mesh members succeed, database needs to be instrumented to avoid duplicate uploads), or would you dedicate 1 ESP for “uplink” to the real network?
Thanks for sharing your thoughts!
Hi.
I think it would be better to have one ESP to upload to the database. But it will depend on your project requirements.
I still need to do some more research on this topic to see how to handle different network topologies and requirements.
Regards,
Sara
Hi Sara,
thank you for your suggestion!
I’m wondering if you can “hook up” other devices to this mesh (eg a raspberry pi) – found articles like this: https://github.com/Coopdis/easyMesh/issues/30 so then this pi (which is currently my php/mysql gateway) can simply listen to the mesh 🙂
But indeed, these are other project requirements than initially drawn, but with this mesh, I can try to link to my water well sensor!
Thank you and have a nice day!
Hi Sara,
I did some further reading on this requirement. Apparently this mesh protocol may not be compatible with the wifi modules and TCPIP stacks, so it’s either mesh or wifi, not both at the same time. So I’m not sure on how one “master” ESP32 could “listen” to the mesh and upload the JSON messages towards the wifi (through router).
I found an android app which had a working painlessmesh, however it seems to be broken with the 2020 releases. Then I could at least copy paste the values from the mesh network into my webportal from my phone 🙂
I know this is not exactly what you are looking for, but I have had great success using mosquitto mqtt with painless mesh. My “bridge” node has painless mesh and mosquitto running, and I can pass any mesh messages through to my router, via mqtt. Personally, I have my mqtt broker running on an Rpi, but you could use another ESPxx device. FWIW, I have another Rpi listening to certain topics and populating items into the DB (I have a temperature sensor mesh in my yard).
I am doing project using Mesh and Wifi at same time. when a node receive msg from other nodes, it will post to server, database over wifi. I tried add “post to database over wifi” function in ReceiveCallback. But error http response code -1.
Can you help me?
Do you solved it? I need the same.
you can send an ID or a timestamp for every different reading of a node.
and set the database to avoid duplicated entries.
Very interesting simple mesh. I would also like to know how to get the data out of the mesh and into MQTT running on another computer, such as a R-pi. I would guess that one of the nodes would be dedicated to that function, but I cannot visualize how to prevent duplicate messages….does the painless mesh library handle that?
Thanks,
Dave K.
Hi Dave.
The painlessMesh library provides an MQTT example.
Here it is: https://github.com/gmag11/painlessMesh/blob/master/examples/mqttBridge/mqttBridge.ino
However, I haven’t experiment it yet.
Regards,
Sara
I actually tried this, and it works. Using the link Sara supplied, flash the mqttBridge ino onto a device (I used an ESP8266). This will be your “root” node, and will connect to your mqtt broker. My broker is running mosquito mqtt on a raspberry pi, and I use MQTTfx to send/receive messages on my network.
Anyhow, navigate to the “start here” project (https://github.com/gmag11/painlessMesh/blob/master/examples/startHere/startHere.ino)
and flash this onto one or more “leaf” node devices (again, I used ESP8266, but I’m pretty sure that this works for ESP32 devices as well).
Each of the leaf nodes will broadcast a “Hello from” message across the mesh, and the bridge node device will publish it to the mqtt broker. There are some other instructions in the mqttbridge readme file.
This will get you going with the basics, and it should be what you are looking for.
A couple of FYIs to help you a little bit:
1) The root node should probably be the closest node to the router. Take a look at the “official” docs for more info: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/esp-wifi-mesh.html
2) No matter which wifi channel you set for your mesh, it will always use the channel that the router is using.
3) All of the nodes must use the same hostname, etc. If you look at your wifi map (use your phone, etc), you will see the various nodes, all with the same hostname. They all have different mesh ids and mac addresses, however, if you need to detect individual nodes.
Good luck!
Tony, it looks like you may be conflating the official esp32 mesh (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/esp-wifi-mesh.html) with painlessMesh which is quite different. painlessMesh does not seem to have a root node concept.
Hi Graham. This is what I was going off of: https://gitlab.com/painlessMesh/painlessMesh/-/wikis/Root-nodes
So I am thinking about a project to attempt, I have a rather long driveway and would like to build a detector.
I know I could easily find purchase one but what fun would that be? So my obstacles are :
Driveway approx 700’
WiFi distance from router around 750’
Using WeMos in conjunction with ESP 8266
I have 2 WeMos and 1 ESP Lolin 8266
Would this work for me given the obstacles and boards I have ?
Great project, could be really useful for me. Would you consider expanding this project to include displaying the readings on a web page running on one of the boards accessible on my home wifi?
Hi.
Yes, we are thinking about writing a tutorial about that.
Regards,
Sara
Can you explain the differences between this painless MESH and ESP-NOW? Are the data passed using ESP-NOW to each node rather than a master-slave scenario? Thanks and please keep up the good work.
Great Tutorial, any way future examples can be done in micropython?
Hi.
Thanks for the suggestion.
Unfortunately, at the moment, ESP-MESH is not implemented in micropython yet.
Regards,
Sara
Maybe you can serial connect another dev-board running micropython to an ESP-MESH device and attempt to interface with the micropython in that manner.
I have tried painless mesh number of times in the past and recently.
I don’t know if painless mesh uses any official ESP-MESH protocol feature, but it definitely has many custom features?
Since you have quoted official ESP-MESH, I think you should confirm how painless mesh is exactly related to official espredsif ESP-MESH!
I am fairly experienced with ESP devices and have used them successfully for long time, using both WiFi and ESP-NOW protocols. I would also love to use a reliable mesh-networking.
Painless mesh sounds impressive, but I and some others have found it unreliable after running from few hours to few days, even with very few (less than 6) nodes, tried with both ESP8266 and ESP32 and combination. All nodes are within RF range of each other (within 10-20m).
It generally starts OK but after some random time nodes start dropping off from the network and take very long time (minutes) or never to reconnect. This is unreliable and unacceptable.
Please read ‘issues’ on GitLab.
https://gitlab.com/groups/painlessMesh/-/issues
I suggest that you set up a reasonable size (more than 6 nodes) painless mesh network for number of days or longer and then report how reliable it is.
I enjoy your tutorials, have purchased previous courses and use lot of your tutorials as reference.
Best Regards
Hi Jack.
Thanks for sharing your knowledge about this subject.
We’ve only recently started experimenting with ESP-MESH.
To get started, we experimented with 4 nodes and everything seemed to work fine. But, we’ve only did simple experiments.
We’ll experiment different scenarios and see how it goes.
Did you experiment with any other library that supports mesh networking?
Thank you so much for sharing your thoughts about this.
Regards,
Sara
Hi Jack, you mentioned that you already made a mesh connections using WIFI and ESP-NOW. I would like to ask, how you can be able to do that? And if the code of Send-to-many and Receive-from-many using ESP-NOW protocol can be combined together? Thank you.
Awesome post!
The range of the MESH network is really good. I tested here with 3 modules in an area where the router coverage doesn’t work very well and, surprisingly, the ESP-MESH bypassed the fisical problems which blocks my router signal (the router signal usually is weak because there is an elevator in the middle).
Thank you very much for this great post!
Hi Eduardo
Did you try anything else with ESP32?
Yes Manuel,
My tests used one ESP32 and two ESP8266. The ESP32 and one ESP8266 were reading sensors (DHT11 on the ESP32 and a BMP280 on the ESP8266) and the other ESP8266 was connected to an OLED display, printing the sensor readings sent by the other two devices. Everything working like a charm!
Regards!
Hi there.
Great post!
Maybe you can post an article about TaskScheduler?
Seems a great tool.
Hi Nuno.
Yes. That is a great topic that many of you might be interested in.
It is already in my to-do list.
Regards,
Sara
Hi Sara, do u any example on esp ble mesh?
Hi.
At the moment, we don’t have any examples of BLE mesh.
Regards,
Sara
The documentation on TaskScheduler is very good and with lots of examples. The basics are pretty simple. I use it in all my projects, have you taken a look at the documentation? I’m not sure an article is needed, although it could use more exposure, it is fantastic.
Good tutorial and also good comments 🙂
Thank you, everyone.
A simple question. Is it possible to automatically number each node? that is, when you insert a new node it recognizes it as “one more” and numbers it.
Hi Manuel.
The mesh recognizes the nodes by the board chip ID.
You might add something to your code that saves the nodes’ chip IDs and numbers the nodes accordingly.
Regards,
Sara
Hi Sara. This is exactly the approach that I have taken. As you say, each node has a unique id (based off of the mac address). My root node (mqtt bridge, actually) maintains a small map of names/ids (backed up in a file using littleFS) of nodes in the mesh. Each node is given a hard-coded name, and they can report that name via a mesh message command. The bridge updates the file as nodes come online (using the New Connection callback), and I can route messages/commands to the desired node(s) by looking up the id in the name table. The nice thing is that mac addresses don’t ever change, so, once a node is mapped, I know that its id will always be the same.
I have a couple of ESP32 scattered around, all linked via my local router and my home network. Each has a fixed IP. I have them talking directly to each other, no problem.
I cannot see how this protocol would work if these ESPs cannot directly contact each other – your comments?
Hi.
Instead of broadcasting, you can send messages to specific boards.
We haven’t explored that topic yet.
Regards,
Sara
Hello Sara and Rui.
How do I only get the message text in the serial monitor?
Without further information.
I’m doing something wrong but don’t understand what I’m doing wrong to get this done.
I only learn very slowly, that’s always my problem.
Please give me a hint
Greetings from the old man in the Netherlands.
Hi Bert,
the easiest way is to try one of the simple “Hello World” samples included in the Arduino IDE. If you can’t see these “Hello World” print-outs on your serial, you are not up to a project like this one 🙂
Greetings from Belgium!
I think I’m misinterpreting it, sorry about that.
How do I change this rule.
Serial.printf (“startHere: Received from% u msg =% s \ n”, from, msg.c_str ());
I only get the text “Hi from node1” in the serial monitor.
And not any other info.
Thanks for your understanding.
Sorry google translate is killing me and me text .
I meant
So that I only get the text “Hi from node1” in the serial monitor.
And not any other info.
Thanks for your understanding.
I could also post in Dutch, but then Sara cannot read it 🙂
Did you upload your code to another ESP device and configure it as node 2? If you only get messages from Node1, you only have 1 node in your mesh.
it works now, after sam studie 🙂
Hello
Thanks again, Sara and Rui.
Do you know if there is any limitations about the number of nodes? can we assume 500 nodes or even 1000?
Thanks
Hi.
I don’t know.
At the moment, we only experimented with 4 nodes.
Regards,
Sara
In the depths of the internet it is said that the number depends only on the RAM and you will probably reach the end at 50…60.
There it is recommended to take off several meshes and to merge them into one mesh … But that’s where I got out of my mind 😉
of course I didn’t put that in the bookmarks …
…sorry 😉
one more question.
If nodes didn’t see each other what happened?
If they don’t “see” each other, they won’t receive its messages.
Regards,
Sara
Oops, typo/copy-paste error in:
void receivedCallback( uint32_t from, String &msg ) {
…
double pres = myObject[“pres”];
…
Serial.print(“Pressure: “);
Serial.print(temp);
Serial.println(” hpa”);
The temp should be pres. The temp shows up twice in the printout sample above.
Hi.
You’re right.
Thanks for pointing that out.
It’s fixed now.
Regards,
Sara
You guys are awesome! Keep doing what you’re doing! Helping us inch into the IoT world!
Thanks 😀
I salute you, I especially wish you health and thank you for the additional study material, but also another problem in my :). But you continue to move on successfully. A lot of good.
But I have another problem. If anyone can advise me. I’ve studied a lot of pages on the Internet. RPI3B and SSD disc mSATA 500GB on the board from GEEKWORM – loading Raspbian. Not from a flash disc (not an SD card). I split the SSD disk, modified the config and another file, but the system does not load. In Raspbian, it can be copied to disk, so it works. I’m sore and thank you.
Hi.
I’m sorry but I haven’t experimented with that and I don’t have any tutorials about that subject.
You’ll get better guidance and help if you post your question on Raspberry Pi related forums.
Regards,
Sara
Unfortunately I have no real success with this example.
I use ESP-01 modules myself, because every chip has its own number anyway, I use this one too – every node has the exact same code.
For sending I decided to use the temperature of a DS18B20 – the integration took longer than expected – but it worked out fine at some point …
– search next sensor
– we are at the end of the list or is this sensor place empty -> to the first sensor
– if this sensor place is occupied -> the conversion time is over -> read sensor, enter values
– start new conversion, remember the time
In the sendMessage(), if a valid sensor was found, it was included in the message – otherwise only the ‘Hello from xyz’.
I also added an output to the terminal, that 5 seconds after the last output a dot is sent (and after 80 the line is wrapped) – so I can at least see that the node hanging on the PC is still alive.
This works for a few minutes, depending on the order in which I supply the nodes – the PC node should be the first one, older nodes I don’t get displayed.
What else I changed in the code:
Access data SSID/PW in separate tab
translated with deepl.com
Translated with http://www.DeepL.com/Translator (free version)
Thank you for the reply.
You have serial use two esp’s to connect to a router. One should be connected to the router and another one should be connected to esp which is connected to router through serial communication protocol
Great work
Can this mesh protocol coexist with wifi for at least one esp32?
thanks
I have the same problem. This example could not work properly while cowork “ESP32 Web Server.”
Thanks for a great tutorial.
Hello!
Can each of the boards act as router so that in case the fourth is out of range of the first but within the range of the others, the first can still communicate with the fourth?
You can do that,
However that is not implemented in this tutorial yet. This tutorial only shows broadcast mode.
Regards,
Sara
Thank you for that.
Hello, I got the following error. I don’t understand it. Please help.
‘JSONVar’ was not declared in this scope
…\sketch_dec11a.ino: In function ‘String getReadings()’:
sketch_dec11a:42:3: error: ‘JSONVar’ was not declared in this scope
JSONVar jsonReadings;
^
sketch_dec11a:43:3: error: ‘jsonReadings’ was not declared in this scope
jsonReadings[“node”] = nodeNumber;
^
sketch_dec11a:47:14: error: ‘JSON’ was not declared in this scope
readings = JSON.stringify(jsonReadings);
^
…\sketch_dec11a.ino: In function ‘void receivedCallback(uint32_t, String&)’:
sketch_dec11a:67:3: error: ‘JSONVar’ was not declared in this scope
JSONVar myObject = JSON.parse(msg.c_str());
^
sketch_dec11a:68:14: error: ‘myObject’ was not declared in this scope
int node = myObject[“node”];
^
Multiple libraries were found for “WiFi.h”
…\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
‘JSONVar’ was not declared in this scope
Hi Larry, check your code and see if this line is missing: “#include <Arduino_JSON.h>”.
If it’s missing, just add it to the beginning of your code and the problem will be solved.
Thank you. Solved.
The one advantage I see with painlessMESH over ESP-NOW is you can mix ESP32 & ESP8266 in the network but I’m wondering about low power and sleep mode and how the MESH might work with that. I’ve been slowing learning and building the code required for a simple 5 node system to monitor 2 water tanks, a septic system and a weather sensors (BME280) using ESP-NOW. The payload is not big but one node will need to be battery(solar charged) powered so obviously low power and sleep mode for that node is important. Have you done any tests with this in mind with the painlessMESH library?
Hi.
Thanks for you comment.
At the moment, we haven’t done any tests regarding power comsumption.
Regards,
Sara
If you don’t need instant readings, you could synchronize time across nodes, then sleep for a set time like 1 hour. The weather sensor could wake more often, save readings and report every hour. It can still take some time for the mesh to form, so might take a minute.
You could divide your nodes into leaf nodes that sleep and always-on intermediate nodes that route packets further than the root router. Then nodes could wake any time, e.g. on a flood sensor.
For lowest power use ESP-NOW on an 8266 (see the RNT tutorials on this) with a programmed wake interval. You’ll have to write your own mesh packet forwarding for nodes too far to reach your base node close to the WiFi router. Mesh is simpler if you preprogram which nodes can pair and which must forward. (The ESP-MESH figures this out on signal strength.) Nodes can sleep until some time, for leaf nodes send a packet and wait for reply, repeat on timeout for some retries. For forwarding nodes, wake and listen for some interval. If no message from a leaf, forward a no-response message. The root node can send a time-sync packet that gets forwarded so nodes can wake within the same second.
Using an ESP-8266 without the USB-serial gives longest battery life. Most of the ESP dev boards connect the serial-USB to the 3.3V CPU power, so drain the battery even when the USB is unplugged.
Thank you for this detailed response Carl.
With what you’ve said it will be better for me to add an extra outdoor node that will be the outdoor “HUB” and is always on. No distances are big and all have unobstructed line of sight. I’ll move the weather sensor to the “HUB” then the only value from the sleeping node will be a tank level which only needs to happen once or twice a day.
Having an always on hub connected to the weather sensors is a good idea. You can just add a bigger solar cell and LiPo (in case of rainy days). I forgot to mention the voltage regulator chips have varying quiescent current and can make a big difference. The lowest ESP32 devboard I noticed had 25uA deep sleep current. So that means you can run your tank CPU for several years on 3 AA or AAA batteries, assuming it sleeps many hours between readings.
You can use google to search for current consumption of various boards. There is a spreadsheet from Andreas Spiess for ESP32 with deep sleep power https://docs.google.com/spreadsheets/d/1Mu-bNwpnkiNUiM7f2dx8-gPnIAFMibsC2hMlWhIHbPQ/edit#gid=0
Rui/Sara, It would be great if the makeradvisor buying guides included deep sleep power. It’s not so easy to measure but important for the battery/solar powered projects.
After a bit more reading (a lot more actually) I now see you are referring to two different mesh libraries that approach the mesh topology differently. ESP-MESH (WiFi) is by Espressif Systems (Shanghai) CO., LTD and follows the more traditional IP sub-net structure which limits leaf to root node to a single path. The “painlessMESH” on the other hand is a true mesh from the sense that if one path is down and a second path exists it will still send the message from leaf to root. In fact this topology is how the military, SWAT and other emergency services do front line comms and video back to command centers. If you are interested have a look at Silvus Technologies.
The caveat as I see it (and it would be nice if I’m wrong) is that if the device is a “painlessMESH” node it can’t be an access point and you’d need to have a second device connected together by serial to create the WiFi gateway? The “painlessMESH” people state:
“painlessMesh subscribes to WiFi events. Please be aware that as a result painlessMesh can be incompatible with user programs/other libraries that try to bind to the same events.”
So my question is have you tried creating a root node WiFi gateway with “painlessMESH” on a single device?? or is it as I have assumed??
Hello, I don’t know if I understood what you are trying to do. But I think I have the same interest. In my case, I would like to generate a MESH network that has more than just to pass sensor data, it can be used as a WiFi repeater. I suppose that in this way I could achieve a way to locate, for example, my cellular device in the house so that the ESP reacts to the presence, because it would connect to the repeated signal with more intensity. In your experience, would this be possible?
Yes I do have the same doubt, no where in the code they have given the Wi-Fi credential thru which it will connect, is the same mesh network id and password is same as Wi-Fi credentials?
Hi.
I’m not sure I understood your question.
In the tutorial, I mention the following:
“Before uploading the code, you can set up the MESH_PREFIX (it’s like the name of the MESH network) and the MESH_PASSWORD variables (you can set it to whatever you like).”
Regards,
Sara
Hi Sara,
my doubt was, say I have 4G router with Wi-Fi Credentials say Username and Password thru which many other devices connect to internet eg., PC, phone etc., now I have 5 ESP32 boards which will also work within same network as per your tutorial whether I can use the MESH_PREFIX and MESH_PASSWORD is nothing but Wi-Fi credentials of the network is that what you are saying? I’m yet to try the code as I do not want to disturb the current network as it is working with Wi-Fi credentials! Your efforts are commendable and I often refer your website for my coding! Keep it up!
Hi.
The MESH network doesn’t use your wi-fi network.
The mesh password and mesh prefix are just made up so that you can connect together devices using on the same mesh network.
You can have multiple mesh networks. Devices know which network they should join by using the mesh prefix and password.
I hope this is clear.
Regards,
Sar
Hi Sara, Thanks for your reply and All the best for your works! Let me try a network in which the mesh of ESP32 along with Internet so that I can try to get data from the device from anywhere using a app or browser based UI.
We loved this project so much that we featured it in this weeks episode of The Electromaker Show! https://youtu.be/RShENYIlInk?t=1082
Hi.
Thank you so much.
I’m really flattered for those nice words in your video.
I wasn’t expecting that at all.
I’m glad you found the tutorial useful. And thank you for sharing.
We intend to create more tutorials about this subject. Stay tuned.
Keep up the good work.
Regards,
Sara
I’ve taken a look at the API for the Espressif’s Mesh protocol. Is there a way to set the number of layers with the painlessMesh library. I am looking to construct a control system for a large number (500-1000) of PWM outputs. I have previously developed a system with XBee 2 units, but seperate PMW controls were necessary. The ESP32 seems an ideal, low cost solution.
Hi.
I still haven’t taken a look into that.
But, I advise you to take a look at the examples provided in the painlessmesh library and see if there is any clue for what you want to do.
https://github.com/gmag11/painlessMesh/tree/master/examples
Regards,
Sara
Rui and Sara
I just want to repeat my congratulations on your work. Thank you, thank you!
I’m still waiting for a mesh setup also connected to Wifi.
It would be interesting to have some mesh points to store and send data (voltage, GPS information, etc.) and put everything in a single database.
Greetings
Manuel
Hi Manuel.
Mesh network connected to wi-fi is in our big to-do list.
Thanks.
Regards,
Sara
Manuel, this too was on my list to get sorted but I’ve been struggling with serial between to ESP devices to send the updates to a WiFi connected controller. Then I found a library that makes it simple. Multiple formats supported. I tested using software serial both ends and it works a treat. Have a look at this SerialTransfer library https://github.com/PowerBroker2/SerialTransfer NOTE I’ve not tested on ESP only ATMega328, that’s the next step!
Ralph I want to test this library using serial 2 or serial 3 with esp32 boards.
Which pair of files I should use?
There is not enogh information in the read me file but I see three pairs datum, i2c, and spi
Thanks
Philip, I used software serial and just random digital pins. I set up a STX31 Temp and Humidity sensor and sent updates on button push. Just change it to what you want. Also I Used the “Structure” packet method. I haven’t tried the “Array” method yet. I’ve zipped up my test code and shared on my Google drive. Here’s the link. Good luck. https://www.dropbox.com/s/jty8lx09w8zlr30/serialTransfer_example.zip?dl=0
Many thanks Ralph
I will give it a shot
Philip
Thank you for the great tutorial.
I would like to implement the same concept. I have multiple ESP-01 and each has one sensor. I want to create a mesh network to be able to cover a bigger range, then allow one main ESP to connect to a router so that I can send the data from the rest of the ESPs to a website.
How can I have one ESP connect to the mesh and the internet at the same time? So that it can receive data from other nodes and send it to a website
Hi.
I recommend taking a look at the examples provided by the library: https://github.com/gmag11/painlessMesh/tree/master/examples
Regards,
Sara
Hi
Thx for this great job
I have experiment myself and works fine
I have a problem with the wifi band because all nodes act as AP and the band will be saturate. This is amplified by the use off 40Mhz wide. I have not found how to define 20Mhz and change the channel.
I have 2 questions to go further
– do you know if an equivalent library exist based on espnow ?
– how to perform espnow connection between node1 to node2 And have node2 in the painlessmesh network at the same time ?
I will try a base structure network with painlessmesh and espnow connections between the base structure and dedicated sensors.
NodeA, NodeB,NodeC etc painlessmesh
NodeA1 NodeA2 NodeA3 to NodeA with espnow
NodeB1 NodeB2 NodeB3 to NodeB with espnow
Thx for ur reply
Eric
Thank you for this tutorial. It inspired me to do some further research and to build opon this demonstration example. It will be used in one of my college classes on Mesh networking.
Currently my setup is as follows.
7 sensors (BMP280 (I²c))(ESP8266) 1 Controll node with a relay board(I²C)(ESP8266) and a root node (ESP32) wich connects to a RPI 3B generated hotspot. Values are sent using UDP packets from the root node to the RPI which put them into a DB using a python script.
Everything works fine.
One of the great advantages is that I can easily create new nodes with minimal changes to code and i can create the net with both ESP32’s and ESP8266’s using the RPI’s I can easily setup multiple mesh’es as they are the “true” root node’s inside this network.
Thank you 😉
Hello Sara and Rui. I have experimented a lot with ESP-MESH.
That went pretty well until I had a total of 4 Node’s up and running.
Too often things went wrong. The distance between the farthest Node was 10 meters with a wall in between. It remained mutually unstable in terms of receipt contunity. (1 Node, s is in the living room with the information of the others on a TFT screen to control).
I then decided to equip all Node’s with an external antenna. Because I suspected that the signals were distorted or too weak. I work with 4 times Wemos D1 Mini. Now after installing the Node, s with external antennas, it has been completely flawless for a few days. I do not know how many Node, s maximum in a group can work together, I know that ?
Greetings the old man Bert.
Many thanks for all these great and comprehensive tutorials Sara and Rui, they have been a really great anti-dote to lockdown isolation over ther last 6 or 8 months for me!
However, I am struggling with something in this one that I really don’t get. You say: “With the boards connected to your computer, open a serial connection with each board.”
Do you have more instructions on how to do this? I have an iMac with a 7-port USB hub connected to one of its USB ports. I have separate USB leads going from 2 USB hub outlets to each of 2 ESP32s running separate sketches but I cannot open more than one Serial Monitor window at once, and that only shows messages from one of the ESP32 boards at once. How do I get to see messages from both boards on the same serial monitor window?
Hi.
You can use putty and open several windows: https://www.ssh.com/ssh/putty/mac/
I never tried on MAC, but it should be similar with Windows.
Regards,
Sara
Thanks Sara.
The point I hadn’t appreciated is that one needs to start a new instance of the Arduino IDE each time one introduces a new node into the mesh. A new IDE instance allows one to select a new port name in the ‘Tools’ tab each time. This link helped me: vishalbhingare.wordpress.com/2015/10/13/how-to-open-multiple-arduino-ide-on-same-computer-mac/.
Thanks for the Putty link. I’ll maybe try that when I know a bit more about what I’m doing!
Regards,
John
Hi.
Yes, you are right.
Thanks for sharing that link.
Regards,
Sara
Hi
Can anyone tell me is it possible to use ESP mesh under BLE protocol?
and I want to use mqtt here as a router.
Yes both Ble and mesh works
At this momment i cant work with espnow and mesh
But ble work fine
Can u please tell me is there any library like painless mesh where I can find ble mesh example?
Sorry I have not ble mesh
I have ble serveur/client AND painless mesh on the same esp32 module
It work but this two library are heavy for the flash memory
I have not found a mesh ble library
Thank you for the information
Can I add mqtt here to store the data to a central??
With painless mesh library you have an example of mqttbridge
Sorry I have not ble mesh
I have ble serveur/client AND painless mesh on the same esp32 module
It work but this two library are heavy for the flash memory
I have not found a mesh ble library
How long does it take to send data and receive data?
I have this scenario of 4 nodes. But Node 4 and node 1 are too far away that they are not in range. So in this case will nodes 3 and 2 will help node 1 and 4 to be connected by acting like a bridge in between? basically The message from node 4 will reach node 3 and node 3 will pass that message to node 2 and node 1. Is that possible in this?
Hi.
Yes, that is possible.
But, you have to configure it in the code of your boards.
The examples in this tutorial don’t do that.
Take a look at all the examples provided by the library, it will help.
Here are the examples: https://github.com/gmag11/painlessMesh/tree/master/examples
Regards,
Sara
Hello, how did you feed the other ESP32? At the moment I am trying to work on sending messages through the basic example of the library, I put the same programming in three, I only changed the name of the nodes, one is connected to the computer, the others fed with a cell phone charger. I did not get any messages on the serial monitor. What can it be?
Hi Mel.
After powering the boards, press the RST button so that they start running the code.
Regards,
Sara
Hello, I just wanted to ask if PainlessMesh.h does auto-routing to messages, in other words, if I have 3 nodes (node1-node2-node3), node 3 Is out of node1 range but in node2 range, in this case, if node3 wanted to send a message to node 1, will PainlessMesh.h make node 2 an AP or something like that so that the message is delivered between node 3 and node 1? or the message won’t be delivered?
Hello Sara and Rui.
Quite informative and useful his tutorial.
I would like to know if it is possible to establish an ESP-MESH using the LoRa communication protocol, since I want to implement it in an area where it does not have Wi-Fi range. (After this I intend to connect one of these devices to a root node that will be connected to Wi-Fi).
Can this be done?
Hi.
Yes, you can do that. But this tutorial is not appropriate for that because this is not related to LoRa.
You can have several LoRa devices communicating with each other.
Then you can have one LoRa node that connects to Wi-Fi. In this subject, this tutorial can help: https://randomnerdtutorials.com/esp32-lora-sensor-web-server/
Regards,
Sara
Thanks for following up on my question and for the recommended resource.
Hey Sara, If I don’t want to introduce a WiFi node, can you recommend a mesh library?
Hi Sara, how was ESP32 fed? By the computer itself? I’m having a problem, the following error appears:
first: 0x1 (POWERON_RESET), initialization: 0x13 (SPI_FAST_FLASH_BOOT)
flash reading error, 1000
ets_main.c 371
ets of June 8, 2016 00:22:57
first: 0x10 (RTCWDT_RTC_RESET), initialization: 0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP: 0xee
clk_drv: 0x00, q_drv: 0x00, d_drv: 0x00, cs0_drv: 0x00, hd_drv: 0x00, wp_drv: 0x00
mode: DIO, clock div: 1
load: 0x3fff0018, len: 4
load: 0x3fff001c, len: 1216
ho 0 tail 12 room 4
load: 0x40078000, len: 10944
load: 0x40080400, len: 6388
entry 0x400806b4
A BMP280 sensor was not found!
From what I found on forums, it can be underfed. Have you had this problem? Or would you know how to solve it?
Thank you in advance.
Hi
Your error says “BMP280 not found”.
Is your sensor connected properly?
Yes, I was powering the ESP32 through the computer.
Regards,
Sara
Maybe try another USB cable. There are good ones, and bad ones. I have tossed away couple of bad ones who gave erroneous behavior.
Good luck!
So I’m trying the first tutorial, just sending some Hi broadcast messages but I’m not getting those messages, instead, this is what is shown in the serial monitor of the COM4, where I connected my node 1:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
setLogLevel: ERROR | STARTUP |
STARTUP: init(): 0
STARTUP: AP tcp server established on port 5555
Then I connected another node and this is what its shown in the serial monitor of its respective COM9:
Pretty similar, but with some diferencies. Any one has a hint of what isn’t working properly? I mean, I don’t see the Hi messages, so I suposse it is not intended to work like this.
Thanks in advance for your help.
Same here!!
I read in another forum on “SPIFFS” that this error might be because of how the “Flash Mode” is set when you compile and upload. It was said changing the mode from “QIO” to “DIO” or visa versa will help.
Apparently not all boards use the same flash memory which leads to some having this problem because of how the IDE sets a board default.
Good luck
Cheers
Thanks a lot Ralph but unfortunately it doesn’t work by changing that too..
I think MESH PREFIX or PASSWORD should be more 10 words. I have solved.
elongate a password
Hello Sara and Rui, congratulations on your work, it has helped me a lot. Doubtful, did you implement it only using the I2C protocol? I need to use the SPI protocol, and I am not able to implement this transition. Would you know how to tell me how to do it?
Hello Sara and Rui, congratulations on the project. Was the work implemented using only the I2C protocol? I need to use the SPI protocol and I cannot implement this transition. Could you tell me how to do this?
Hi, Your tutorials are awsome!
After reading: ESP-MESH with ESP32 and ESP8266: Getting Started (painlessMesh library) I managed to make a mesh network as in this chapter:
Exchange Sensor Readings using ESP-MESH, and it works fine.
Since I want to load my code over-the-air I have added code from your tutorial about ElegantOTA.
The ElegantOTA works fine in a separete sketch but merged into ESP-MESH I can´t open the web page in the browser with the ip-address copied from the serial monitor. If I comment out the line
“mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
the web page open with the text “Hi! I am ESP32.” as it should.
Is there anyone who knows more about this?
Hello, thanks for the tutorial about Mesh Network. I have a problem with the library, this is the error:
“In file included from C:\Users\Vidangos\Documents\Arduino\libraries\Painless_Mesh\src/painlessMesh.h:10:0,
from D:\Selim\Tesis\Mesh_Broadcast_Message\Mesh_Broadcast_Message.ino:8:
C:\Users\Vidangos\Documents\Arduino\libraries\Painless_Mesh\src/painlessmesh/configuration.hpp:31:22: fatal error: AsyncTCP.h: No such file or directory
compilation terminated.
exit status 1
Error compilando para la tarjeta ESP32 Dev Module.”
Can you help me please? I have a ESP32 DevKitc_V4
Hi.
You need to install the AsyncTCP.h library.
Regards,
Sara
I got the same error. The AsyncTCP lib is installed.
The libs are localy on my hd. Its a ondrive folder could it be a problem?
Hello, congratulations, good work with Rede-Mesh. I’m having trouble implementing ESP32-Mesh using the SPI protocol. Would such an implementation be possible?
Hi.
What do you mean?
Use SPI with the sensor?
Yes, I think you can do that.
Regards,
Sara
Hi Sara,
I tried searching “all” over the net for a way to do TWO way communication from one (master) node to multiple (Slave) nodes. Either its not covered or its so easy that its not being covered.. :/
Could you explain if any of your guides are covering this? or how you would approach this case?
/Kasper.
Hi.
You can find all the examples provided by the painlessmesh library here: https://gitlab.com/painlessMesh/painlessMesh/-/tree/master/examples
We have tutorials for those configurations with ESP-NOW communication:
https://randomnerdtutorials.com/esp-now-two-way-communication-esp32/
https://randomnerdtutorials.com/esp-now-one-to-many-esp32-esp8266/
https://randomnerdtutorials.com/esp-now-many-to-one-esp32/
Regards,
Sara
dear all
i can not upload basic code sample for ESP8266. Can everyone help me
Hi.
Can you provide more details?
What happens when you try it?
Regards,
Sara
HI
I try your esp-mesh tutorial, good and easy. when I would like try on esp32 I have this type of error.. help help
“Arduino:1.8.13 (Windows 7), Scheda:”DOIT ESP32 DEVKIT V1, 80MHz, 115200, None
In file included from C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessmesh/ntp.hpp:16,
from C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessmesh/mesh.hpp:6,
from C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessMeshConnection.h:16,
from C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessMesh.h:20,
from C:\Users\xsf4\Documents\arduino\Code\TestMesh_A\TestMesh_A.ino:8:
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessmesh/router.hpp: In function ‘void painlessmesh::router::handleNodeSync(T&, painlessmesh::protocol::NodeTree, std::shared_ptr)’:
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessmesh/router.hpp:162:26: warning: lambda capture initializers only available with -std=c++14 or -std=gnu++14
mesh.addTask([&mesh, remoteNodeId = newTree.nodeId]() {
^~~~~~~~~~~~
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessmesh/router.hpp:189:26: warning: lambda capture initializers only available with -std=c++14 or -std=gnu++14
mesh.addTask([&mesh, nodeId = newTree.nodeId]() {
^~~~~~
In file included from C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/painlessMesh.h:23,
from C:\Users\xsf4\Documents\arduino\Code\TestMesh_A\TestMesh_A.ino:8:
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/arduino/wifi.hpp: In member function ‘void painlessmesh::wifi::Mesh::eventHandleInit()’:
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/arduino/wifi.hpp:252:22: error: ‘SYSTEM_EVENT_SCAN_DONE’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE);
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/arduino/wifi.hpp:261:22: error: ‘SYSTEM_EVENT_STA_START’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_START);
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/arduino/wifi.hpp:272:22: error: ‘SYSTEM_EVENT_STA_DISCONNECTED’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\xsf4\Documents\Arduino\code\libraries\Painless_Mesh\src/arduino/wifi.hpp:282:22: error: ‘SYSTEM_EVENT_STA_GOT_IP’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
^~~~~~~~~~~~~~~~~~~~~~~
Più di una libreria trovata per “WiFi.h”
Usata: C:\Users\xsf4\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-alpha1\libraries\WiFi
exit status 1
Errore durante la compilazione per la scheda DOIT ESP32 DEVKIT V1.
Hi.
Double-check that you’ve installed all the following dependencies:
ArduinoJson (by bblanchon): https://github.com/bblanchon/ArduinoJson
TaskScheduler: https://github.com/arkhipenko/TaskScheduler
ESPAsyncTCP (ESP8266): https://github.com/me-no-dev/ESPAsyncTCP
AsyncTCP (ESP32): https://github.com/me-no-dev/AsyncTCP
Regards,
Sara
Same problem and I reinstalled all the dependencies and it still didn’t work.
Him again.
Try updating your ESP32 boards’ installation.
Go to Tools > Board > Boards Manager and search for esp32. Update to version 1.0.6.
I’ve just tested the example and it is compiling fine.
Regards,
Sara
Hi,
Thanks for your project.
Please help me, when i compiled my code (basic) i have this error:
C:\Users\Mahjabin\Documents\Arduino\libraries\Painless_Mesh\src\painlessMeshConnection.cpp:640:21: error: ‘SYSTEM_EVENT_STA_GOT_IP’ is not a member of ‘arduino_event_id_t’
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
Would you please tell me what is the priblem ?
Thanks
Hi.
Do you have an ESP32 board selected in Tools > Board?
Make sure you have an ESP32 board selected before compiling the code.
Regards,
Sara
800 / 5000
Résultats de traduction
Hello everyone ,
I started the realization of this project.
But at the first complilation on IDE Arduino 1.8.15 and although having correctly installed the libraries, I got this error:
I uninstalled the library, then reinstalled it is always the same.
Alternatives for AsyncTCP.h: []
ResolveLibrary (AsyncTCP.h)
-> candidates: []
In file included from C: \ Users \ lmgmo \ OneDrive \ Documents \ Arduino \ libraries \ Painless_Mesh \ src / painlessMesh.h: 10: 0,
from C: \ lmg2020 \ base_lmg_intel \ ESP-MESH_Basic \ ESP-MESH_Basic.ino: 8:
C: \ Users \ lmgmo \ OneDrive \ Documents \ Arduino \ libraries \ Painless_Mesh \ src / painlessmesh / configuration.hpp: 31: 22: fatal error: AsyncTCP.h: No such file or directory.
Thank you for your help, I am a beginner and do not have a perfect command of English.
Gerard
Gerard
What the error is saying to you is that you haven’t got the “AsyncTCP” library installed. I’m guessing you are using an ESP32 so here’s the link to the correct library https://github.com/me-no-dev/AsyncTCP
Good luck
mac
just remove Arduino ide and install a new one and the library too
Hello,
I am trying to compile the following example code below, and I am getting these compile errors:
C:\Users\cjh39\Documents\Arduino\libraries\painlessMesh-master\src/arduino/wifi.hpp:252:22: error: ‘SYSTEM_EVENT_SCAN_DONE’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE);
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\cjh39\Documents\Arduino\libraries\painlessMesh-master\src/arduino/wifi.hpp:261:22: error: ‘SYSTEM_EVENT_STA_START’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_START);
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\cjh39\Documents\Arduino\libraries\painlessMesh-master\src/arduino/wifi.hpp:272:22: error: ‘SYSTEM_EVENT_STA_DISCONNECTED’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\cjh39\Documents\Arduino\libraries\painlessMesh-master\src/arduino/wifi.hpp:282:22: error: ‘SYSTEM_EVENT_STA_GOT_IP’ is not a member of ‘arduino_event_id_t’
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
^~~~~~~~~~~~~~~~~~~~~~~
We have the following libraries installed
ArduinoJson (by bblanchon): https://github.com/bblanchon/ArduinoJson
TaskScheduler: https://github.com/arkhipenko/TaskScheduler
ESPAsyncTCP (ESP8266): https://github.com/me-no-dev/ESPAsyncTCP
AsyncTCP (ESP32): https://github.com/me-no-dev/AsyncTCP
With Espressif Systems version 1.0.6 Installed.
If we try 2.0.0 or 2.0.1 or any other version we still get errors.
Also I am getting this error:
Could not find boards.txt in E:\WORKING\arduino-nightly\hardware\espressif\esp32. Is it pre-1.5?
WARNING: Error loading hardware folder E:\WORKING\arduino-nightly\hardware\espressif
No valid hardware definitions found in folder espressif.
Can you please tell me how to fix it ?
Thanks
I think it’s telling you that you are linking to the wrong “WiFi” library. If you look at your error messages at the end of the link it shows “src/arduino/wifi.hpp” on every error and I think that is the generic 8 bit arduino WiFi library because when I compile the link for WiFi is this
“\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi”
If we add to the that the system complains it can’t find the “boards.txt” then I’d say you have not installed the ESP32 library correctly.
These guys have a tutorial on the correct method here https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
Good luck!
mac
Has anyone implemented the “sendSingle (destId, msg)” function? My nodes are spread too far to contact the central node, so I wanted nearby nodes to forward the messages to & from the central node.
I can’t seem to find any example code that I could use.
Thanks for any assistance,
Joel
Because you’ve structured your message with “destId” then you’d be able to test the inbound message in the “receivedCallback” with something like
if(destId != nodeID){
sendSingle (destId, msg);
}else{
//Message is for this nodeID so process it
}
If you want a true mesh you have fallback options as well like this
NODE_1
__________|__________
| |
NODE_2 NODE_3
|____________________|
|
NODE_4
In the example layout the code will be written that if NODE_4 is sending to NODE_1 and NODE_2 is unreachable or there is no “received message” within a timeout period then NODE_1 will try and send the message via NODE_3 and visa-versa.
Hope this theory helps
Cheers
Hi Sara, thank you for this lecture. But I just want to ask. What if I want to send or receive from the specific nodes only. For example:
Node 1 will only send and receive to Node 2
Node 2 will only send and receive to Node 1 and 3
Node 3 will only send and receive to Node 2, and 4
How can I be able to achieve this?
Hello, would it be possible to use the MESH network of the ESP to repeat the WiFi… and at the same time that it would work as a locator to know from which node the client has connected?
Hi all!
Can you help me?
I tryed painlessmesh last year and everything worked.
This is the error on the serial monitor now:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
setLogLevel: ERROR | STARTUP |
STARTUP: init(): 0
STARTUP: AP tcp server established on port 5555
Any updates on this matter? I am having the same issue. Changing the setting of DIO/QIO nor increase the length of MESH_PREFIX and MESH_PASSWORD didn’t fix the issue.
Serial terminal messages:
setLogLevel: ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE |
GENERAL: encodeNodeId():
GENERAL: tcpServerInit():
GENERAL: onNewConnection():
GENERAL: onChangedConnections():
GENERAL: onNodeTimeAdjusted():
CONNECTION: stationScan(): Mesh_username12345678
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
CONNECTION: eventScanDoneHandler: ARDUINO_EVENT_WIFI_SCAN_DONE
CONNECTION: scanComplete(): Scan finished
CONNECTION: scanComplete():– > Cleared old APs.
CONNECTION: scanComplete(): num = 1
CONNECTION: Found 0 nodes
CONNECTION: connectToAP(): No unknown nodes found scan rate set to normal
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
CONNECTION: stationScan(): Mesh_username12345678
CONNECTION: eventScanDoneHandler: ARDUINO_EVENT_WIFI_SCAN_DONE
CONNECTION: scanComplete(): Scan finished
CONNECTION: scanComplete():– > Cleared old APs.
CONNECTION: scanComplete(): num = 1
CONNECTION: Found 0 nodes
CONNECTION: connectToAP(): No unknown nodes found scan rate set to normal
COMMUNICATION: sendBroadcast(): msg=This is a testing message from Node [1] 365025357
Hi . I want to thank you for all the great tutorials , this has been about the best place for a novice to start out . Your examples and explanations are the best . Awhile ago I downloaded several of your downloadable books to support your cause and to help me with my hobby. In the past I have worked with mostly Arduino Uno boards but I really like the 2 core and 10X speed of ESP32 boards . I created a 3 ESP32Wroom and Freenove ESP32-Wrover-Dev bds. I had to change the code to use DHT11 for one of the nodes because thats what I had at the time . I was actually impressed with myself that I was able to rem out the BMP280 and add the DHT11 code instead and it worked. The one problem I am having or maybe its just my misunderstanding . When I get all 3 up and running each serial monitor only displays 2 nodes ? 1 & 2 , 2 & 3 , and 1 & 3 . Any suggestions ? Right now I am just learning all I can about ESP32 because I want to build it into robot cars that communicate with each other to send info. before I used Bluetooth to send motor codes . It would be nice if Wifi could transmit locations to each robot car and move accordingly.
Anyway thanks for all your great work .
Greg
Hi.
If I understood your question correctly, that’s the normal behavior.
If you have three nodes, each node will only print the messages received by the other two nodes.
Regards
Sara
Hi , Thanks Sara ,
Yes now I see. I set up four nodes and received data from the other 3 nodes .
Do you any tutorials on using the second Core of the ESP32 to process data ?
And can the WIFI be used to pinpoint its location ?
Thanks for all the wonderful information .
Hi.
We only have this tutorial about dual core and its based on the example provided by the arduino core: https://randomnerdtutorials.com/esp32-dual-core-arduino-ide/
Regards,
Sara
Thanks Sara , that was exactly what i was looking for . I built the 2 leds blinking from separate cores and I worked as expected . I can use one core for gathering sensor data and the other core to process the data . Great . I just purchased Learn ESP32 with Arduino Ver 2 . Its nice to have the downloaded PDF on my PC . I look forward to building 2 ESP32 omni wheel robot cars with alot of sensors and to be able for them to share data . With just using arduino boards I ran into alot of issues with IR sensors not processing fast enough because it had complete the whole code loop . With 2 processors and multitasking hopefully things will process fast enough to try to make swarm robots. Thanks for all the great work and examples.
GregE
I am doing project using Mesh and Wifi at same time. when a node receive msg from other nodes, it will post to server, database over wifi. I tried add “post to database over wifi” function in ReceiveCallback. But error http response code -1.
Can you help me?
Hi, is every code almost same for all nodes?
Hello.
I just started with this and It runs great. I’ve communicate two DHT11 on my ESP32 end device boards to a single coordinator using the ESP MESH code example in this page. My problem is that I want to make a MQTT bridge, so I could pass my info from those end devices to a single mqtt server. I’ve tried the MQTT bridge example (flashing it just in my coordinator ESP32 device), changing the MESH and STATION’s values to mines, the MQTT broker IP Address and this (mqttClient.connect(“painlessMeshClient”,”mqtt”,”password”). I can connect the End devices to the mesh network and my coordinator is detecting them but I cannot connect to a my mosquitto server. Could you give me an advice?
Thank you so much. Regards.
Hi.
Did you take a look at our guide on how to setup the Mosquitto broker?
https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/
Regards,
Sara
Hello.
Yes, I already had my MQTT server ready and tested without Mesh. My problem is that when I try to connect It to my ESP32 when It is my mesh’s coordinator, It doesn’t connect to the MQTT server or internet either
Hi.
Maybe it’s best to post an issue on the library Github page.
I haven’t experimented with MESH and MQTT simultaneously yet.
Regards,
Sara
Okay, I’ll do it. Thanks!
hello.
I want to send data from the system connected by mesh to the web server through wifi.
I combined the web server and mesh tutorial to make the mesh address and ssid the same, but it doesn’t work well.
Could you tell me how to send data to the web server through wifi in the system connected by mesh?
Thank you.
when should we use esp-meah?
when should we use esp-now?
Hello Sara,
I successfully setup a mesh bridge with webserver which displays the data from all the nodes on a website. Is it possible to connect a single node (not the root) outside the range of the internet router to the internet f(NTP server etc.) via the root bridge node?
Hello,
Is it possible for you to share the code of mesh with webserver ?
Thank you
Aashutosh
Hello,
Is it possible for you to leave a content or posting your working code?
Currently stuck on this topic and try to find a solution, thanks you so much
Thank you
Jason
Use your bridge connection to push the current NTP “EPOCH” (now()) to the MESH then you can just run <TimeLib.h> on all the nodes and set every node to NTP time.
In my case my bridge is UART serial from a Blynk node to the MESH root. I have a destination variable that tells the nodes the message contains an epoch update and it’s as simple as doing “setTime(epoch); and you’re done!
Cheers
mac
Can you share the code somehow? I am also trying to work on that but with not much effect whatsoever.
Hello Sara,
does it possible to use ESP32 MESH as separate Task in freeRTOS?
Thank you.
Thank you for a great tutorial.
I have a setup with multiple groups of microcontrollers sending sensor measurements via cables to be processed by corresponding multiple single board computers (like rpi or odroid). I’m considering switching to painlessmesh – the question I have is ability to have multiple root nodes to split the mesh into multiple submeshes. The comment in the code tells it’s something to be avoided. The number of sensors is in hundreds with measurements taken 10 times per second. This is likely to be crucial to make the mesh scalable and avoid bottlenecks. The other aspect is the ability to instruct node to switch to another submesh. This is desirable due to the fact that there are groups of sensors that have to be processed on a single board computer together.
Hello,
Is it possible to use ESP32 Lora board such as ones shown in
https://makeradvisor.com/tools/ttgo-lora32-sx1276-esp32-oled/
given that all ESP32 based baords come equipped with a BLE module?
{correction} with a WPA module
Hi.
Yes.
You should be able to use any ESP32 board model with this example.
Regards,
Sara
Is there any example used in the ESP8266 board model?
Hi.
These examples are compatible with ESP32 and ESP8266 boards.
Regards,
Sara
Hi Sara,
Thanks for your tutorial.
Can I combine this example to “ESP32 Web Server”?
So far, I could not make them coworking.
Hi.
I’m not sure. I haven’t tried it yet.
Check the library page. They provide several examples and one of them includes a web server: https://gitlab.com/painlessMesh/painlessMesh/-/tree/develop/examples
Regards,
Sara
Hello!
Any idea how to modify the code to add web-server functionality which would allow to display the data collected from all nodes?
PainlessMesh has a very clear list of “Limitations and caveats” here https://github.com/gmag11/painlessMesh#limitations-and-caveats
In short you can’t run a web-server on the same device as you’d need to use WiFi events which would then break your MESH.
The documentation on how to “Bridge” to another network and use a second device is here https://gitlab.com/painlessMesh/painlessMesh/-/wikis/bridge-between-mesh-and-another-network There are a few options listed. I went with the hardwired UART bridge method. It’s simple and robust and has not given any problems. I’m a fan of helper libraries so I use “SerialTransfer” to manage the UART bridge. You can see my code here https://github.com/macca448/Blynk2MESH/blob/main/current/node1/node1.ino
Cheers
macca
Hi.
Thanks for your detailed response.
It’s very helpful.
Regards,
Sara
You are most welcome Sara.
I got started with all things ESP Arduino using Random Nerd (Extremely Helpful) Tutorials so it’s the least I can do in the spirit of “Open Source”.
Cheers
macca
Thank you 🙂
Hi,
I have been experimenting with ESP-Mesh for the last few weeks using mostly painlessMesh. I have a network of 7 sensor nodes, 1 display node, and 1 bridge/display node.
The bridge was the biggest challenge. I use
mesh.stationManual(WiFiSSID, WiFiPass);
There can only be 1 bridge and both WiFi and Mesh must be on the same channel. In my initial test it took anywhere from 3 min to several hours for the 2 to synchronize. So, I looked into forcing the issue. My current bridge does the following upon bootup:
1) connect to WiFi
2) get channel using:
esp_wifi_set_promiscuous(true);
esp_wifi_get_channel(chan1p, chan2p);
3) disconnect from WiFi
4) connect to Mesh
5) as root node, issue a switch channel request:
esp_mesh_get_router_bssid(router_bssidP);
esp_mesh_switch_channel(router_bssidP,chan1,50);
In a minute or two it will be connected to both networks. It then listens to all sensors, repeats their data to MQTT, and every 15 minutes the most recent data is written to an MSSQL database.
There is one catch. Sometimes not all the nodes change the channel and are “lost.” I have not yet figured out how to address this other than by rebooting those nodes. Of course, if the bridge is always the first device to boot, there is no problem.
This did not work out as well as it seemed at first. The response to the change channel request seems to be almost arbitrary. If some change and some do not you end up with two mesh networks on different channels which do not communicate with each other.
I experimented with PainlessMesh and decided that using a Wireless bridge was tempting fate so I did a UART bridge on the root node and the other device is the cloud (Blynk) node.
I also do a push back to the MESH from the cloud node an NTP “epoch” stamp so all MESH nodes can run “Time and Date (Seasonal)” driven tasks.
The one gotcha is Blynk won’t push data to the cloud while watching the inbound serial. That took a bit to figure that out. Simple fix is to use a bool to block the inbound serial while you do the Blynk update push.
It all works seamlessly and doesn’t miss a beat!
Thanks. I was thinking about trying a serial connection. At the moment, I am only going one way but I use my own servers so hopefully that shouldn’t be a problem if I decide to expand the system. Thanks again and thanks to Sara and everyone else who keep this forum going.
I went to a serial connection between two ESP32 devices. With one radio for the Mesh and another for the WiFi everything connects up instantly and everything works smoothly. It has only been up for a day and a half but I don’t see any glitches. I use the serial port for debugging so I used SoftSerial on two unused pins for the bridge and it seems to work smoothly. Thanks again.
Hi Sara,
Thanks for the Tutorial, i’m on the way digging up this kind of IoT for about 3 days, i found this Material related to my need, one thing i didn’t get from here is : How do the connecting each node? is the individual node have their own “router” to connect to ? in the same time they need to make a connection to each other.
i plan to make a lot of street lamp, and i want to make sure they can connect each other to share and publish the status, also each node can get subscribed data via MQTT
Please explain
Thanks in advance
I have a question regarding WiFi channels.
My WiFi router (access point) can pick from a number of WiFi channels from 1 to 11.
Can I force my mesh network to use a channel NOT in use by the AP?
Also, is there a way I can have one node (maybe 2) that can connect to more then one channel?
For example, say my AP is using channel 1. I’d like the mesh network to use channel 6 (for example) and have a node or two switch back and forth between the mesh network on ch6 and the AP on ch1.
Maybe, in this way, I can have more then one mesh network for security or performance reasons.
Honestly, I can’t think of a reason to do this, just thinking outside the box.
Mark.
you cannot use a different router channel for painless mesh to the channel used by your router. For example if your router uses channel one the PLM will use channel 1 too. I believe that is stated in the documentation.
in the section Exchange Sensor Readings using ESP-MESH you seem to use the libraries bblanchon/ArduinoJson and arduino-libraries/Arduino_JSON almost interchangeably. However they have quite different functionality. Is there a guide or suggestion hoe to migrate the sketches using Arduino_JSON to the ArduinoJson library.
In particular:
String getReadings () {
JSONVar jsonReadings;
jsonReadings[“node”] = nodeNumber;
jsonReadings[“temp”] = bmp.readTemperature();
// jsonReadings[“hum”] = bmp.readHumidity();
jsonReadings[“pres”] = bmp.readPressure()/100.0F;
readings = JSON.stringify(jsonReadings);
return readings;
}
Thanks for your assistance.
Hi.
We don’t have any guide.
But, the ArduinoJson library by bblanchon have real good documentation. Check it out here: https://arduinojson.org/
Regards,
Sara
Hi Rui/Sara,
I am new to ESP32 and I haven’t worked much with wifi or mesh networks. I have a total of 4 ESP32 boards that are in a mesh connection, I want 1 of the ESP32 to communicate with my wifi router so that it can access the internet and web server to monitor sensor data. I don’t understand how to do that. Can you help?
The library’s dependency processing has a bug: when a dependency already exists, and the dependency has the right version, the installer should just silently skip it, and move on to the next dependency. Error msg:
Failed to install library: ‘Painless Mesh:1.5.0’.
Error: 2 UNKNOWN: destination dir c:[HIDDEN]\Documents\Arduino\libraries\ArduinoJson already exists, cannot install
A workaround is for users to install the dependecies individually, but it’s better to just fix your bug, eh?
Hello.
I would like to ask for advice.
I have a Shelly 3EM (inside is ESP32) in the house switchboard , and it can not “communicate” (WiFi) with the router, which is located behind two concrete walls and a metal wall of the switchboard. I want to create ESP-MESH with ESP32 behind the first wall and insert a script with painlessMesh library into Shelly so that they communicate with each other (send consumption data and possibly a shutdown command). It’s a good idea, or take a different path. Thank you for your time devoted to my problem and I wish you much success.
I don’t expect it will be easy to run any custom software like ESP-Mesh alongside the Shelly firmware. You would waste less effort by moving the 3EM closer to the appliance(s) to be measured, outside the faraday cage of the switchboard/
Greetings and thank you. The advice of experts is always appreciated. Good luck at work.
Hi Rui/Sara,
I am new to ESP32 and I haven’t worked much with wifi or wifi mesh. I have total 4 ESP32 boards which are in a mesh connection, I want 1 of the ESP32 to communicate with my wifi router so that it can access the internet and a webserver. I couldn’t understand how to do it. Can you help out?
hi, I’m also experiencing the exact same thing, have you solved the problem?
Greetings.
In VS with PlatformIO and four ESP32s, I commented on the “arduinoUnity” library in “platformio.ini”, otherwise it gave an error.
Hello
In this example, I used the esp8266-01 module and the connection was fine. However, I don’t know if I can extend the connection time interval by, for example, 1 minute. How should I modify the program to reduce power consumption and heat generation? quantity. thank you
Hello yroj,
Check “Create tasks” section of tutorial, change YOUR_TIME_IN_SECONDS for your value there
Task taskSendMessage(TASK_SECOND * YOUR_TIME_IN_SECONDS , TASK_FOREVER, &sendMessage);
Regards, Alex