Skip to content

Commit

Permalink
global.h: add initialization to log message array
Browse files Browse the repository at this point in the history
hopfully the Exception (28) crashes go away after this
  • Loading branch information
madmartin committed Jun 2, 2018
1 parent 128c289 commit ba46258
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions Jarolift_MQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void setup()
EEPROM.begin(4096);
Serial.begin(115200);
delay(500);
InitLog();
WriteLog("[INFO] - starting Jarolift Dongle "+ (String)PROGRAM_VERSION, true);
WriteLog("[INFO] - ESP-ID "+ (String)ESP.getChipId()+ " // ESP-Core "+ ESP.getCoreVersion()+ " // SDK Version "+ ESP.getSdkVersion(), true);

Expand Down
25 changes: 19 additions & 6 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,43 @@ struct strConfig {
} config;


//####################################################################
// Initalize log message array with empty strings
//####################################################################
void InitLog()
{
for ( int i = 0; i < NUM_WEB_LOG_MESSAGES; i++ ) {
web_log_message[i] = "";
}
}

//####################################################################
// Function to write Log to both, serial and Weblog
//####################################################################
void WriteLog(String msg, boolean new_line = false)
{
// check if log buffer is "full"
if (web_log_message_count == NUM_WEB_LOG_MESSAGES) {
// when full then move all messages one line up
for ( int i = 1; i < NUM_WEB_LOG_MESSAGES; ++i ) {
web_log_message[i - 1] = web_log_message[i];
}
web_log_message[NUM_WEB_LOG_MESSAGES-1] = "";
web_log_message_count--;
web_log_message[web_log_message_count] = "";
}

if (web_log_message[web_log_message_count] == "") {
web_log_message[web_log_message_count] = msg;
} else {
web_log_message[web_log_message_count] += " " + msg;
}
if (new_line == true) {
web_log_message[web_log_message_count] = web_log_message[web_log_message_count] + " " + msg;
web_log_message_count++;
//web_log = web_log + " " + msg + "\n";
Serial.println(" " + msg);
} else {
web_log_message[web_log_message_count] = web_log_message[web_log_message_count] + " " + msg;
//web_log = web_log + " " + msg;
Serial.print(" " + msg);
}

delay(2);
}

//####################################################################
Expand Down

0 comments on commit ba46258

Please sign in to comment.