@@ -138,7 +138,7 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
138138#endif /* AVR */
139139
140140#if OTA_ENABLED && !defined(__AVR__)
141- _ota_img_sha256 = getOTAImageSHA256 ();
141+ _ota_img_sha256 = OTA::getImageSHA256 ();
142142 DEBUG_VERBOSE (" SHA256: HASH(%d) = %s" , strlen (_ota_img_sha256.c_str ()), _ota_img_sha256.c_str ());
143143#endif /* OTA_ENABLED */
144144
@@ -205,38 +205,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
205205 addPropertyReal (_tz_offset, " tz_offset" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
206206 addPropertyReal (_tz_dst_until, " tz_dst_until" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
207207
208- #if OTA_STORAGE_PORTENTA_QSPI
209- #define BOOTLOADER_ADDR (0x8000000 )
210- uint32_t bootloader_data_offset = 0x1F000 ;
211- uint8_t * bootloader_data = (uint8_t *)(BOOTLOADER_ADDR + bootloader_data_offset);
212- uint8_t currentBootloaderVersion = bootloader_data[1 ];
213- if (currentBootloaderVersion < 22 ) {
214- _ota_cap = false ;
215- DEBUG_WARNING (" ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader" , __FUNCTION__);
216- DEBUG_WARNING (" ArduinoIoTCloudTCP::%s File -> Examples -> Portenta_System -> PortentaH7_updateBootloader" , __FUNCTION__);
217- }
218- else {
219- _ota_cap = true ;
220- }
221- #endif
222-
223- #if OTA_STORAGE_SNU && OTA_ENABLED
224- if (String (WiFi.firmwareVersion ()) < String (" 1.4.1" )) {
225- _ota_cap = false ;
226- DEBUG_WARNING (" ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, NINA firmware needs to be >= 1.4.1, current %s" , __FUNCTION__, WiFi.firmwareVersion ());
227- }
228- else {
229- _ota_cap = true ;
230- }
231- #endif /* OTA_STORAGE_SNU */
232-
233- #if defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_NICLA_VISION)
234- _ota_cap = true ;
235- #endif
236-
237- #if defined(ARDUINO_ARCH_ESP32) && OTA_ENABLED
238- /* NOTE: here is possible to check if current partition scheme is OTA compatible */
239- _ota_cap = true ;
208+ #if OTA_ENABLED
209+ _ota_cap = OTA::isCapable ();
240210#endif
241211
242212#ifdef BOARD_HAS_OFFLOADED_ECCX08
@@ -609,7 +579,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
609579 /* Transmit the cleared request flags to the cloud. */
610580 sendDevicePropertyToCloud (" OTA_REQ" );
611581 /* Call member function to handle OTA request. */
612- onOTARequest ( );
582+ _ota_error = OTA::onRequest (_ota_url, _connection-> getInterface () );
613583 /* If something fails send the OTA error to the cloud */
614584 sendDevicePropertyToCloud (" OTA_ERROR" );
615585 }
@@ -762,45 +732,6 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
762732 return 0 ;
763733}
764734
765- #if OTA_ENABLED
766- void ArduinoIoTCloudTCP::onOTARequest ()
767- {
768- DEBUG_INFO (" ArduinoIoTCloudTCP::%s _ota_url = %s" , __FUNCTION__, _ota_url.c_str ());
769-
770- #ifdef ARDUINO_ARCH_SAMD
771- _ota_error = samd_onOTARequest (_ota_url.c_str ());
772- #endif
773-
774- #ifdef ARDUINO_NANO_RP2040_CONNECT
775- _ota_error = rp2040_connect_onOTARequest (_ota_url.c_str ());
776- #endif
777-
778- #ifdef BOARD_STM32H7
779- bool const use_ethernet = _connection->getInterface () == NetworkAdapter::ETHERNET ? true : false ;
780- _ota_error = portenta_h7_onOTARequest (_ota_url.c_str (), use_ethernet);
781- #endif
782-
783- #ifdef ARDUINO_ARCH_ESP32
784- _ota_error = esp32_onOTARequest (_ota_url.c_str ());
785- #endif
786- }
787-
788- String ArduinoIoTCloudTCP::getOTAImageSHA256 ()
789- {
790- #if defined (ARDUINO_ARCH_SAMD)
791- return samd_getOTAImageSHA256 ();
792- #elif defined (ARDUINO_NANO_RP2040_CONNECT)
793- return rp2040_connect_getOTAImageSHA256 ();
794- #elif defined (BOARD_STM32H7)
795- return portenta_h7_getOTAImageSHA256 ();
796- #elif defined (ARDUINO_ARCH_ESP32)
797- return esp32_getOTAImageSHA256 ();
798- #else
799- # error "No method for SHA256 checksum calculation over application image defined for this architecture."
800- #endif
801- }
802- #endif
803-
804735void ArduinoIoTCloudTCP::updateThingTopics ()
805736{
806737 _shadowTopicOut = getTopic_shadowout ();
0 commit comments