@@ -25,10 +25,34 @@ SerialAgentClass SerialAgent;
25
25
GenericConnectionHandler conMan;
26
26
NetworkConfiguratorClass NetworkConfigurator (conMan);
27
27
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
+
28
53
void setup () {
29
54
/* Initialize serial debug port and wait up to 5 seconds for port to open */
30
55
Serial.begin (9600 );
31
- for (unsigned long const serialBeginTime = millis (); !Serial && (millis () - serialBeginTime <= 5000 ); ) { }
32
56
33
57
/* Set the debug message level:
34
58
* - DBG_ERROR: Only show error messages
@@ -39,15 +63,24 @@ void setup() {
39
63
*/
40
64
setDebugMessageLevel (DBG_INFO);
41
65
66
+ while (!Serial);
67
+
42
68
/* Set the KVStore */
43
69
NetworkConfigurator.setStorage (kvstore);
44
- /* Wipe out the network configuration */
45
- if (NetworkConfigurator.resetStoredConfiguration ()) {
46
- Serial.println (" Network configuration reset successfully." );
70
+
71
+ Serial.println (" \n WARNING! 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
+ }
47
81
} else {
48
- Serial.println (" Failed to reset network configuration ." );
82
+ Serial.println (" Aborted ." );
49
83
}
50
-
51
84
}
52
85
53
86
void loop () {
0 commit comments