Skip to content

Commit 21637dd

Browse files
authored
Merge pull request #200 from adafruit/fix-esp32-connect-issue-b19
Fix ESP32 Connection Issue on Beta 19
2 parents 81f0f9c + 6c125cc commit 21637dd

File tree

6 files changed

+27
-57
lines changed

6 files changed

+27
-57
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit WipperSnapper Beta
2-
version=1.0.0-beta.19
2+
version=1.0.0-beta.20
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino client for Adafruit.io WipperSnapper

src/Wippersnapper.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,14 @@ 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-
// validate esp32 has been programmed with credentials
88-
if (!_nvs->validateNVSConfig()) {
89-
WS_DEBUG_PRINTLN(
90-
"ERROR: NVS partition or credentials not found - was NVS flashed?");
91-
while (1)
92-
yield();
93-
}
94-
// pull values out of NVS configuration
95-
_nvs->setNVSConfig();
84+
_nvs->parseSecrets();
9685
#endif
97-
// Set credentials
98-
set_user_key();
86+
87+
// Set WiFi credentials within network interface
9988
set_ssid_pass();
10089
}
10190

@@ -115,19 +104,6 @@ void Wippersnapper::set_user_key(const char *aio_username,
115104
WS._key = aio_key;
116105
}
117106

118-
/****************************************************************************/
119-
/*!
120-
@brief Configures the device's Adafruit IO credentials from the
121-
secrets.json file.
122-
*/
123-
/****************************************************************************/
124-
void Wippersnapper::set_user_key() {
125-
#ifdef USE_TINYUSB
126-
WS._username = _fileSystem->io_username;
127-
WS._key = _fileSystem->io_key;
128-
#endif
129-
}
130-
131107
/**************************************************************************/
132108
/*!
133109
@brief Disconnects from Adafruit IO+ Wippersnapper.
@@ -1218,8 +1194,6 @@ void Wippersnapper::errorWriteHang(String error) {
12181194
/**************************************************************************/
12191195
void Wippersnapper::runNetFSM() {
12201196
WS.feedWDT();
1221-
// MQTT connack RC
1222-
int mqttRC;
12231197
// Initial state
12241198
fsm_net_t fsmNetwork;
12251199
fsmNetwork = FSM_NET_CHECK_MQTT;
@@ -1274,7 +1248,7 @@ void Wippersnapper::runNetFSM() {
12741248
maxAttempts = 10;
12751249
while (maxAttempts >= 0) {
12761250
setStatusLEDColor(LED_IO_CONNECT);
1277-
mqttRC = WS._mqtt->connect();
1251+
int8_t mqttRC = WS._mqtt->connect();
12781252
if (mqttRC == WS_MQTT_CONNECTED) {
12791253
fsmNetwork = FSM_NET_CHECK_MQTT;
12801254
break;

src/Wippersnapper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#endif
6464

6565
#define WS_VERSION \
66-
"1.0.0-beta.19" ///< WipperSnapper app. version (semver-formatted)
66+
"1.0.0-beta.20" ///< WipperSnapper app. version (semver-formatted)
6767

6868
// Reserved Adafruit IO MQTT topics
6969
#define TOPIC_IO_THROTTLE "/throttle" ///< Adafruit IO Throttle MQTT Topic
@@ -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: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
*/
2323
/****************************************************************************/
2424
Wippersnapper_ESP32_nvs::Wippersnapper_ESP32_nvs() {
25-
// init. nvs, read-only
26-
nvs.begin("wsNamespace", false);
25+
// Attempt to initialize NVS partition
26+
if (!nvs.begin("wsNamespace", false)) {
27+
WS.setStatusLEDColor(RED);
28+
while (1)
29+
;
30+
}
2731
}
2832

2933
/****************************************************************************/
@@ -35,39 +39,32 @@ Wippersnapper_ESP32_nvs::~Wippersnapper_ESP32_nvs() { nvs.end(); }
3539

3640
/****************************************************************************/
3741
/*!
38-
@brief Reads and validates credentials from nvs' "wsNamespace"
42+
@brief Reads, validates, and sets credentials from nvs' "wsNamespace"
3943
namespace.
40-
@returns True if credentials were found, False otherwise.
4144
*/
4245
/****************************************************************************/
43-
bool Wippersnapper_ESP32_nvs::validateNVSConfig() {
46+
void Wippersnapper_ESP32_nvs::parseSecrets() {
47+
// Parse from
48+
// https://github.com/adafruit/Adafruit_WebSerial_NVMGenerator/blob/main/wsPartitions.csv
4449
_ssid = nvs.getString("wsNetSSID", "");
4550
_ssidPass = nvs.getString("wsNetPass", "");
4651
_aioUser = nvs.getString("wsAIOUser", "");
4752
_aioPass = nvs.getString("wsAIOKey", "");
48-
_aioURL = nvs.getString("wsAIOURL", "");
4953

50-
// validate config properly set in partition
51-
if (_ssid == "" || _ssidPass == "" || _aioUser == "" || _aioPass == "") {
52-
// TODO: Possibly LED blink/some external error handling around this
53-
return false;
54+
// Validate getString() calls
55+
if (_ssid.length() == 0 || _ssidPass.length() == 0 ||
56+
_aioUser.length() == 0 || _aioPass.length() == 0) {
57+
WS.setStatusLEDColor(RED);
58+
while (1)
59+
;
5460
}
55-
return true;
56-
}
5761

58-
/****************************************************************************/
59-
/*!
60-
@brief Sets Wippersnapper configuration using nvs configuration
61-
@returns True if credentials set successfully, False otherwise.
62-
*/
63-
/****************************************************************************/
64-
bool Wippersnapper_ESP32_nvs::setNVSConfig() {
62+
// Set global configuration strings
6563
WS._network_ssid = _ssid.c_str();
6664
WS._network_pass = _ssidPass.c_str();
6765
WS._username = _aioUser.c_str();
6866
WS._key = _aioPass.c_str();
69-
WS._mqttBrokerURL = _aioURL.c_str();
70-
return true;
67+
WS._mqttBrokerURL = nullptr;
7168
}
7269

7370
#endif // ARDUINO_ARCH_ESP32

src/provisioning/Wippersnapper_ESP32_nvs.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class Wippersnapper_ESP32_nvs {
2929
public:
3030
Wippersnapper_ESP32_nvs();
3131
~Wippersnapper_ESP32_nvs();
32-
33-
bool validateNVSConfig();
34-
bool setNVSConfig();
32+
void parseSecrets();
3533

3634
Preferences nvs; ///< Provides access to ESP32's Non-Volatile Storage
3735

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 = 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 = 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)