@@ -439,11 +439,14 @@ void ArduinoIoTCloudTCP::onOTARequest()
439439 }
440440
441441 /* Request binary via http-get */
442+ /*
442443 char get_msg[128];
443444 snprintf(get_msg, 128, "GET /ota/%s HTTP/1.1", _ota_url.c_str());
444445 DBG_VERBOSE("ArduinoIoTCloudTCP::%s \"%s\"", __FUNCTION__, get_msg);
445446
446447 ota_client.println(get_msg);
448+ */
449+ ota_client.println (" GET /ota/wifi1010-sha256-remote.ota HTTP/1.1" );
447450 ota_client.println (" Host: www.107-systems.org" );
448451 ota_client.println (" Connection: close" );
449452 ota_client.println ();
@@ -453,26 +456,30 @@ void ArduinoIoTCloudTCP::onOTARequest()
453456 size_t bytes_recv = 0 ;
454457 String http_header;
455458
456- while (ota_client. available () )
459+ for (; _ota_error == static_cast < int >(OTAError::None); )
457460 {
458- char const c = ota_client.read ();
459- Serial.print (c);
460-
461- /* Check if header is complete. */
462- if (!is_header_complete)
461+ while (ota_client.available ())
463462 {
464- http_header += c;
465- is_header_complete = http_header.endsWith (" \r\n\r\n " );
466- break ;
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+ }
467482 }
468-
469- /* If we reach this point then the HTTP header has
470- * been received and we can feed the incoming binary
471- * data into the OTA state machine.
472- */
473- _ota_logic.onOTADataReceived (reinterpret_cast <uint8_t const *>(&c), 1 );
474- _ota_error = static_cast <int >(_ota_logic.update ());
475- DBG_VERBOSE (" ArduinoIoTCloudTCP::%s %d bytes received" , __FUNCTION__, ++bytes_recv);
476483 }
477484 }
478485}
0 commit comments