I’ve done this and it works wonderfully. I look for terminal input being “reboot” and then look at a succeeding password string. If that matches, I execute ESP.reset();
/**************************************************************************************
TERMINAL INTERACTION SECTION
Attached to Virtual Pin V9
Commands supported are help, info, time, upime, wifi, ver, ip, name, reboot, erase
Commands to change labels of widgets like buttons and timers are also supported.
Command format is sn "string" for switches/timers.
**************************************************************************************/
BLYNK_WRITE(V9)
{
int j = 0;
char command_txt[30];
char original_txt[40];
//convert keyed in text to lower case
strcpy(termtxt, param.asStr());
for (int i = 0; termtxt[i]; i++) {
termtxt[i] = tolower(termtxt[i]);
}
//Extract command and arguments and trimming the strings
strcpy(original_txt, termtxt);
String orig = String(original_txt);
orig.trim();
Serial.print("Trimmed original: ");
Serial.println(orig);
int spacepos = orig.indexOf(" ");
String arg = orig.substring(spacepos);
arg.trim();
Serial.print("Argument: ");
Serial.println(arg);
sscanf(termtxt, "%s", command_txt);
strcpy(termtxt, command_txt);
Serial.println(command_txt);
if (String("help") == termtxt) {
terminal.println("\nCommands are not case sensitive");
terminal.println("Supported commands: help, info, clear, time, uptime, wifi, ip, name, ver");
terminal.println("Can change switch/timer names eg. s1 name1");
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("info") == termtxt) {
terminal.print(device_type);
terminal.println();
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("time") == termtxt) {
terminal.print("\nTime: ");
rawtime = now();
ts = localtime ( &rawtime );
strftime (time_stamp, 80, "%a %I:%M%p %d %b %G.", ts);
terminal.println(time_stamp);
Serial.println(time_stamp);
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("uptime") == termtxt) {
int x, days, hours, minutes, months = 0;
x = (millis() / 1000);
Serial.println(x);
days = x / 60 / 60 / 24;
hours = (x / 60 / 60) % 24;
minutes = (x / 60) % 60;
terminal.print("\nUp since ");
terminal.println(firstconnect_ts);
terminal.print("Uptime: " );
terminal.print(days);
terminal.print("d:");
terminal.print(hours);
terminal.print("h:");
terminal.print(minutes);
terminal.println("m");
terminal.flush();
j = 1;
strcpy(prevcmd, termtxt);
update_uptime();
}
if (String("wifi") == termtxt) {
terminal.print("\nSSID: ");
terminal.print(WiFi.SSID());
terminal.print("\nSignal: ");
terminal.print(WiFi.RSSI());
terminal.println("dB");
terminal.flush();
j = 1;
strcpy(prevcmd, termtxt);
}
if (String("ip") == termtxt) {
terminal.print("\nName: ");
terminal.println(WiFi.hostname());
terminal.print("Device ip: ");
terminal.println(WiFi.localIP());
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("name") == termtxt) {
terminal.print("\nName: ");
terminal.println(WiFi.hostname());
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("clear") == termtxt) {
for (int i = 0; i <= 50; i++)
{
terminal.println(""); // "clear screen" in app.
}
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
//Till the reboot commands, the next set of if statements will be used to
//widget labels to suit the customer
if (String("s1") == termtxt) {
if (arg != "") {
Blynk.setProperty(V1, "label", arg);
Blynk.setProperty(V11, "label", (arg + " timer"));
terminal.println("Changed name for s1");
}
else {
terminal.println("No name given");
}
j=1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("s2") == termtxt) {
if (arg != "") {
Blynk.setProperty(V2, "label", arg);
Blynk.setProperty(V12, "label", (arg + " timer"));
terminal.println("Changed name for s2");
}
else {
terminal.println("No name given");
}
j=1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("s3") == termtxt) {
if (arg != "") {
Blynk.setProperty(V3, "label", arg);
Blynk.setProperty(V13, "label", (arg + " timer"));
terminal.println("Changed name for s3");
}
else {
terminal.println("No name given");
}
j=1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("s4") == termtxt) {
if (arg != "") {
Blynk.setProperty(V4, "label", arg);
Blynk.setProperty(V14, "label", (arg + " timer"));
terminal.println("Changed name for s4");
}
else {
terminal.println("No name given");
}
j=1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
// end of label definition section
if (String("reboot") == termtxt) {
terminal.println("\npassword:");
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if (String("erase") == termtxt) {
terminal.println("\npassword:");
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
}
if ((String("mohan") == termtxt) && (String("reboot") == prevcmd)) {
ESP.reset();
}
if ((String("maple") == termtxt) && (String("erase") == prevcmd)) {
wifiManager.resetSettings();
ESP.reset();
}
if (String("ver") == termtxt) {
terminal.print("\nVer: ");
terminal.println(firmware_ver_date);
j = 1;
strcpy(prevcmd, termtxt);
terminal.flush();
} else {
if (!j) {
terminal.println("\nInvalid command");
terminal.flush();
}
}
Serial.print("prevcmd: ");
Serial.println(prevcmd);
terminal.flush();
//exit point of BLYNK_WRITE(V9) Terminal section
}