Skip to content

Commit 02d9ded

Browse files
committed
remove set user key call, move into parse, error checking within nvs
1 parent b8f5d31 commit 02d9ded

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

src/Wippersnapper.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,10 @@ void Wippersnapper::provision() {
7777
// init. LED for status signaling
7878
statusLEDInit();
7979
#ifdef USE_TINYUSB
80-
// init new filesystem
8180
_fileSystem = new Wippersnapper_FS();
82-
// parse out secrets.json file
8381
_fileSystem->parseSecrets();
8482
#elif defined(USE_NVS)
85-
// init esp32 nvs partition namespace
8683
_nvs = new Wippersnapper_ESP32_nvs();
87-
// parse out secrets
8884
_nvs->parseSecrets();
8985
#endif
9086
// Set credentials
@@ -108,19 +104,6 @@ void Wippersnapper::set_user_key(const char *aio_username,
108104
WS._key = aio_key;
109105
}
110106

111-
/****************************************************************************/
112-
/*!
113-
@brief Configures the device's Adafruit IO credentials from the
114-
secrets.json file.
115-
*/
116-
/****************************************************************************/
117-
void Wippersnapper::set_user_key() {
118-
#ifdef USE_TINYUSB
119-
WS._username = _fileSystem->io_username;
120-
WS._key = _fileSystem->io_key;
121-
#endif
122-
}
123-
124107
/**************************************************************************/
125108
/*!
126109
@brief Disconnects from Adafruit IO+ Wippersnapper.

src/Wippersnapper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class Wippersnapper {
187187
bool lockStatusLED = false; ///< True if status LED is using the built-in LED
188188

189189
void set_user_key(const char *aio_username, const char *aio_key);
190-
void set_user_key();
191190
virtual void set_ssid_pass(const char *ssid, const char *ssidPassword);
192191
virtual void set_ssid_pass();
193192

src/provisioning/Wippersnapper_ESP32_nvs.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,26 @@ Wippersnapper_ESP32_nvs::~Wippersnapper_ESP32_nvs() { nvs.end(); }
4444
*/
4545
/****************************************************************************/
4646
void Wippersnapper_ESP32_nvs::parseSecrets() {
47-
// parsey
47+
// Parse from
48+
// https://github.com/adafruit/Adafruit_WebSerial_NVMGenerator/blob/main/wsPartitions.csv
4849
_ssid = nvs.getString("wsNetSSID", "");
4950
_ssidPass = nvs.getString("wsNetPass", "");
5051
_aioUser = nvs.getString("wsAIOUser", "");
5152
_aioPass = nvs.getString("wsAIOKey", "");
52-
_aioURL = nvs.getString("wsAIOURL", "");
5353

54-
// Validate configuration was set within the partition
55-
if (_ssid == "" || _ssidPass == "" || _aioUser == "" || _aioPass == "") {
54+
// Validate getString() calls
55+
if (_ssid.length() == 0 || _ssidPass.length() == 0 ||
56+
_aioUser.length() == 0 || _aioPass.length() == 0) {
5657
WS.setStatusLEDColor(RED);
5758
while (1)
5859
;
5960
}
6061

62+
// optional NVS staging url
63+
_aioURL = nvs.getString("wsAIOURL", "");
64+
if (_aioURL.length() == 0)
65+
_aioURL = "io.adafruit.com";
66+
6167
// Set global configuration strings
6268
WS._network_ssid = _ssid.c_str();
6369
WS._network_pass = _ssidPass.c_str();

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ void Wippersnapper_FS::parseSecrets() {
340340
"effect");
341341
fsHalt();
342342
}
343+
WS._username = _fileSystem->io_username;
343344

344345
// Get io key
345346
io_key = doc["io_key"];
@@ -349,6 +350,7 @@ void Wippersnapper_FS::parseSecrets() {
349350
writeErrorToBootOut("ERROR: invalid io_key value in secrets.json!");
350351
fsHalt();
351352
}
353+
WS._key = _fileSystem->io_key;
352354

353355
// next, we detect the network interface from the `secrets.json`
354356
WS_DEBUG_PRINTLN("Attempting to find network interface...");

0 commit comments

Comments
 (0)