diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index 2515575c9..dc758a79d 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -72,6 +72,12 @@ #define OTA_ENABLED (0) #endif +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_HAS_NINA (1) +#else + #define BOARD_HAS_NINA (0) +#endif + #if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_PORTENTA_H7_M7) || \ diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index a8a01438c..cb7c4c7fd 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -58,7 +58,9 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP() , _mqtt_data_buf{0} , _mqtt_data_len{0} , _mqtt_data_request_retransmit{false} -#ifdef BOARD_HAS_ECCX08 +#if BOARD_HAS_NINA + /* Do nothing here because we are using onboard onboard SSL on NINA. */ +#elif defined(BOARD_HAS_ECCX08) , _sslClient(nullptr, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM, getTime) #endif #ifdef BOARD_ESP @@ -112,15 +114,17 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) _ota_img_sha256 = FlashSHA256::calc(0x2000, 0x40000 - 0x2000); #endif /* OTA_ENABLED */ - #ifdef BOARD_HAS_ECCX08 +#if BOARD_HAS_NINA + /* Do nothing here because we are using onboard SSL on NINA. */ +#elif defined(BOARD_HAS_ECCX08) if (!ECCX08.begin()) { DBG_ERROR(F("Cryptography processor failure. Make sure you have a compatible board.")); return 0; } if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR(F("Cryptography processor read failure.")); return 0; } if (!CryptoUtil::reconstructCertificate(_eccx08_cert, getDeviceId(), ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { DBG_ERROR(F("Cryptography certificate reconstruction failure.")); return 0; } _sslClient.setClient(_connection->getClient()); _sslClient.setEccSlot(static_cast(ECCX08Slot::Key), _eccx08_cert.bytes(), _eccx08_cert.length()); - #elif defined(BOARD_ESP) +#elif defined(BOARD_ESP) _sslClient.setInsecure(); - #endif +#endif _mqttClient.setClient(_sslClient); #ifdef BOARD_ESP diff --git a/src/ArduinoIoTCloudTCP.h b/src/ArduinoIoTCloudTCP.h index 77a5c957f..5dba888cf 100644 --- a/src/ArduinoIoTCloudTCP.h +++ b/src/ArduinoIoTCloudTCP.h @@ -98,13 +98,15 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass int _mqtt_data_len; bool _mqtt_data_request_retransmit; - #ifdef BOARD_HAS_ECCX08 +#if BOARD_HAS_NINA + WiFiSSLClient _sslClient; +#elif defined(BOARD_HAS_ECCX08) ECCX08CertClass _eccx08_cert; BearSSLClient _sslClient; - #elif defined(BOARD_ESP) +#elif defined(BOARD_ESP) WiFiClientSecure _sslClient; String _password; - #endif +#endif MqttClient _mqttClient;