Hi. I’m building an automated irrigation system for rice field.
whenever i input something from blynk terminal, esp8266 reboots. Sometimes it work, but most of the time it shows this in serial monitor.
rst cause:2, boot mode:(3,6)
17:23:26.404 ->
17:23:26.404 -> load 0x4010f000, len 3424, room 16
17:23:26.404 -> tail 0
17:23:26.404 -> chksum 0x2e
17:23:26.404 -> load 0x3fff20b8, len 40, room 8
17:23:26.404 -> tail 0
17:23:26.404 -> chksum 0x2b
17:23:26.404 -> csum 0x2b
17:23:26.404 -> v00076700
17:23:26.404 -> ~ld
The code to handle the terminal input
BLYNK_WRITE_DEFAULT() {
String command = param.asStr();
if (command.startsWith("s1c")) {
bs1c = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "s1c is changed");
} else if (command.startsWith("s2c")) {
bs2c = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "s2c is changed");
} else if (command.startsWith("s3c")) {
bs3c = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "s3c is changed");
} else if (command.startsWith("s4c")) {
bs4c = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "s4c is changed");
} else if (command.startsWith("gl")) {
bgroundLevel = command.substring(3).toInt();
Blynk.virtualWrite(V6, "groundLevel is changed");
} else if (command.startsWith("m1l")) {
bm1low = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "mode 1 low threshold is changed");
} else if (command.startsWith("m1h")) {
bm1high = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "mode 1 high threshold is changed");
} else if (command.startsWith("m2t")) {
bm2t = command.substring(4).toFloat();
Blynk.virtualWrite(V6, "mode 2 threshold is changed");
} else if (command.startsWith("prefc")) {
preferences.begin("irrigation", false);
preferences.clear();
preferences.end();
Blynk.virtualWrite(V6, "pref is cleared");
} else if (command.equals("reboot")) {
Blynk.virtualWrite(V6, "Restarting ESP8266...");
//delay(1000);
ESP.restart();
} else if (command.startsWith("idate")) {
String newDate = command.substring(6);
if (isValidDateFormat(newDate)) {
binitialDate = newDate;
GetDateTime(initialDate);
savePreferences1();
Blynk.virtualWrite(V6, "initialDate is changed");
} else {
Blynk.virtualWrite(V6, "Invalid date format. Please use dd/mm/yyyy.");
}
} else if (command.startsWith("lidate")) {
String newDate2 = command.substring(7);
if (isValidDateFormat(newDate2)) {
int liday = newDate2.substring(0, 2).toInt();
int limonth = newDate2.substring(3, 5).toInt()-1;
int liyear = newDate2.substring(6).toInt()-1900;
Serial.print("Last irrigation day: ");
Serial.println(liday);
Serial.print("Last irrigation month: ");
Serial.println(limonth);
Serial.print("Last irrigation year: ");
Serial.println(liyear);
preferences.begin("irrigation", false);
preferences.putInt("lastIrriagationDay", liday);
preferences.putInt("lastIrriagationMon", limonth);
preferences.putInt("lastIrriagationYear", liyear);
preferences.end();
Blynk.virtualWrite(V6, "last irrigation Date is changed");
} else {
Blynk.virtualWrite(V6, "Invalid date format. Please use dd/mm/yyyy.");
}
} else {
// Handle commands received from the Blynk Terminal widget
// Add your custom commands handling here
Blynk.virtualWrite(V6, "Not a command: " + command);
}
savePreferences1();
}
When it fails, it doesn’t even show the value changed confirmation text in the terminal, showing that the error happens before that.
the full code is available here if anyone is interested Code - PasteCode.dev