Stability test?

Hi guys. Is there a way to test the stability of the program written based on the Blynk platform on the NodeMCU board? For example, how do I know that my board continues to work for a long time without crashing?

thanks.

To calculate how many times an ESP8266 has crashed, you can use the ESP8266’s built-in crash counters. You can access these counters using the ESP8266 SDK and the SDK’s system_get_rst_info() function. This function will return a structure containing information about the ESP8266’s reset cause and the crash counters. You can then use the crash counters to determine how many times the ESP8266 has crashed.

You can also add your own reboot counter and use the preferences library to store it in the flash memory and retrieve it after a reboot.
Here’s an example of how to implement a reboot counter using the preferences library:

#include <Preferences.h>
 
Preferences preferences;
 
void setup() {
  preferences.begin("reboot-counter", false); // open preferences with namespace "reboot-counter"
  int rebootCounter = preferences.getUInt("counter", 0); // retrieve the counter value, default to 0 if not found
  Serial.println("Previous reboot counter: " + String(rebootCounter));
  rebootCounter++; // increment the counter
  preferences.putUInt("counter", rebootCounter); // store the updated counter value
}
 
void loop() {
  //empty 
}

A file system can be used as well. You can use Littlefs or Spiffs to write the reboot counter to a file system and retrieve it after a reboot. Here’s a Littlefs example:

#include <LittleFS.h>
 
void setup() {
  LittleFS.begin();
  File file = LittleFS.open("/rebootCounter.txt", "r");
  if (!file) {
    // file doesn't exist, create it with value 0
    file = LittleFS.open("/rebootCounter.txt", "w");
    file.println("0");
    file.close();
  } else {
    // file exists, read the value and increment it
    int rebootCounter = file.parseInt();
    rebootCounter++;
    file.close();
    file = LittleFS.open("/rebootCounter.txt", "w");
    file.println(rebootCounter);
    file.close();
    Serial.println("Previous reboot counter: " + String(rebootCounter));
  }
}
 
void loop() {
  // empty 
}

Last but not least, you can use the Blynk cloud as a storage similar to the above methods.

4 Likes

Thank you for your answer. It was very useful and concise. :rose:

1 Like