Skip to content

Commit 94b601f

Browse files
authored
Add example for erasing the network configuration via library api (#20)
* add example for wiping out the network configuration * add user confirmation
1 parent 0f19b47 commit 94b601f

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- name: Arduino_KVStore
3636
SKETCH_PATHS: |
3737
- examples/NetworkConfiguratorDemo
38+
- examples/utility/DeleteConfiguration
3839
SKETCHES_REPORTS_PATH: sketches-reports
3940
strategy:
4041
fail-fast: false
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright (c) 2025 Arduino SA
3+
4+
This Source Code Form is subject to the terms of the Mozilla Public
5+
License, v. 2.0. If a copy of the MPL was not distributed with this
6+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
/*
10+
* This sketch wipes out the stored network configuration
11+
* using the NetworkConfigurator library.
12+
* This sketch doesn't use the reconfiguration procedure.
13+
*/
14+
15+
#include <Arduino_ConnectionHandler.h>
16+
#include <GenericConnectionHandler.h>
17+
#include <Arduino_KVStore.h>
18+
#include <Arduino_NetworkConfigurator.h>
19+
#include <configuratorAgents/agents/BLEAgent.h>
20+
#include <configuratorAgents/agents/SerialAgent.h>
21+
22+
KVStore kvstore;
23+
BLEAgentClass BLEAgent;
24+
SerialAgentClass SerialAgent;
25+
GenericConnectionHandler conMan;
26+
NetworkConfiguratorClass NetworkConfigurator(conMan);
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+
53+
void setup() {
54+
/* Initialize serial debug port and wait up to 5 seconds for port to open */
55+
Serial.begin(9600);
56+
57+
/* Set the debug message level:
58+
* - DBG_ERROR: Only show error messages
59+
* - DBG_WARNING: Show warning and error messages
60+
* - DBG_INFO: Show info, warning, and error messages
61+
* - DBG_DEBUG: Show debug, info, warning, and error messages
62+
* - DBG_VERBOSE: Show all messages
63+
*/
64+
setDebugMessageLevel(DBG_INFO);
65+
66+
while (!Serial);
67+
68+
/* Set the KVStore */
69+
NetworkConfigurator.setStorage(kvstore);
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+
}
81+
} else {
82+
Serial.println("Aborted.");
83+
}
84+
}
85+
86+
void loop() {
87+
}

0 commit comments

Comments
 (0)