Tutorial del Internet de las Cosas y Bluetooth con el ESP32
Juan Antonio Villalpando
Volver al índice del tutorial
____________________________
229_2.- Wemos D1 R32 ESP32. Mesh red de Nodos. (II)
- Vamos a seguir los tutoriales de:
https://randomnerdtutorials.com/esp-mesh-esp32-esp8266-painlessmesh
- Utilizaremos la librería:
painlessmesh
- Al instalarlo nos pide que instalemos otras librerías.

_______________________________________________
- Código.
|
/*
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 "hola" // Nombre de red que quieres crear.
#define MESH_PASSWORD "1234" // Contraseña común para todos.
#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();
}
|

- PainlessMesh:
https://gitlab.com/painlessMesh/painlessMesh/tree/master/examples
- Este archivo contiene tres librerías, cópialos en la carpeta libraries de Arduino.
painlessMeth_varios.zip
https://www.youtube.com/watch?v=jOmHlHHpK2k
_______________________________
- Documentación de ESP32 sobre Mesh.
https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/mesh.html
https://github.com/espressif/esp-mdf
https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_mesh.html
_______________________________
|