Skip to content

Commit 84fc709

Browse files
committed
Examples: provisioning, add wifi version check and prompt retry for UNO R4 WiFi
1 parent 31fa0f8 commit 84fc709

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

examples/utility/Provisioning/Provisioning.ino

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include <WiFiNINA.h>
1313
#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_VERSION
1414
#endif
15+
#if defined(ARDUINO_UNOR4_WIFI)
16+
#include <WiFiS3.h>
17+
#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_VERSION
18+
#endif
19+
20+
String promptAndReadLine(const char* prompt, const unsigned int timeout = 0);
1521

1622
void setup() {
1723
Serial.begin(9600);
@@ -51,7 +57,7 @@ void setup() {
5157
}
5258

5359
/* WARNING: This string is parsed from IoTCloud frontend */
54-
String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): ");
60+
String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): ", 5000);
5561
csrConfirm.toLowerCase();
5662

5763
if (csrConfirm != "y") {
@@ -86,6 +92,7 @@ void setup() {
8692

8793
Serial.println("Generated CSR is:");
8894
Serial.println();
95+
/* WARNING: This string is parsed from IoTCloud frontend */
8996
Serial.println(csr);
9097

9198
String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
@@ -111,6 +118,7 @@ void setup() {
111118
}
112119

113120
if (!Certificate.begin()) {
121+
/* WARNING: This string is parsed from IoTCloud frontend */
114122
Serial.println("Error starting crypto storage!");
115123
while (1);
116124
}
@@ -133,12 +141,13 @@ void setup() {
133141
Serial.println("Error building cert!");
134142
while (1);
135143
}
136-
144+
137145
if (!SElementArduinoCloudCertificate::write(secureElement, Certificate, SElementArduinoCloudSlot::CompressedCertificate)) {
138146
Serial.println("Error storing cert!");
139147
while (1);
140148
}
141149

150+
/* WARNING: This string is parsed from IoTCloud frontend */
142151
Serial.println("Compressed cert = ");
143152

144153
const byte* certData = Certificate.bytes();
@@ -193,18 +202,32 @@ void setup() {
193202
void loop() {
194203
}
195204

196-
String promptAndReadLine(const char* prompt) {
197-
Serial.print(prompt);
198-
String s = readLine();
205+
String promptAndReadLine(const char* prompt, const unsigned int timeout) {
206+
String s = "";
207+
while(1) {
208+
Serial.print(prompt);
209+
s = readLine(timeout);
210+
if (s.length() > 0) {
211+
break;
212+
}
213+
}
199214
Serial.println(s);
200215

201216
return s;
202217
}
203218

204-
String readLine() {
205-
String line;
219+
bool isExpired(const unsigned int start, const unsigned int timeout) {
220+
if (timeout) {
221+
return (millis() - start) > timeout;
222+
} else {
223+
return false;
224+
}
225+
}
206226

207-
while (1) {
227+
String readLine(const unsigned int timeout) {
228+
String line;
229+
const unsigned int start = millis();
230+
while (!isExpired(start, timeout)) {
208231
if (Serial.available()) {
209232
char c = Serial.read();
210233

0 commit comments

Comments
 (0)