Hi, I am new to PlatformIO i am facing an stack overflow exception(29) error from platformIO when i upload the code( i have copied the painlessmesh example code Starthere).
if same code is uploaded through Arduino IDE It works fine can any one get me the Solution for this.
code:
#include "painlessMesh.h"
#include <ESP8266WiFi.h>
#define MESH_PREFIX "ThisisTechnowspro"
#define MESH_PASSWORD "111222333"
#define MESH_PORT 5555
#define LED 2 // GPIO number of connected LED, ON ESP-12 IS GPIO2
#define BLINK_PERIOD 3000 // milliseconds until cycle repeat
#define BLINK_DURATION 100 // milliseconds LED is on for
// WiFi credentials: should match your access point!
#define STATION_SSID "test1"
#define STATION_PASSWORD "111222333"
#define HOSTNAME "MJ_Host"
// Prototypes
void sendMessage();
void receivedCallback(uint32_t from, String & msg);
void newConnectionCallback(uint32_t nodeId);
void changedConnectionCallback();
void nodeTimeAdjustedCallback(int32_t offset);
void delayReceivedCallback(uint32_t from, int32_t delay);
Scheduler userScheduler; // to control your personal task
painlessMesh mesh;
bool calc_delay = false;
SimpleList<uint32_t> nodes;
void sendMessage() ; // Prototype
Task taskSendMessage( TASK_SECOND * 1, TASK_FOREVER, &sendMessage ); // start with a one second interval
// Task to blink the number of nodes
Task blinkNoNodes;
bool onFlag = false;
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
mesh.setDebugMsgTypes(ERROR | DEBUG); // set before init() so that you can see error messages
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
mesh.onNodeDelayReceived(&delayReceivedCallback);
// mesh.stationManual(STATION_SSID, STATION_PASSWORD);
mesh.setHostname(HOSTNAME);
//mesh.setRoot(true);
mesh.setContainsRoot(true);
userScheduler.addTask( taskSendMessage );
taskSendMessage.enable();
blinkNoNodes.set(BLINK_PERIOD, (mesh.getNodeList().size() + 1) * 2, []() {
// If on, switch off, else switch on
if (onFlag)
onFlag = false;
else
onFlag = true;
blinkNoNodes.delay(BLINK_DURATION);
if (blinkNoNodes.isLastIteration()) {
// Finished blinking. Reset task for next run
// blink number of nodes (including this node) times
blinkNoNodes.setIterations((mesh.getNodeList().size() + 1) * 2);
// Calculate delay based on current mesh time and BLINK_PERIOD
// This results in blinks between nodes being synced
blinkNoNodes.enableDelayed(BLINK_PERIOD -
(mesh.getNodeTime() % (BLINK_PERIOD*1000))/1000);
}
});
userScheduler.addTask(blinkNoNodes);
blinkNoNodes.enable();
randomSeed(analogRead(A0));
}
void loop() {
mesh.update();
digitalWrite(LED, !onFlag);
}
void sendMessage() {
String msg = "Hl fr " + String(mesh.getNodeId());
msg += " rt " + String(mesh.isRoot());
msg += " MAC " + String(WiFi.macAddress());
msg += " cp id: " + String(ESP.getChipId());
msg += " myFreeMemory: " + String(ESP.getFreeHeap());
mesh.sendBroadcast(msg);
if (calc_delay) {
SimpleList<uint32_t>::iterator node = nodes.begin();
while (node != nodes.end()) {
mesh.startDelayMeas(*node);
node++;
}
calc_delay = false;
}
Serial.printf("Sending message: %s\n", msg.c_str());
taskSendMessage.setInterval( random(TASK_SECOND * 1, TASK_SECOND * 5)); // between 1 and 5 seconds
// serilize json data.
/*DynamicJsonDocument doc(1024);
float h = dht.readHumidity();
float t = dht.readTemperature();
doc["TEMP"] = t;
doc["HUM"] = h;
String msg ;
serializeJson(doc, msg);
mesh.sendBroadcast( msg );
Serial.println(msg);
taskSendMessage.setInterval((TASK_SECOND * 10));*/
}
void receivedCallback(uint32_t from, String & msg) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
// below code for deserilize json doc
String json;
DynamicJsonDocument doc(1024);
json = msg.c_str();
/* DeserializationError error = deserializeJson(doc, json);
if (error)
{
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
} */
//relay1_status = doc["Relay1"];
// digitalWrite(Relay1, relay1_status);
}
void newConnectionCallback(uint32_t nodeId) {
// Reset blink task
onFlag = false;
blinkNoNodes.setIterations((mesh.getNodeList().size() + 1) * 2);
blinkNoNodes.enableDelayed(BLINK_PERIOD - (mesh.getNodeTime() % (BLINK_PERIOD*1000))/1000);
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
Serial.printf("--> startHere: New Connection, %s\n", mesh.subConnectionJson(true).c_str());
}
void changedConnectionCallback() {
Serial.printf("Changed connections\n");
// Reset blink task
onFlag = false;
blinkNoNodes.setIterations((mesh.getNodeList().size() + 1) * 2);
blinkNoNodes.enableDelayed(BLINK_PERIOD - (mesh.getNodeTime() % (BLINK_PERIOD*1000))/1000);
nodes = mesh.getNodeList();
Serial.printf("Num nodes: %d\n", nodes.size());
Serial.printf("Json Connection, %s\n", mesh.subConnectionJson(true).c_str());
Serial.printf("Connection list:");
SimpleList<uint32_t>::iterator node = nodes.begin();
while (node != nodes.end()) {
Serial.printf(" %u", *node);
node++;
}
Serial.println();
calc_delay = true;
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(), offset);
}
void delayReceivedCallback(uint32_t from, int32_t delay) {
Serial.printf("Delay to node %u is %d us\n", from, delay);
}