Skip to content

Commit 300a38e

Browse files
committed
add user confirmation
1 parent 8440f09 commit 300a38e

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

examples/utility/DeleteConfiguration/DeleteConfiguration.ino

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,34 @@ SerialAgentClass SerialAgent;
2525
GenericConnectionHandler conMan;
2626
NetworkConfiguratorClass NetworkConfigurator(conMan);
2727

28+
bool waitResponse() {
29+
bool confirmation = false;
30+
bool proceed = false;
31+
while (confirmation == false) {
32+
if (Serial.available()) {
33+
char choice = Serial.read();
34+
switch (choice) {
35+
case 'y':
36+
case 'Y':
37+
confirmation = true;
38+
proceed = true;
39+
break;
40+
case 'n':
41+
case 'N':
42+
confirmation = true;
43+
proceed = false;
44+
break;
45+
default:
46+
continue;
47+
}
48+
}
49+
}
50+
return proceed;
51+
}
52+
2853
void setup() {
2954
/* Initialize serial debug port and wait up to 5 seconds for port to open */
3055
Serial.begin(9600);
31-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
3256

3357
/* Set the debug message level:
3458
* - DBG_ERROR: Only show error messages
@@ -39,15 +63,24 @@ void setup() {
3963
*/
4064
setDebugMessageLevel(DBG_INFO);
4165

66+
while (!Serial);
67+
4268
/* Set the KVStore */
4369
NetworkConfigurator.setStorage(kvstore);
44-
/* Wipe out the network configuration */
45-
if (NetworkConfigurator.resetStoredConfiguration()) {
46-
Serial.println("Network configuration reset successfully.");
70+
71+
Serial.println("\nWARNING! Running the sketch the stored network configuration will be erased.");
72+
Serial.println("Do you want to proceed? Y/[n]");
73+
74+
if (true == waitResponse()) {
75+
/* Wipe out the network configuration */
76+
if (NetworkConfigurator.resetStoredConfiguration()) {
77+
Serial.println("Network configuration reset successfully.");
78+
} else {
79+
Serial.println("Failed to reset network configuration.");
80+
}
4781
} else {
48-
Serial.println("Failed to reset network configuration.");
82+
Serial.println("Aborted.");
4983
}
50-
5184
}
5285

5386
void loop() {

0 commit comments

Comments
 (0)