ESP32 Crashing with too much IFs or Serial.print?

Hi all,

Need some help with my code, I am stuck as to why having too much ifs or Serial.prints causing my esp32 to crash. I'm doing a datalogging receiver from multiple ESP32s and when I code it like this it crashes.

Full code below:

#include <esp_now.h>
#include <WiFi.h>
#include <Wire.h>
TaskHandle_t Task_loop1;

unsigned int currentMillis = 0;
unsigned int previousMillis3 = 0;
unsigned int currentMillis4 = 0;
unsigned int previousMillis4 = 0;

#define interval3 1000
#define interval4 1000

unsigned int M54 = 0;
unsigned int M54PART = 0;
unsigned int M54GOOD = 0;
float M54LGTH = 0;

unsigned int M69 = 0;
unsigned int M69PART = 0;
unsigned int M69GOOD = 0;
float M69LGTH = 0;

unsigned int M67 = 0;
unsigned int M67PART = 0;
unsigned int M67GOOD = 0;
float M67LGTH = 0;
unsigned int M67RUN = 0;
unsigned int M67S0 = 0;
unsigned int M67S1 = 0;
unsigned int M67S2 = 0;
unsigned int M67S3 = 0;
unsigned int M67S4 = 0;
unsigned int M67S5 = 0;
unsigned int M67S6 = 0;
unsigned int M67S7 = 0;
unsigned int M67S8 = 0;
unsigned int M67S9 = 0;
unsigned int M67S10 = 0;


unsigned int M61 = 0;
unsigned int M61PART = 0;
unsigned int M61GOOD = 0;
float M61LGTH = 0;

unsigned int M64 = 0;
unsigned int M64PART = 0;
unsigned int M64GOOD = 0;
float M64LGTH = 0;

unsigned int M60 = 0;
unsigned int M60PART = 0;
unsigned int M60GOOD = 0;
float M60LGTH = 0;
unsigned int M60RUN = 0;
unsigned int M60S0 = 0;
unsigned int M60S1 = 0;
unsigned int M60S2 = 0;
unsigned int M60S3 = 0;
unsigned int M60S4 = 0;
unsigned int M60S5 = 0;
unsigned int M60S6 = 0;
unsigned int M60S7 = 0;
unsigned int M60S8 = 0;
unsigned int M60S9 = 0;
unsigned int M60S10 = 0;

unsigned int M76 = 0;
unsigned int M76PART = 0;
unsigned int M76GOOD = 0;
float M76LGTH = 0;

unsigned int M17 = 0;
unsigned int M17PART = 0;
unsigned int M17GOOD = 0;
float M17LGTH = 0;

unsigned int M53 = 0;
unsigned int M53PART = 0;
unsigned int M53GOOD = 0;
float M53LGTH = 0;

unsigned int M32 = 0;
unsigned int M32PART = 0;
unsigned int M32GOOD = 0;
float M32LGTH = 0;

unsigned int M54M = 0;
unsigned int M69M = 0;
unsigned int M67M = 0;
unsigned int M61M = 0;
unsigned int M64M = 0;
unsigned int M60M = 0;
unsigned int M76M = 0;
unsigned int M17M = 0;
unsigned int M53M = 0;
unsigned int M32M = 0;

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
  byte id;
  byte integer;
  unsigned int lgth;
  unsigned int v;
  byte w;
  byte x;
  unsigned int y;
} struct_message;


struct_message myData;

struct_message board1;
struct_message board2;
struct_message board3;
struct_message board4;
struct_message board5;
struct_message board6;
struct_message board7;
struct_message board8;
struct_message board9;
struct_message board10;

struct_message boardsStruct[10] = {board1, board2, board3, board4, board5, board6, board7, board8, board9, board10};

// Create a struct_message called myData

void data_receive(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  char macStr[18];
  //Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  //Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  //Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id - 1].integer = myData.integer;
  boardsStruct[myData.id - 1].lgth = myData.lgth;
  boardsStruct[myData.id - 1].v = myData.v;
  boardsStruct[myData.id - 1].y = myData.y;
}


void esploop1(void* pvParameters) {
  //  Serial.print("WIFI running on core ");
  //  Serial.println(xPortGetCoreID());
  //setup1();
  //for (int i = 0; i <= 1; i++) {

  //for (;;) {
  for (;;) {
    if (currentMillis4 - previousMillis4 >= interval4) {
      previousMillis4 = currentMillis4;





    }
  }
}
/*Serial.println((String)"SAVEWORKBOOKAS,J2_" + (now.year()) + "-" + (now.month()) + "-" + (now.day()));
  Serial.println("CLEARDATA");*/



void setup() {
  // Initialize Serial Monitor
  xTaskCreatePinnedToCore(esploop1, "loop1", 10000, NULL, 1, NULL, 0);
  Serial.begin(112500);

  //Serial.println(F("CLEARDATA"));
  //Serial.println(F("CLEARSHEET"));
  //Serial.println(F("LABEL, Time, M61, M61P, M61L, M61G, M54, M54P, M54L, M54G, M17, M17P, M17L, M17G, M67, M67P, M67L, M67G, M76, M76P, M76L, M76G, M60, M60P, M60L, M60G, M53, M53P, M53L, M53G, M64, M64P, M64L, M64G, M69, M69P, M69L, M69G, M32, M32P, M32L, M32G"));




  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);


  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    //Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(data_receive);

  //lcd3.setCursor (0, 2);
  //lcd3.print(F("--------------------"));

  disableCore0WDT();
}

void loop() {

  currentMillis = millis();



  M54 = boardsStruct[54 - 1].integer;
  M54LGTH =  boardsStruct[54 - 1].lgth;
  M54PART =  boardsStruct[54 - 1].v;
  M54GOOD =  boardsStruct[54 - 1].y;

  M69 = boardsStruct[69 - 1].integer;
  M69LGTH =  boardsStruct[69 - 1].lgth;
  M69PART =  boardsStruct[69 - 1].v;
  M69GOOD =  boardsStruct[69 - 1].y;

  M67 = boardsStruct[67 - 1].integer;
  M67LGTH =  boardsStruct[67 - 1].lgth;
  M67PART =  boardsStruct[67 - 1].v;
  M67GOOD =  boardsStruct[67 - 1].y;

  M61 = boardsStruct[61 - 1].integer;
  M61LGTH =  boardsStruct[61 - 1].lgth;
  M61PART =  boardsStruct[61 - 1].v;
  M61GOOD =  boardsStruct[61 - 1].y;

  M64 = boardsStruct[64 - 1].integer;
  M64LGTH =  boardsStruct[64 - 1].lgth;
  M64PART =  boardsStruct[64 - 1].v;
  M64GOOD =  boardsStruct[64 - 1].y;

  M60 = boardsStruct[60 - 1].integer;
  M60LGTH =  boardsStruct[60 - 1].lgth;
  M60PART =  boardsStruct[60 - 1].v;
  M60GOOD =  boardsStruct[60 - 1].y;

  M76 = boardsStruct[76 - 1].integer;
  M76LGTH =  boardsStruct[76 - 1].lgth;
  M76PART =  boardsStruct[76 - 1].v;
  M76GOOD =  boardsStruct[76 - 1].y;

  M17 = boardsStruct[17 - 1].integer;
  M17LGTH =  boardsStruct[17 - 1].lgth;
  M17PART =  boardsStruct[17 - 1].v;
  M17GOOD =  boardsStruct[17 - 1].y;

  M53 = boardsStruct[53 - 1].integer;
  M53LGTH =  boardsStruct[53 - 1].lgth;
  M53PART =  boardsStruct[53 - 1].v;
  M53GOOD =  boardsStruct[53 - 1].y;

  M32 = boardsStruct[32 - 1].integer;
  M32LGTH =  boardsStruct[32 - 1].lgth;
  M32PART =  boardsStruct[32 - 1].v;
  M32GOOD =  boardsStruct[54 - 1].y;

  if (M54 == 16) {
    M54M = 16;
  }

  if (M54 != 16) {
    M54M = M54;
  }

  ///////

  if (M69 == 16) {
    M69M = 16;
  }

  if (M69 != 16) {
    M69M = M69;
  }

  ///////

  if (M67 == 16) {
    M67M = 16;
  }

  if (M67 == 16) {
    M67M = 16;
  }

  else if (M67 != 16) {
    M67M = M67;
    if (M67M == 0) {
      M67S0++;
    }
    else if (M67M == 1) {
      M67S1++;
    }
    else if (M67M == 2) {
      M67S2++;
    }
    else if (M67M == 3) {
      M67S3++;
    }
    else if (M67M == 4) {
      M67S4++;
    }
    else if (M67M == 5) {
      M67S5++;
    }
    else if (M67M == 6) {
      M67S6++;
    }
    else if (M67M == 7) {
      M67S7++;
    }
    else if (M67M == 8) {
      M67S8++;
    }
    else if (M67M == 9) {
      M67S9++;
    }
    else if (M67M == 10) {
      M67S10++;
    }
  }


  ///////

  if (M61 == 16) {
    M61M = 16;
  }

  if (M61 != 16) {
    M61M = M61;
  }

  ///////

  if (M64 == 16) {
    M64M = 16;
  }

  if (M64 != 16) {
    M64M = M64;
  }

  ///////

  if (M60 == 16) {
    M60M = 16;
  }

  if (M60 != 16) {
    M60M = M60;
  }

  ///////

  if (M76 == 16) {
    M76M = 16;
  }

  if (M76 != 16) {
    M76M = M76;
  }

  ///////

  if (M17 == 16) {
    M17M = 16;
  }

  if (M17 != 16) {
    M17M = M17;
  }

  ///////

  if (M53 == 16) {
    M53M = 16;
  }

  if (M53 != 16) {
    M53M = M53;
  }

  ///////

  if (M32 == 16) {
    M32M = 16;
  }

  if (M32 != 16) {
    M32M = M32;
  }


  //Serial.print("M60 = ");
  //Serial.println(M60);
  //Serial.print("M54 = ");
  //Serial.println(M54);

  if (currentMillis - previousMillis3 >= interval3) {
    previousMillis3 = currentMillis;
    //Serial.print(F("DATA"));
    //Serial.print(F(","));
    //Serial.print(F("DATE"));   //Date
    //Serial.print(F(","));
    //Serial.print(F("TIME"));   //Time
    //Serial.print(F(","));
    Serial.print(M61M);   //61
    Serial.print(F(","));
    Serial.print(M61PART);  //61PART
    Serial.print(F(","));
    Serial.print(M61LGTH / 100); //61LGTH
    Serial.print(F(","));
    Serial.print(M61GOOD);  //61GOOD
    Serial.print(F(","));
    Serial.print(M54M);   //54
    Serial.print(F(","));
    Serial.print(M54PART);  //54PART

    Serial.print(F(","));
    Serial.print(M54LGTH / 100); //54LGTH
    Serial.print(F(","));
    Serial.print(M54GOOD);  //54GOOD
    Serial.print(F(","));
    Serial.print(M17M); //17
    Serial.print(F(","));
    Serial.print(M17PART);  //17PART
    Serial.print(F(","));
    Serial.print(M17LGTH / 100); //17LGTH
    Serial.print(F(","));
    Serial.print(M17GOOD);  //17GOOD
    Serial.print(F(","));
    Serial.print(M67M); //67
    Serial.print(F(","));
    Serial.print(M67RUN);
    Serial.print(F(","));
    Serial.print(M67S0);
    Serial.print(F(","));
    Serial.print(M67S1);
    Serial.print(F(","));
    Serial.print(M67S2);
    Serial.print(F(","));
    Serial.print(M67S3);
    Serial.print(F(","));
    Serial.print(M67S4);
    Serial.print(F(","));
    Serial.print(M67S5);
    Serial.print(F(","));
    Serial.print(M67S6);
    Serial.print(F(","));
    Serial.print(M67S7);
    Serial.print(F(","));
    Serial.print(M67S8);
    Serial.print(F(","));
    Serial.print(M67S9);
    Serial.print(F(","));
    Serial.print(M67S10);
    Serial.print(F(","));
    Serial.print(M67PART);  //67PART
    Serial.print(F(","));
    Serial.print(M67LGTH / 100); //67LGTH
    Serial.print(F(","));
    Serial.print(M67GOOD);  //67GOOD
    Serial.print(F(","));
    Serial.print(M76M); //76
    Serial.print(F(","));
    Serial.print(M76PART);  //76PART
    Serial.print(F(","));
    Serial.print(M76LGTH / 100); //76LGTH
    Serial.print(F(","));
    Serial.print(M76GOOD);  //76GOOD
    Serial.print(F(","));
    Serial.print(M60M);  //60
    Serial.print(F(","));
    Serial.print(M60PART);  //60PART
    Serial.print(F(","));
    Serial.print(M60LGTH / 100); //60LGTH
    Serial.print(F(","));
    Serial.print(M60GOOD);  //60GOOD
    Serial.print(F(","));
    Serial.print(M53M); //53
    Serial.print(F(","));
    Serial.print(M53PART);  //53PART
    Serial.print(F(","));
    Serial.print(M53LGTH / 100); //53LGTH
    Serial.print(F(","));
    Serial.print(M53GOOD);  //53GOOD
    Serial.print(F(","));
    Serial.print(M64M); //64
    Serial.print(F(","));
    Serial.print(M64PART);  //64PART
    Serial.print(F(","));
    Serial.print(M64LGTH / 100); //64LGTH
    Serial.print(F(","));
    Serial.print(M64GOOD);  //64GOOD
    Serial.print(F(","));
    Serial.print(M69M); //69
    Serial.print(F(","));
    Serial.print(M69PART);  //69PART
    Serial.print(F(","));
    Serial.print(M69LGTH / 100); //69LGTH
    Serial.print(F(","));
    Serial.print(M69GOOD);  //69GOOD
    Serial.print(F(","));
    Serial.print(M32M); //32
    Serial.print(F(","));
    Serial.print(M32PART);  //32PART
    Serial.print(F(","));
    Serial.print(M32LGTH / 100); //32LGTH
    Serial.print(F(","));
    Serial.println(M32GOOD);  //32GOOD
    //Serial.print(F(","));
    //Serial.print(F(",AUTOSCROLL_20"));
    //Serial.print(F(","));
    //Serial.println(F("DONE"));




  }

}

If i run the code like this below, it does not crash.

#include <esp_now.h>
#include <WiFi.h>
#include <Wire.h>
TaskHandle_t Task_loop1;

unsigned int currentMillis = 0;
unsigned int previousMillis3 = 0;
unsigned int currentMillis4 = 0;
unsigned int previousMillis4 = 0;

#define interval3 1000
#define interval4 1000

unsigned int M54 = 0;
unsigned int M54PART = 0;
unsigned int M54GOOD = 0;
float M54LGTH = 0;

unsigned int M69 = 0;
unsigned int M69PART = 0;
unsigned int M69GOOD = 0;
float M69LGTH = 0;

unsigned int M67 = 0;
unsigned int M67PART = 0;
unsigned int M67GOOD = 0;
float M67LGTH = 0;
unsigned int M67RUN = 0;
unsigned int M67S0 = 0;
unsigned int M67S1 = 0;
unsigned int M67S2 = 0;
unsigned int M67S3 = 0;
unsigned int M67S4 = 0;
unsigned int M67S5 = 0;
unsigned int M67S6 = 0;
unsigned int M67S7 = 0;
unsigned int M67S8 = 0;
unsigned int M67S9 = 0;
unsigned int M67S10 = 0;


unsigned int M61 = 0;
unsigned int M61PART = 0;
unsigned int M61GOOD = 0;
float M61LGTH = 0;

unsigned int M64 = 0;
unsigned int M64PART = 0;
unsigned int M64GOOD = 0;
float M64LGTH = 0;

unsigned int M60 = 0;
unsigned int M60PART = 0;
unsigned int M60GOOD = 0;
float M60LGTH = 0;
unsigned int M60RUN = 0;
unsigned int M60S0 = 0;
unsigned int M60S1 = 0;
unsigned int M60S2 = 0;
unsigned int M60S3 = 0;
unsigned int M60S4 = 0;
unsigned int M60S5 = 0;
unsigned int M60S6 = 0;
unsigned int M60S7 = 0;
unsigned int M60S8 = 0;
unsigned int M60S9 = 0;
unsigned int M60S10 = 0;

unsigned int M76 = 0;
unsigned int M76PART = 0;
unsigned int M76GOOD = 0;
float M76LGTH = 0;

unsigned int M17 = 0;
unsigned int M17PART = 0;
unsigned int M17GOOD = 0;
float M17LGTH = 0;

unsigned int M53 = 0;
unsigned int M53PART = 0;
unsigned int M53GOOD = 0;
float M53LGTH = 0;

unsigned int M32 = 0;
unsigned int M32PART = 0;
unsigned int M32GOOD = 0;
float M32LGTH = 0;

unsigned int M54M = 0;
unsigned int M69M = 0;
unsigned int M67M = 0;
unsigned int M61M = 0;
unsigned int M64M = 0;
unsigned int M60M = 0;
unsigned int M76M = 0;
unsigned int M17M = 0;
unsigned int M53M = 0;
unsigned int M32M = 0;

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
  byte id;
  byte integer;
  unsigned int lgth;
  unsigned int v;
  byte w;
  byte x;
  unsigned int y;
} struct_message;


struct_message myData;

struct_message board1;
struct_message board2;
struct_message board3;
struct_message board4;
struct_message board5;
struct_message board6;
struct_message board7;
struct_message board8;
struct_message board9;
struct_message board10;

struct_message boardsStruct[10] = {board1, board2, board3, board4, board5, board6, board7, board8, board9, board10};

// Create a struct_message called myData

void data_receive(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  char macStr[18];
  //Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  //Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  //Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id - 1].integer = myData.integer;
  boardsStruct[myData.id - 1].lgth = myData.lgth;
  boardsStruct[myData.id - 1].v = myData.v;
  boardsStruct[myData.id - 1].y = myData.y;
}


void esploop1(void* pvParameters) {
  //  Serial.print("WIFI running on core ");
  //  Serial.println(xPortGetCoreID());
  //setup1();
  //for (int i = 0; i <= 1; i++) {

  //for (;;) {
  for (;;) {
    if (currentMillis4 - previousMillis4 >= interval4) {
      previousMillis4 = currentMillis4;





    }
  }
}
/*Serial.println((String)"SAVEWORKBOOKAS,J2_" + (now.year()) + "-" + (now.month()) + "-" + (now.day()));
  Serial.println("CLEARDATA");*/



void setup() {
  // Initialize Serial Monitor
  xTaskCreatePinnedToCore(esploop1, "loop1", 10000, NULL, 1, NULL, 0);
  Serial.begin(112500);

  //Serial.println(F("CLEARDATA"));
  //Serial.println(F("CLEARSHEET"));
  //Serial.println(F("LABEL, Time, M61, M61P, M61L, M61G, M54, M54P, M54L, M54G, M17, M17P, M17L, M17G, M67, M67P, M67L, M67G, M76, M76P, M76L, M76G, M60, M60P, M60L, M60G, M53, M53P, M53L, M53G, M64, M64P, M64L, M64G, M69, M69P, M69L, M69G, M32, M32P, M32L, M32G"));




  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);


  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    //Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(data_receive);

  //lcd3.setCursor (0, 2);
  //lcd3.print(F("--------------------"));

  disableCore0WDT();
}

void loop() {

  currentMillis = millis();



  M54 = boardsStruct[54 - 1].integer;
  M54LGTH =  boardsStruct[54 - 1].lgth;
  M54PART =  boardsStruct[54 - 1].v;
  M54GOOD =  boardsStruct[54 - 1].y;

  M69 = boardsStruct[69 - 1].integer;
  M69LGTH =  boardsStruct[69 - 1].lgth;
  M69PART =  boardsStruct[69 - 1].v;
  M69GOOD =  boardsStruct[69 - 1].y;

  M67 = boardsStruct[67 - 1].integer;
  M67LGTH =  boardsStruct[67 - 1].lgth;
  M67PART =  boardsStruct[67 - 1].v;
  M67GOOD =  boardsStruct[67 - 1].y;

  M61 = boardsStruct[61 - 1].integer;
  M61LGTH =  boardsStruct[61 - 1].lgth;
  M61PART =  boardsStruct[61 - 1].v;
  M61GOOD =  boardsStruct[61 - 1].y;

  M64 = boardsStruct[64 - 1].integer;
  M64LGTH =  boardsStruct[64 - 1].lgth;
  M64PART =  boardsStruct[64 - 1].v;
  M64GOOD =  boardsStruct[64 - 1].y;

  M60 = boardsStruct[60 - 1].integer;
  M60LGTH =  boardsStruct[60 - 1].lgth;
  M60PART =  boardsStruct[60 - 1].v;
  M60GOOD =  boardsStruct[60 - 1].y;

  M76 = boardsStruct[76 - 1].integer;
  M76LGTH =  boardsStruct[76 - 1].lgth;
  M76PART =  boardsStruct[76 - 1].v;
  M76GOOD =  boardsStruct[76 - 1].y;

  M17 = boardsStruct[17 - 1].integer;
  M17LGTH =  boardsStruct[17 - 1].lgth;
  M17PART =  boardsStruct[17 - 1].v;
  M17GOOD =  boardsStruct[17 - 1].y;

  M53 = boardsStruct[53 - 1].integer;
  M53LGTH =  boardsStruct[53 - 1].lgth;
  M53PART =  boardsStruct[53 - 1].v;
  M53GOOD =  boardsStruct[53 - 1].y;

  M32 = boardsStruct[32 - 1].integer;
  M32LGTH =  boardsStruct[32 - 1].lgth;
  M32PART =  boardsStruct[32 - 1].v;
  M32GOOD =  boardsStruct[54 - 1].y;

  if (M54 == 16) {
    M54M = 16;
  }

  if (M54 != 16) {
    M54M = M54;
  }

  ///////

  if (M69 == 16) {
    M69M = 16;
  }

  if (M69 != 16) {
    M69M = M69;
  }

  ///////

  if (M67 == 16) {
    M67M = 16;
  }

 if (M67 != 16) {
    M67M = M67;

  }


  ///////

  if (M61 == 16) {
    M61M = 16;
  }

  if (M61 != 16) {
    M61M = M61;
  }

  ///////

  if (M64 == 16) {
    M64M = 16;
  }

  if (M64 != 16) {
    M64M = M64;
  }

  ///////

  if (M60 == 16) {
    M60M = 16;
  }

  if (M60 != 16) {
    M60M = M60;
  }

  ///////

  if (M76 == 16) {
    M76M = 16;
  }

  if (M76 != 16) {
    M76M = M76;
  }

  ///////

  if (M17 == 16) {
    M17M = 16;
  }

  if (M17 != 16) {
    M17M = M17;
  }

  ///////

  if (M53 == 16) {
    M53M = 16;
  }

  if (M53 != 16) {
    M53M = M53;
  }

  ///////

  if (M32 == 16) {
    M32M = 16;
  }

  if (M32 != 16) {
    M32M = M32;
  }


  //Serial.print("M60 = ");
  //Serial.println(M60);
  //Serial.print("M54 = ");
  //Serial.println(M54);

  if (currentMillis - previousMillis3 >= interval3) {
    previousMillis3 = currentMillis;
    //Serial.print(F("DATA"));
    //Serial.print(F(","));
    //Serial.print(F("DATE"));   //Date
    //Serial.print(F(","));
    //Serial.print(F("TIME"));   //Time
    //Serial.print(F(","));
    Serial.print(M61M);   //61
    Serial.print(F(","));
    Serial.print(M61PART);  //61PART
    Serial.print(F(","));
    Serial.print(M61LGTH / 100); //61LGTH
    Serial.print(F(","));
    Serial.print(M61GOOD);  //61GOOD
    Serial.print(F(","));
    Serial.print(M54M);   //54
    Serial.print(F(","));
    Serial.print(M54PART);  //54PART
    Serial.print(F(","));
    Serial.print(M54LGTH / 100); //54LGTH
    Serial.print(F(","));
    Serial.print(M54GOOD);  //54GOOD
    Serial.print(F(","));
    Serial.print(M17M); //17
    Serial.print(F(","));
    Serial.print(M17PART);  //17PART
    Serial.print(F(","));
    Serial.print(M17LGTH / 100); //17LGTH
    Serial.print(F(","));
    Serial.print(M17GOOD);  //17GOOD
    Serial.print(F(","));
    Serial.print(M67M); //67
    Serial.print(F(","));
    Serial.print(M67PART);  //67PART
    Serial.print(F(","));
    Serial.print(M67LGTH / 100); //67LGTH
    Serial.print(F(","));
    Serial.print(M67GOOD);  //67GOOD
    Serial.print(F(","));
    Serial.print(M76M); //76
    Serial.print(F(","));
    Serial.print(M76PART);  //76PART
    Serial.print(F(","));
    Serial.print(M76LGTH / 100); //76LGTH
    Serial.print(F(","));
    Serial.print(M76GOOD);  //76GOOD
    Serial.print(F(","));
    Serial.print(M60M);  //60
    Serial.print(F(","));
    Serial.print(M60PART);  //60PART
    Serial.print(F(","));
    Serial.print(M60LGTH / 100); //60LGTH
    Serial.print(F(","));
    Serial.print(M60GOOD);  //60GOOD
    Serial.print(F(","));
    Serial.print(M53M); //53
    Serial.print(F(","));
    Serial.print(M53PART);  //53PART
    Serial.print(F(","));
    Serial.print(M53LGTH / 100); //53LGTH
    Serial.print(F(","));
    Serial.print(M53GOOD);  //53GOOD
    Serial.print(F(","));
    Serial.print(M64M); //64
    Serial.print(F(","));
    Serial.print(M64PART);  //64PART
    Serial.print(F(","));
    Serial.print(M64LGTH / 100); //64LGTH
    Serial.print(F(","));
    Serial.print(M64GOOD);  //64GOOD
    Serial.print(F(","));
    Serial.print(M69M); //69
    Serial.print(F(","));
    Serial.print(M69PART);  //69PART
    Serial.print(F(","));
    Serial.print(M69LGTH / 100); //69LGTH
    Serial.print(F(","));
    Serial.print(M69GOOD);  //69GOOD
    Serial.print(F(","));
    Serial.print(M32M); //32
    Serial.print(F(","));
    Serial.print(M32PART);  //32PART
    Serial.print(F(","));
    Serial.print(M32LGTH / 100); //32LGTH
    Serial.print(F(","));
    Serial.println(M32GOOD);  //32GOOD
    //Serial.print(F(","));
    //Serial.print(F(",AUTOSCROLL_20"));
    //Serial.print(F(","));
    //Serial.println(F("DONE"));




  }

}

I tried googling so much regarding this error but there is so many types. Do hope I can find answers here.

Ooops

(Way too many magic numbers in there)

1 Like

You write out of bounds of the array very many times, for example:

Note that your boardsStruct[] array defined as having only 10 elements.

Hi b707,

I've been following this guide:

ESP-NOW: Receive Data from Multiple ESP32 Boards (many-to-one) | Random Nerd Tutorials

Have I misunderstood it?

It shows

typedef struct struct_message {
  int id;
  int x;
  int y;
}struct_message;

// Create a struct_message called myData
struct_message myData;

// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;
struct_message board3;

// Create an array with all the structures
struct_message boardsStruct[3] = {board1, board2, board3};

// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  char macStr[18];
  Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id-1].x = myData.x;
  boardsStruct[myData.id-1].y = myData.y;
  Serial.printf("x value: %d \n", boardsStruct[myData.id-1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id-1].y);
  Serial.println();
}

3 arrays for 3 boards with each board sending 3 variables. I'm very confused :sweat_smile:

No, in the code above there is ONE array for 3 boards, each sending 3 variables.

But it's not that important. The main thing is that in the example there is an array of 3 boards and three boards are used.

And you are trying to use up to 66 cells by creating an array of only 10.

What did you try to achieve with boardsStruct[54 - 1] ?

Do you understand that expression "54 - 1" gives just 53 at run time? So your line is equivalent to
M54 = boardsStruct[53].integer;

which is way out of array limits?

Oh my gosh, I think I get it now. I always assumed that the integer number inside can be any given number to "name" my various transmitter esp32 devices.

Like device number 54. thats why i did [54 - 1]. And yes dumb of me to not realize it is actually 53 in the end.

I'll change all similar

M54 = boardsStruct[54 - 1].integer;

to

M54 = boardsStruct[0].integer;

to

 M32 = boardsStruct[10].integer;

and see how it goes

This incorrect too:

because there is no element with index 10 in array of 10 elements , elements has numbers 0-9

1 Like

Ok I've changed it all and this solved a problem I didn't mention whereby all the figures looked funny until it is connected but since it continued working, I ignored for the moment.

Code as below:

#include <esp_now.h>
#include <WiFi.h>
#include <Wire.h>
TaskHandle_t Task_loop1;

unsigned int currentMillis = 0;
unsigned int previousMillis3 = 0;
unsigned int currentMillis4 = 0;
unsigned int previousMillis4 = 0;

#define interval3 1000
#define interval4 1000

unsigned int M54 = 0;
unsigned int M54PART = 0;
unsigned int M54GOOD = 0;
float M54LGTH = 0;

unsigned int M69 = 0;
unsigned int M69PART = 0;
unsigned int M69GOOD = 0;
float M69LGTH = 0;

unsigned int M67 = 0;
unsigned int M67PART = 0;
unsigned int M67GOOD = 0;
float M67LGTH = 0;
unsigned int M67RUN = 0;
unsigned int M67S0 = 0;
unsigned int M67S1 = 0;
unsigned int M67S2 = 0;
unsigned int M67S3 = 0;
unsigned int M67S4 = 0;
unsigned int M67S5 = 0;
unsigned int M67S6 = 0;
unsigned int M67S7 = 0;
unsigned int M67S8 = 0;
unsigned int M67S9 = 0;
unsigned int M67S10 = 0;


unsigned int M61 = 0;
unsigned int M61PART = 0;
unsigned int M61GOOD = 0;
float M61LGTH = 0;

unsigned int M64 = 0;
unsigned int M64PART = 0;
unsigned int M64GOOD = 0;
float M64LGTH = 0;

unsigned int M60 = 0;
unsigned int M60PART = 0;
unsigned int M60GOOD = 0;
float M60LGTH = 0;
unsigned int M60RUN = 0;
unsigned int M60S0 = 0;
unsigned int M60S1 = 0;
unsigned int M60S2 = 0;
unsigned int M60S3 = 0;
unsigned int M60S4 = 0;
unsigned int M60S5 = 0;
unsigned int M60S6 = 0;
unsigned int M60S7 = 0;
unsigned int M60S8 = 0;
unsigned int M60S9 = 0;
unsigned int M60S10 = 0;

unsigned int M76 = 0;
unsigned int M76PART = 0;
unsigned int M76GOOD = 0;
float M76LGTH = 0;

unsigned int M17 = 0;
unsigned int M17PART = 0;
unsigned int M17GOOD = 0;
float M17LGTH = 0;

unsigned int M53 = 0;
unsigned int M53PART = 0;
unsigned int M53GOOD = 0;
float M53LGTH = 0;

unsigned int M32 = 0;
unsigned int M32PART = 0;
unsigned int M32GOOD = 0;
float M32LGTH = 0;

unsigned int M54M = 0;
unsigned int M69M = 0;
unsigned int M67M = 0;
unsigned int M61M = 0;
unsigned int M64M = 0;
unsigned int M60M = 0;
unsigned int M76M = 0;
unsigned int M17M = 0;
unsigned int M53M = 0;
unsigned int M32M = 0;

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
  byte id;
  byte integer;
  unsigned int lgth;
  unsigned int v;
  byte w;
  byte x;
  unsigned int y;
} struct_message;


struct_message myData;

struct_message board1;
struct_message board2;
struct_message board3;
struct_message board4;
struct_message board5;
struct_message board6;
struct_message board7;
struct_message board8;
struct_message board9;
struct_message board10;

struct_message boardsStruct[10] = {board1, board2, board3, board4, board5, board6, board7, board8, board9, board10};

// Create a struct_message called myData

void data_receive(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  char macStr[18];
  //Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  //Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  //Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  // Update the structures with the new incoming data
  boardsStruct[myData.id - 1].integer = myData.integer;
  boardsStruct[myData.id - 1].lgth = myData.lgth;
  boardsStruct[myData.id - 1].v = myData.v;
  boardsStruct[myData.id - 1].y = myData.y;
}


void esploop1(void* pvParameters) {
  //  Serial.print("WIFI running on core ");
  //  Serial.println(xPortGetCoreID());
  //setup1();
  //for (int i = 0; i <= 1; i++) {

  //for (;;) {
  for (;;) {
    if (currentMillis4 - previousMillis4 >= interval4) {
      previousMillis4 = currentMillis4;





    }
  }
}
/*Serial.println((String)"SAVEWORKBOOKAS,J2_" + (now.year()) + "-" + (now.month()) + "-" + (now.day()));
  Serial.println("CLEARDATA");*/



void setup() {
  // Initialize Serial Monitor
  xTaskCreatePinnedToCore(esploop1, "loop1", 10000, NULL, 1, NULL, 0);
  Serial.begin(112500);

  //Serial.println(F("CLEARDATA"));
  //Serial.println(F("CLEARSHEET"));
  //Serial.println(F("LABEL, Time, M61, M61P, M61L, M61G, M54, M54P, M54L, M54G, M17, M17P, M17L, M17G, M67, M67P, M67L, M67G, M76, M76P, M76L, M76G, M60, M60P, M60L, M60G, M53, M53P, M53L, M53G, M64, M64P, M64L, M64G, M69, M69P, M69L, M69G, M32, M32P, M32L, M32G"));




  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);


  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    //Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(data_receive);

  //lcd3.setCursor (0, 2);
  //lcd3.print(F("--------------------"));

  disableCore0WDT();
}

void loop() {

  currentMillis = millis();

  if (currentMillis - previousMillis3 >= interval3) {
    previousMillis3 = currentMillis;

    M54 = boardsStruct[0].integer;
    M54LGTH =  boardsStruct[0].lgth;
    M54PART =  boardsStruct[0].v;
    M54GOOD =  boardsStruct[0].y;

    M69 = boardsStruct[1].integer;
    M69LGTH =  boardsStruct[1].lgth;
    M69PART =  boardsStruct[1].v;
    M69GOOD =  boardsStruct[1].y;

    M67 = boardsStruct[2].integer;
    M67LGTH =  boardsStruct[2].lgth;
    M67PART =  boardsStruct[2].v;
    M67GOOD =  boardsStruct[2].y;

    M61 = boardsStruct[3].integer;
    M61LGTH =  boardsStruct[3].lgth;
    M61PART =  boardsStruct[3].v;
    M61GOOD =  boardsStruct[3].y;

    M64 = boardsStruct[4].integer;
    M64LGTH =  boardsStruct[4].lgth;
    M64PART =  boardsStruct[4].v;
    M64GOOD =  boardsStruct[4].y;

    M60 = boardsStruct[5].integer;
    M60LGTH =  boardsStruct[5].lgth;
    M60PART =  boardsStruct[5].v;
    M60GOOD =  boardsStruct[5].y;

    M76 = boardsStruct[6].integer;
    M76LGTH =  boardsStruct[6].lgth;
    M76PART =  boardsStruct[6].v;
    M76GOOD =  boardsStruct[6].y;

    M17 = boardsStruct[7].integer;
    M17LGTH =  boardsStruct[7].lgth;
    M17PART =  boardsStruct[7].v;
    M17GOOD =  boardsStruct[7].y;

    M53 = boardsStruct[8].integer;
    M53LGTH =  boardsStruct[8].lgth;
    M53PART =  boardsStruct[8].v;
    M53GOOD =  boardsStruct[8].y;

    M32 = boardsStruct[9].integer;
    M32LGTH =  boardsStruct[9].lgth;
    M32PART =  boardsStruct[9].v;
    M32GOOD =  boardsStruct[9].y;

    if (M54 == 16) {
      M54M = 16;
    }

    else {
      M54M = M54;
    }

    ///////

    if (M69 == 16) {
      M69M = 16;
    }

    else {
      M69M = M69;
    }

    ///////

    if (M67 == 16) {
      M67M = 16;
    }

    else {
      M67M = M67;

    }


    ///////

    if (M61 == 16) {
      M61M = 16;
    }

    else {
      M61M = M61;
    }

    ///////

    if (M64 == 16) {
      M64M = 16;
    }

    else {
      M64M = M64;
    }

    ///////

    if (M60 == 16) {
      M60M = 16;
    }

    else {
      M60M = M60;
    }

    ///////

    if (M76 == 16) {
      M76M = 16;
    }

    else {
      M76M = M76;
    }

    ///////

    if (M17 == 16) {
      M17M = 16;
    }

    else {
      M17M = M17;
    }

    ///////

    if (M53 == 16) {
      M53M = 16;
    }

    else {
      M53M = M53;
    }

    ///////

    if (M32 == 16) {
      M32M = 16;
    }

    else {
      M32M = M32;
    }


    Serial.print(M61M);   //61
    Serial.print(F(","));
    Serial.print(M61PART);  //61PART
    Serial.print(F(","));
    Serial.print(M61LGTH / 100); //61LGTH
    Serial.print(F(","));
    Serial.print(M61GOOD);  //61GOOD
    Serial.print(F(","));
    Serial.print(M54M);   //54
    Serial.print(F(","));
    Serial.print(M54PART);  //54PART
    Serial.print(F(","));
    Serial.print(M54LGTH / 100); //54LGTH
    Serial.print(F(","));
    Serial.print(M54GOOD);  //54GOOD
    Serial.print(F(","));
    Serial.print(M17M); //17
    Serial.print(F(","));
    Serial.print(M17PART);  //17PART
    Serial.print(F(","));
    Serial.print(M17LGTH / 100); //17LGTH
    Serial.print(F(","));
    Serial.print(M17GOOD);  //17GOOD
    Serial.print(F(","));
    Serial.print(M67M); //67
    Serial.print(F(","));
    /* Serial.print(M67RUN);
      Serial.print(F(","));
      Serial.print(M67S0);
      Serial.print(F(","));
      Serial.print(M67S1);
      Serial.print(F(","));
      Serial.print(M67S2);
      Serial.print(F(","));
      Serial.print(M67S3);
      Serial.print(F(","));
      Serial.print(M67S4);
      Serial.print(F(","));
      Serial.print(M67S5);
      Serial.print(F(","));
      Serial.print(M67S6);
      Serial.print(F(","));
      Serial.print(M67S7);
      Serial.print(F(","));
      Serial.print(M67S8);
      Serial.print(F(","));
      Serial.print(M67S9);
      Serial.print(F(","));
      Serial.print(M67S10);
      Serial.print(F(","));*/
    Serial.print(M67PART);  //67PART
    Serial.print(F(","));
    Serial.print(M67LGTH / 100); //67LGTH
    Serial.print(F(","));
    Serial.print(M67GOOD);  //67GOOD
    Serial.print(F(","));
    Serial.print(M76M); //76
    Serial.print(F(","));
    Serial.print(M76PART);  //76PART
    Serial.print(F(","));
    Serial.print(M76LGTH / 100); //76LGTH
    Serial.print(F(","));
    Serial.print(M76GOOD);  //76GOOD
    Serial.print(F(","));
    Serial.print(M60M);  //60
    Serial.print(F(","));
    Serial.print(M60PART);  //60PART
    Serial.print(F(","));
    Serial.print(M60LGTH / 100); //60LGTH
    Serial.print(F(","));
    Serial.print(M60GOOD);  //60GOOD
    Serial.print(F(","));
    Serial.print(M53M); //53
    Serial.print(F(","));
    Serial.print(M53PART);  //53PART
    Serial.print(F(","));
    Serial.print(M53LGTH / 100); //53LGTH
    Serial.print(F(","));
    Serial.print(M53GOOD);  //53GOOD
    Serial.print(F(","));
    Serial.print(M64M); //64
    Serial.print(F(","));
    Serial.print(M64PART);  //64PART
    Serial.print(F(","));
    Serial.print(M64LGTH / 100); //64LGTH
    Serial.print(F(","));
    Serial.print(M64GOOD);  //64GOOD
    Serial.print(F(","));
    Serial.print(M69M); //69
    Serial.print(F(","));
    Serial.print(M69PART);  //69PART
    Serial.print(F(","));
    Serial.print(M69LGTH / 100); //69LGTH
    Serial.print(F(","));
    Serial.print(M69GOOD);  //69GOOD
    Serial.print(F(","));
    Serial.print(M32M); //32
    Serial.print(F(","));
    Serial.print(M32PART);  //32PART
    Serial.print(F(","));
    Serial.print(M32LGTH / 100); //32LGTH
    Serial.print(F(","));
    Serial.println(M32GOOD);  //32GOOD

  }

}

This works fine. But when I enable these,

    /* Serial.print(M67RUN);
      Serial.print(F(","));
      Serial.print(M67S0);
      Serial.print(F(","));
      Serial.print(M67S1);
      Serial.print(F(","));
      Serial.print(M67S2);
      Serial.print(F(","));
      Serial.print(M67S3);
      Serial.print(F(","));
      Serial.print(M67S4);
      Serial.print(F(","));
      Serial.print(M67S5);
      Serial.print(F(","));
      Serial.print(M67S6);
      Serial.print(F(","));
      Serial.print(M67S7);
      Serial.print(F(","));
      Serial.print(M67S8);
      Serial.print(F(","));
      Serial.print(M67S9);
      Serial.print(F(","));
      Serial.print(M67S10);
      Serial.print(F(","));*/

My code crashes and this come out,

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13836
load:0x40080400,len:3608
entry 0x400805f0
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d53be  PS      : 0x00060730  A0      : 0x800d44ec  A1      : 0x3ffb27b0  
A2      : 0x00000378  A3      : 0xffffffff  A4      : 0x000001c2  A5      : 0x00006f40  
A6      : 0x00000003  A7      : 0x00060023  A8      : 0x00000378  A9      : 0x3ffb2770  
A10     : 0x00000001  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x3ffb8b90  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000378  LBEG    : 0x400844ad  LEND    : 0x400844b5  LCOUNT  : 0x00000027  


Backtrace: 0x400d53bb:0x3ffb27b0 0x400d44e9:0x3ffb27e0 0x400d45a2:0x3ffb2800 0x400d4f06:0x3ffb2820




ELF file SHA256: d14b7e0caa9e2a5f

Rebooting...
ets Jul 29 2019 12:21:46

:smiling_face_with_tear:

Yes sorry I meant till [9]

That's a read

Hi b707,

Thank you very much. After I set all my other esp32 devices to the right id and arrays, and my code works fineee!!!!!

Best regards.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.