@@ -32,6 +32,7 @@ UNOR4OTACloudProcess::UNOR4OTACloudProcess(MessageStream *ms)
3232}
3333
3434OTACloudProcessInterface::State UNOR4OTACloudProcess::resume (Message* msg) {
35+ (void )msg;
3536 return OtaBegin;
3637}
3738
@@ -57,22 +58,25 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::startOTA() {
5758}
5859
5960OTACloudProcessInterface::State UNOR4OTACloudProcess::fetch () {
60- int ota_err = OTAUpdate::OTA_ERROR_NONE;
61-
6261 String fv = WiFi.firmwareVersion ();
63- if (fv >= " 0.5.0" ) {
62+ /* Firmware supports non blocking OTA */
63+ if (fv >= " 0.5.0" ) {
6464 auto progress = ota.downloadProgress ();
65+ if (progress < 0 ) {
66+ return OtaDownloadFail;
67+ }
6568
66- if ((millis () - context->lastReportTime ) > 5000 ) { // Report the download progress each X millisecond
69+ if ((millis () - context->lastReportTime ) > 5000 ) { // Report the download progress each X millisecond
6770 DEBUG_VERBOSE (" OTA Download Progress %d/%d" , progress, context->downloadSize );
6871
6972 reportStatus (progress);
7073 context->lastReportTime = millis ();
7174 }
7275
73- if (progress < context->downloadSize ) {
76+ /* It is safe to cast progress here because we are sure that is positive */
77+ if ((size_t )progress < context->downloadSize ) {
7478 return Fetch;
75- } else if ( progress > context->downloadSize || progress < 0 ) {
79+ } else if (( size_t ) progress > context->downloadSize ) {
7680 return OtaDownloadFail;
7781 } else {
7882 return FlashOTA;
@@ -85,7 +89,6 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::fetch() {
8589 }
8690
8791 DEBUG_VERBOSE (" OTAUpdate::download() %d bytes downloaded" , ota_download);
88-
8992 return FlashOTA;
9093 }
9194}
@@ -99,13 +102,18 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::flashOTA() {
99102 }
100103
101104 /* Flash new firmware */
102- if ((ota_err = ota.update (UPDATE_FILE_NAME)) != OTAUpdate::OTA_ERROR_NONE) { // This reboots the MCU
105+ if ((ota_err = ota.update (UPDATE_FILE_NAME)) != OTAUpdate::OTA_ERROR_NONE) {
103106 DEBUG_VERBOSE (" OTAUpdate::update() failed with %d" , ota_err);
104107 return convertUnor4ErrorToState (ota_err);
105108 }
109+
110+ /* This is never called because ota.uptade reboots the microcontroller */
111+ return Resume;
106112}
107113
108114OTACloudProcessInterface::State UNOR4OTACloudProcess::reboot () {
115+ /* This is never called; the microcontroller reboots in flashOTA state */
116+ return Resume;
109117}
110118
111119void UNOR4OTACloudProcess::reset () {
0 commit comments