#include<stdio.h>
#include<stdlib.h>
#include "painlessMesh.h"
#include <WiFiManager.h> // https://g...content-available-to-author-only...b.com/tzapu/WiFiManager
#define serial serial = ()
void setup()
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it.
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
// reset settings - wipe stored credentials for testing
// these are stored by the esp library
wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
#define MESH_PREFIX "AutoConnectAP" // Troque para o nome da sua rede
#define MESH_PASSWORD "password" // coloque a senha da sua rede
#define MESH_PORT 5555
Scheduler userScheduler;
painlessMesh mesh;
void sendMessage(); /
Task taskSendMessage(TASK_SECOND * 1, TASK_FOREVER, &sendMessage);
void sendMessage() {
String msg = "Hello from node ";
msg += mesh.getNodeId();
mesh.sendBroadcast(msg);
taskSendMessage.setInterval(random(TASK_SECOND * 1, TASK_SECOND * 5));
}
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);
// COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes(
ERROR | STARTUP |
DEBUG); // 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);W
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCall);
mesh.initOTAReceive("otareceiver");
userScheduler.addTask(taskSendMessage);
taskSendMessage.enable();
void loop()
mesh.update();