fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include "painlessMesh.h"
  4. #include <WiFiManager.h> // https://g...content-available-to-author-only...b.com/tzapu/WiFiManager
  5. #define serial serial = ()
  6.  
  7. void setup()
  8. // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  9. // it is a good practice to make sure your code sets wifi mode how you want it.
  10.  
  11. // put your setup code here, to run once:
  12. Serial.begin(115200);
  13.  
  14. //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
  15. WiFiManager wm;
  16.  
  17. // reset settings - wipe stored credentials for testing
  18. // these are stored by the esp library
  19. wm.resetSettings();
  20.  
  21. // Automatically connect using saved credentials,
  22. // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
  23. // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
  24. // then goes into a blocking loop awaiting configuration and will return success result
  25.  
  26. bool res;
  27. // res = wm.autoConnect(); // auto generated AP name from chipid
  28. // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
  29. res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
  30.  
  31. if(!res) {
  32. Serial.println("Failed to connect");
  33. // ESP.restart();
  34. }
  35. else {
  36. //if you get here you have connected to the WiFi
  37. Serial.println("connected...yeey :)");
  38. }
  39.  
  40. }
  41.  
  42. void loop() {
  43. // put your main code here, to run repeatedly:
  44. }
  45.  
  46. #define MESH_PREFIX "AutoConnectAP" // Troque para o nome da sua rede
  47. #define MESH_PASSWORD "password" // coloque a senha da sua rede
  48. #define MESH_PORT 5555
  49.  
  50. Scheduler userScheduler;
  51.  
  52. painlessMesh mesh;
  53.  
  54. void sendMessage(); /
  55. Task taskSendMessage(TASK_SECOND * 1, TASK_FOREVER, &sendMessage);
  56.  
  57. void sendMessage() {
  58. String msg = "Hello from node ";
  59. msg += mesh.getNodeId();
  60. mesh.sendBroadcast(msg);
  61. taskSendMessage.setInterval(random(TASK_SECOND * 1, TASK_SECOND * 5));
  62. }
  63.  
  64. void receivedCallback(uint32_t from, String &msg) {
  65. Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
  66. }
  67. void newConnectionCallback(uint32_t nodeId) {
  68. Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
  69. }
  70. void changedConnectionCallback() { Serial.printf("Changed connections\n"); }
  71. void nodeTimeAdjustedCallback(int32_t offset) {
  72. Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(), offset);
  73. }
  74. void setup() {
  75. Serial.begin(115200);
  76. // COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
  77. mesh.setDebugMsgTypes(
  78. ERROR | STARTUP |
  79. DEBUG); // set before init() so that you can see startup messages
  80. mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
  81. mesh.onReceive(&receivedCallback);
  82. mesh.onNewConnection(&newConnectionCallback);W
  83. mesh.onChangedConnections(&changedConnectionCallback);
  84. mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCall);
  85. mesh.initOTAReceive("otareceiver");
  86. userScheduler.addTask(taskSendMessage);
  87. taskSendMessage.enable();
  88.  
  89. void loop()
  90. mesh.update();
  91.  
Success #stdin #stdout 0.02s 25948KB
stdin
Standard input is empty
stdout
#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();