21
21
#include < utility/SElementArduinoCloud.h>
22
22
#include < utility/SElementArduinoCloudCertificate.h>
23
23
#include < Arduino_JSON.h>
24
- #include < WiFiNINA.h>
25
24
26
25
const bool DEBUG = true ;
27
26
@@ -31,16 +30,35 @@ char client_id[] = SECRET_CLIENT_ID;
31
30
char secret_id[] = SECRET_SECRET_ID;
32
31
33
32
#if defined(ARDUINO_SAMD_NANO_33_IOT)
33
+ #include < WiFiNINA.h>
34
34
char board_type[] = " nano_33_iot" ; // Nano 33 IoT
35
35
char board_fqbn[] = " arduino:samd:nano_33_iot" ; // Nano 33 IoT
36
36
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
37
+ #include < WiFiNINA.h>
37
38
char board_type[] = " mkrwifi1010" ; // MKR WiFi 1010
38
39
char board_fqbn[] = " arduino:samd:mkrwifi1010" ; // MKR WiFi 1010
39
40
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
41
+ #include < WiFiNINA.h>
40
42
char board_type[] = " nanorp2040connect" ; // Nano RP2040 Connect
41
43
char board_fqbn[] = " arduino:mbed_nano:nanorp2040connect" ; // Nano RP2040 Connect
44
+ #elif defined(ARDUINO_PORTENTA_H7_M7)
45
+ #include < WiFi.h>
46
+ char board_type[] = " envie_m7" ; // Portenta H7
47
+ char board_fqbn[] = " arduino:mbed_portenta:envie_m7" ; // Portenta H7
48
+ #elif defined(ARDUINO_NICLA_VISION)
49
+ #include < WiFi.h>
50
+ char board_type[] = " nicla_vision" ; // Nicla Vision
51
+ char board_fqbn[] = " arduino:mbed_nicla:nicla_vision" ; // Nicla Vision
52
+ #elif defined(ARDUINO_GIGA)
53
+ #include < WiFi.h>
54
+ char board_type[] = " giga" ; // Giga R1 WiFi
55
+ char board_fqbn[] = " arduino:mbed_giga:giga" ; // Giga R1 WiFi
56
+ #elif defined(ARDUINO_OPTA)
57
+ #include < WiFi.h>
58
+ char board_type[] = " opta" ; // Opta
59
+ char board_fqbn[] = " arduino:mbed_opta:opta" ; // Opta
42
60
#else
43
- char board_type[] = " nonina " ; // Not supported boards
61
+ char board_type[] = " unsupported " ; // Not supported boards
44
62
char board_fqbn[] = " " ;
45
63
#endif
46
64
@@ -67,7 +85,7 @@ void setup() {
67
85
Serial.begin (9600 );
68
86
while (!Serial);
69
87
70
- if (board_type == " nonina " ) {
88
+ if (board_type == " unsupported " ) {
71
89
Serial.println (" Sorry, this sketch only works on Nano 33 IoT and MKR 1010 WiFi" );
72
90
while (1 ) { ; }
73
91
}
@@ -356,6 +374,7 @@ void WiFiFirmwareVersion(String fv, String deviceId, String token) {
356
374
client.println ();
357
375
client.println (PostData);
358
376
}
377
+ client.stop ();
359
378
}
360
379
361
380
void ArduinoToken (String client_id, String client_secret) {
@@ -398,12 +417,14 @@ void ArduinoToken(String client_id, String client_secret) {
398
417
if (tokenResponse[intIndex] == -1 ) {
399
418
break ;
400
419
}
420
+ delay (1 );
401
421
intIndex++;
402
422
}
403
423
JSONVar myObject = JSON.parse (tokenResponse);
404
424
if (myObject.hasOwnProperty (" access_token" )) {
405
425
Arduino_Token += (const char *) myObject[" access_token" ];
406
426
}
427
+ client.stop ();
407
428
}
408
429
409
430
void BoardUuid (String board_name, String board_type, String board_fqbn, String board_serial, String user_token) {
@@ -432,7 +453,8 @@ void BoardUuid(String board_name, String board_type, String board_fqbn, String b
432
453
}
433
454
434
455
while (!client.available ()) {
435
- ;
456
+ Serial.println (" No client" );
457
+ delay (2000 );
436
458
}
437
459
438
460
char endOfHeaders[] = " \r\n\r\n " ;
@@ -451,12 +473,14 @@ void BoardUuid(String board_name, String board_type, String board_fqbn, String b
451
473
if (deviceResponse[intIndex] == -1 ) {
452
474
break ;
453
475
}
476
+ delay (1 );
454
477
intIndex++;
455
478
}
456
479
JSONVar myObject = JSON.parse (deviceResponse);
457
480
if (myObject.hasOwnProperty (" id" )) {
458
481
deviceId += (const char *) myObject[" id" ];
459
482
}
483
+ client.stop ();
460
484
}
461
485
462
486
void ArduinoCertificate (String user_token, String DeviceUuid, String csr) {
@@ -505,6 +529,7 @@ void ArduinoCertificate(String user_token, String DeviceUuid, String csr) {
505
529
if (certResponse[intIndex] == -1 ) {
506
530
break ;
507
531
}
532
+ delay (1 );
508
533
intIndex++;
509
534
}
510
535
char * p = strstr (certResponse, " {" );
0 commit comments