12
12
#include < WiFiNINA.h>
13
13
#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_VERSION
14
14
#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 );
15
21
16
22
void setup () {
17
23
Serial.begin (9600 );
@@ -51,7 +57,7 @@ void setup() {
51
57
}
52
58
53
59
/* 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 );
55
61
csrConfirm.toLowerCase ();
56
62
57
63
if (csrConfirm != " y" ) {
@@ -86,6 +92,7 @@ void setup() {
86
92
87
93
Serial.println (" Generated CSR is:" );
88
94
Serial.println ();
95
+ /* WARNING: This string is parsed from IoTCloud frontend */
89
96
Serial.println (csr);
90
97
91
98
String issueYear = promptAndReadLine (" Please enter the issue year of the certificate (2000 - 2031): " );
@@ -111,6 +118,7 @@ void setup() {
111
118
}
112
119
113
120
if (!Certificate.begin ()) {
121
+ /* WARNING: This string is parsed from IoTCloud frontend */
114
122
Serial.println (" Error starting crypto storage!" );
115
123
while (1 );
116
124
}
@@ -133,12 +141,13 @@ void setup() {
133
141
Serial.println (" Error building cert!" );
134
142
while (1 );
135
143
}
136
-
144
+
137
145
if (!SElementArduinoCloudCertificate::write (secureElement, Certificate, SElementArduinoCloudSlot::CompressedCertificate)) {
138
146
Serial.println (" Error storing cert!" );
139
147
while (1 );
140
148
}
141
149
150
+ /* WARNING: This string is parsed from IoTCloud frontend */
142
151
Serial.println (" Compressed cert = " );
143
152
144
153
const byte* certData = Certificate.bytes ();
@@ -193,18 +202,32 @@ void setup() {
193
202
void loop () {
194
203
}
195
204
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
+ }
199
214
Serial.println (s);
200
215
201
216
return s;
202
217
}
203
218
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
+ }
206
226
207
- while (1 ) {
227
+ String readLine (const unsigned int timeout) {
228
+ String line;
229
+ const unsigned int start = millis ();
230
+ while (!isExpired (start, timeout)) {
208
231
if (Serial.available ()) {
209
232
char c = Serial.read ();
210
233
0 commit comments