Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By fd1
#55789 I am encountering a strange behavior. I am using ESP8266 arduino SPIFFS to store configuration settings. Here is the relevant part of mycode;

Code: Select allvoid loop()
{
      handleUartRxOk();
}

void handleUartRxOk() {
   String cmd;
   
   char charBuff[3200];
   char char_print[50];
   static bool terminatorReceived = false;

   char incomingChar = 0;   // for incoming serial data

   if (Serial.available()) {
      incomingChar = Serial.read();
      saveChar(incomingChar);

      if (incomingChar == '\r') {
         terminatorReceived = true;
      }

      if (terminatorReceived) {
         buffer[buffer_index - 1] = '\0';
         cmd = String(buffer);
         if (cmd == "XXX") {
            ConfigSettings.ssid = "SSID_XX";
            ConfigSettings.password = "PASSWORD_XX";
            saveConfig();
         }
         
         buffer_index = 0;
         terminatorReceived = false;
      }
   }
}


In the above code, the UART will receive a command "XXX\r", then run saveConfig() which will save the config parameters ssid and parameters into SPIFSS. This code works perfectly fine until I add more code which is totally unrelated.

This is how the new code looks like.

Code: Select allvoid handleUartRxOk() {
   String cmd;
   
   char charBuff[3200];
   char char_print[50];
   static bool terminatorReceived = false;

   char incomingChar = 0;   // for incoming serial data

   if (Serial.available()) {
      incomingChar = Serial.read();
      saveChar(incomingChar);

      if (incomingChar == '\r') {
         terminatorReceived = true;
      }

      if (terminatorReceived) {
         buffer[buffer_index - 1] = '\0';
         cmd = String(buffer);
         if (cmd == "XXX") {
            ConfigSettings.ssid = "SSID_XX";
            ConfigSettings.password = "PASSWORD_XX";
            saveConfig();
         }

         //Why does adding this else statement cause saveConfig() to crash?
         else {
               strcat(charBuff, cmd.c_str());
            }   
         
         buffer_index = 0;
         terminatorReceived = false;
      }
   }
}


After adding the additional else clause, sending "XXX\r" to the UARt and causing saveConfig() will cause an exception error. This is puzzling since the new code did not even get to run.

The exception error is as below;

[i]Exception (3):

epc1=0x401002f0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x400072f6 depc=0x00000
000

ctx: sys

sp: 3fff06b0 end: 3fffffb0 offset: 01a0
Last edited by fd1 on Fri Sep 30, 2016 12:36 am, edited 2 times in total.