#include "painlessMesh.h"
#define MESH_PREFIX "mesh123"
#define MESH_PASSWORD "pass123"
#define MESH_PORT 5555
Scheduler userScheduler;
painlessMesh mesh;
uint32_t ID;
hw_timer_t * timer = NULL;
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("Received from %u msg= %X %s\n", from, from - 1, msg.c_str());
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("New Connection, nodeId = %u\n", nodeId);
mesh.sendBroadcast("root");
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
}
void IRAM_ATTR Timer0_ISR(void) {
mesh.sendBroadcast("sending");
}
void setup() {
Serial.begin(115200);
mesh.setDebugMsgTypes( ERROR | STARTUP );
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.setRoot();
mesh.setContainsRoot();
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &Timer0_ISR, true);
timerAlarmWrite(timer, 500000, true);
timerAlarmEnable(timer);
}
void loop() {
mesh.update();
}