@@ -173,8 +173,8 @@ void ArduinoIoTCloudTCP::update()
173
173
* 'update' method here in order to process incoming data and generally
174
174
* to transition to the OTA logic update states.
175
175
*/
176
- OTAError const err = _ota_logic.update ();
177
- _ota_error = static_cast <int >(err);
176
+ // OTAError const err = _ota_logic.update();
177
+ // _ota_error = static_cast<int>(err);
178
178
#endif /* OTA_ENABLED */
179
179
180
180
/* Run through the state machine. */
@@ -432,55 +432,34 @@ void ArduinoIoTCloudTCP::onOTARequest()
432
432
433
433
if (_ota_req)
434
434
{
435
- WiFiSSLClient ota_client;
436
- if (!ota_client.connect (" www.107-systems.org" , 443 )) {
437
- DBG_VERBOSE (" ArduinoIoTCloudTCP::%s ota_client.connect failed" , __FUNCTION__);
438
- return ;
439
- }
440
-
441
- /* Request binary via http-get */
442
- /*
443
- char get_msg[128];
444
- snprintf(get_msg, 128, "GET /ota/%s HTTP/1.1", _ota_url.c_str());
445
- DBG_VERBOSE("ArduinoIoTCloudTCP::%s \"%s\"", __FUNCTION__, get_msg);
435
+ /* Clear the request flag. */
436
+ _ota_req = false ;
446
437
447
- ota_client.println(get_msg);
448
- */
449
- ota_client.println (" GET /ota/wifi1010-sha256-remote.ota HTTP/1.1" );
450
- ota_client.println (" Host: www.107-systems.org" );
451
- ota_client.println (" Connection: close" );
452
- ota_client.println ();
438
+ /* Status flag to prevent the reset from being executed
439
+ * when HTTPS download is not supported.
440
+ */
441
+ bool ota_download_success = false ;
453
442
454
- /* Read and parse the received data. */
455
- bool is_header_complete = false ;
456
- size_t bytes_recv = 0 ;
457
- String http_header ;
443
+ # if OTA_STORAGE_SNU
444
+ /* Just to be safe delete any remains from previous updates. */
445
+ WiFiStorage. remove ( " /fs/UPDATE.BIN.LZSS " ) ;
446
+ WiFiStorage. remove ( " /fs/UPDATE.BIN.LZSS.TMP " ) ;
458
447
459
- for (; _ota_error == static_cast <int >(OTAError::None);)
448
+ /* Trigger direct download to nina module. */
449
+ if (!WiFiStorage.downloadOTA (_ota_url.c_str ()))
460
450
{
461
- while (ota_client.available ())
462
- {
463
- char const c = ota_client.read ();
464
-
465
- /* Check if header is complete. */
466
- if (!is_header_complete)
467
- {
468
- http_header += c;
469
- is_header_complete = http_header.endsWith (" \r\n\r\n " );
470
- break ;
471
- }
472
-
473
- /* If we reach this point then the HTTP header has
474
- * been received and we can feed the incoming binary
475
- * data into the OTA state machine.
476
- */
477
- if (_ota_logic.onOTADataReceived (reinterpret_cast <uint8_t const *>(&c), 1 ) == 200 )
478
- {
479
- _ota_error = static_cast <int >(_ota_logic.update ());
480
- bytes_recv += 200 ;
481
- }
482
- }
451
+ DBG_ERROR (" ArduinoIoTCloudTCP::%s download to NiNa failed" , __FUNCTION__, _ota_req ? " true" : " false" );
452
+ _ota_error = static_cast <int >(OTAError::DownloadFailed);
453
+ return ;
483
454
}
455
+
456
+ /* The download was a success. */
457
+ ota_download_success = true ;
458
+ #endif /* OTA_STORAGE_SNU */
459
+
460
+ /* Perform the reset to reboot to SxU. */
461
+ if (ota_download_success)
462
+ NVIC_SystemReset ();
484
463
}
485
464
}
486
465
#endif
0 commit comments