2121#include < utility/SElementArduinoCloud.h>
2222#include < utility/SElementArduinoCloudCertificate.h>
2323#include < Arduino_JSON.h>
24- #include < WiFiNINA.h>
2524
2625const bool DEBUG = true ;
2726
@@ -31,16 +30,35 @@ char client_id[] = SECRET_CLIENT_ID;
3130char secret_id[] = SECRET_SECRET_ID;
3231
3332#if defined(ARDUINO_SAMD_NANO_33_IOT)
33+ #include < WiFiNINA.h>
3434 char board_type[] = " nano_33_iot" ; // Nano 33 IoT
3535 char board_fqbn[] = " arduino:samd:nano_33_iot" ; // Nano 33 IoT
3636#elif defined(ARDUINO_SAMD_MKRWIFI1010)
37+ #include < WiFiNINA.h>
3738 char board_type[] = " mkrwifi1010" ; // MKR WiFi 1010
3839 char board_fqbn[] = " arduino:samd:mkrwifi1010" ; // MKR WiFi 1010
3940#elif defined(ARDUINO_NANO_RP2040_CONNECT)
41+ #include < WiFiNINA.h>
4042 char board_type[] = " nanorp2040connect" ; // Nano RP2040 Connect
4143 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
4260#else
43- char board_type[] = " nonina " ; // Not supported boards
61+ char board_type[] = " unsupported " ; // Not supported boards
4462 char board_fqbn[] = " " ;
4563#endif
4664
@@ -67,7 +85,7 @@ void setup() {
6785 Serial.begin (9600 );
6886 while (!Serial);
6987
70- if (board_type == " nonina " ) {
88+ if (board_type == " unsupported " ) {
7189 Serial.println (" Sorry, this sketch only works on Nano 33 IoT and MKR 1010 WiFi" );
7290 while (1 ) { ; }
7391 }
@@ -356,6 +374,7 @@ void WiFiFirmwareVersion(String fv, String deviceId, String token) {
356374 client.println ();
357375 client.println (PostData);
358376 }
377+ client.stop ();
359378}
360379
361380void ArduinoToken (String client_id, String client_secret) {
@@ -398,12 +417,14 @@ void ArduinoToken(String client_id, String client_secret) {
398417 if (tokenResponse[intIndex] == -1 ) {
399418 break ;
400419 }
420+ delay (1 );
401421 intIndex++;
402422 }
403423 JSONVar myObject = JSON.parse (tokenResponse);
404424 if (myObject.hasOwnProperty (" access_token" )) {
405425 Arduino_Token += (const char *) myObject[" access_token" ];
406426 }
427+ client.stop ();
407428}
408429
409430void 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
432453 }
433454
434455 while (!client.available ()) {
435- ;
456+ Serial.println (" No client" );
457+ delay (2000 );
436458 }
437459
438460 char endOfHeaders[] = " \r\n\r\n " ;
@@ -451,12 +473,14 @@ void BoardUuid(String board_name, String board_type, String board_fqbn, String b
451473 if (deviceResponse[intIndex] == -1 ) {
452474 break ;
453475 }
476+ delay (1 );
454477 intIndex++;
455478 }
456479 JSONVar myObject = JSON.parse (deviceResponse);
457480 if (myObject.hasOwnProperty (" id" )) {
458481 deviceId += (const char *) myObject[" id" ];
459482 }
483+ client.stop ();
460484}
461485
462486void ArduinoCertificate (String user_token, String DeviceUuid, String csr) {
@@ -505,6 +529,7 @@ void ArduinoCertificate(String user_token, String DeviceUuid, String csr) {
505529 if (certResponse[intIndex] == -1 ) {
506530 break ;
507531 }
532+ delay (1 );
508533 intIndex++;
509534 }
510535 char * p = strstr (certResponse, " {" );
0 commit comments