Skip to content

Commit e4fcc2e

Browse files
committed
OTA: Use connection handler network adapter type to select between Ethernet and WiFi
1 parent 9da8516 commit e4fcc2e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ void ArduinoIoTCloudTCP::onOTARequest()
830830
#endif
831831

832832
#ifdef BOARD_STM32H7
833-
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str());
833+
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
834+
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str(), use_ethernet);
834835
#endif
835836
}
836837
#endif

src/utility/ota/OTA-portenta-h7.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
#include <Arduino_DebugUtils.h>
2929
#include <Arduino_Portenta_OTA.h>
3030

31+
#include <WiFi.h>
32+
#include <Ethernet.h>
33+
3134
#include "../watchdog/Watchdog.h"
3235

3336
/******************************************************************************
3437
* FUNCTION DEFINITION
3538
******************************************************************************/
3639

37-
int portenta_h7_onOTARequest(char const * ota_url)
40+
int portenta_h7_onOTARequest(char const * ota_url, bool use_ethernet)
3841
{
3942
watchdog_reset();
4043

@@ -63,7 +66,13 @@ int portenta_h7_onOTARequest(char const * ota_url)
6366
watchdog_reset();
6467

6568
/* Download the OTA file from the web storage location. */
66-
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */);
69+
MbedSocketClass * download_socket = static_cast<MbedSocketClass*>(&WiFi);
70+
#if defined (ARDUINO_PORTENTA_H7_M7)
71+
if(use_ethernet) {
72+
download_socket = static_cast<MbedSocketClass*>(&Ethernet);
73+
}
74+
#endif
75+
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */, download_socket);
6776
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", ota_url, ota_portenta_qspi_download_ret_code);
6877

6978
watchdog_reset();

src/utility/ota/OTA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int rp2040_connect_onOTARequest(char const * ota_url);
6363
#endif
6464

6565
#ifdef BOARD_STM32H7
66-
int portenta_h7_onOTARequest(char const * ota_url);
66+
int portenta_h7_onOTARequest(char const * ota_url, bool use_ethernet);
6767
#endif
6868

6969
#endif /* ARDUINO_OTA_LOGIC_H_ */

0 commit comments

Comments
 (0)