Files
arduino-libs/arduino-cli/libraries/painlessMesh-master/examples/echoNode/echoNode.ino
2024-07-20 22:09:06 +08:00

34 lines
916 B
C++

//************************************************************
// this is a simple example that uses the painlessMesh library and echos any
// messages it receives
//
//************************************************************
#include "painlessMesh.h"
#define MESH_PREFIX "whateverYouLike"
#define MESH_PASSWORD "somethingSneaky"
#define MESH_PORT 5555
// Prototypes
void receivedCallback( uint32_t from, String &msg );
painlessMesh mesh;
void setup() {
Serial.begin(115200);
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT );
mesh.onReceive(&receivedCallback);
}
void loop() {
mesh.update();
}
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("echoNode: Received from %u msg=%s\n", from, msg.c_str());
mesh.sendSingle(from, msg);
}