21
21
#include < Arduino_DebugUtils.h>
22
22
#include < WiFiC3.h>
23
23
#include < WiFiSSLClient.h>
24
+ #include < Client.h>
24
25
25
26
#define AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (5 *1000UL );
26
27
#define AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms (5 *60 *1000UL );
@@ -74,7 +75,7 @@ void URI::parse(const string& url_s)
74
75
query_.assign (query_i, url_s.end ());
75
76
}
76
77
77
- int SFU::download (const char * ota_path, const char * ota_url) {
78
+ int SFU::download (Client& client, const char * ota_path, const char * ota_url) {
78
79
int err = -1 ;
79
80
80
81
FILE * file = fopen (ota_path, " wb" );
@@ -86,32 +87,29 @@ int SFU::download(const char* ota_path, const char* ota_url) {
86
87
}
87
88
88
89
URI url (ota_url);
89
- Client * client = nullptr ;
90
90
int port = 0 ;
91
91
92
92
if (url.protocol_ == " http" ) {
93
- client = new WiFiClient ();
94
93
port = 80 ;
95
94
} else if (url.protocol_ == " https" ) {
96
- client = new WiFiSSLClient ();
97
95
port = 443 ;
98
96
} else {
99
97
DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, url.host_ .c_str ());
100
98
fclose (file);
101
99
return static_cast <int >(OTAError::PORTENTA_C33_UrlParseError);
102
100
}
103
101
104
- if (!client-> connect (url.host_ .c_str (), port))
102
+ if (!client. connect (url.host_ .c_str (), port))
105
103
{
106
104
DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
107
105
fclose (file);
108
106
return static_cast <int >(OTAError::PORTENTA_C33_ServerConnectError);
109
107
}
110
108
111
- client-> println (String (" GET " ) + url.path_ .c_str () + " HTTP/1.1" );
112
- client-> println (String (" Host: " ) + url.host_ .c_str ());
113
- client-> println (" Connection: close" );
114
- client-> println ();
109
+ client. println (String (" GET " ) + url.path_ .c_str () + " HTTP/1.1" );
110
+ client. println (String (" Host: " ) + url.host_ .c_str ());
111
+ client. println (" Connection: close" );
112
+ client. println ();
115
113
116
114
/* Receive HTTP header. */
117
115
String http_header;
@@ -122,9 +120,9 @@ int SFU::download(const char* ota_path, const char* ota_url) {
122
120
is_http_header_timeout = (millis () - start) > AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms;
123
121
if (is_http_header_timeout) break ;
124
122
125
- if (client-> available ())
123
+ if (client. available ())
126
124
{
127
- char const c = client-> read ();
125
+ char const c = client. read ();
128
126
129
127
http_header += c;
130
128
if (http_header.endsWith (" \r\n\r\n " ))
@@ -166,9 +164,9 @@ int SFU::download(const char* ota_path, const char* ota_url) {
166
164
is_http_data_timeout = (millis () - start) > AIOT_CONFIG_PORTENTA_C33_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms;
167
165
if (is_http_data_timeout) break ;
168
166
169
- if (client-> available ())
167
+ if (client. available ())
170
168
{
171
- char const c = client-> read ();
169
+ char const c = client. read ();
172
170
173
171
if (fwrite (&c, 1 , sizeof (c), file) != sizeof (c))
174
172
{
0 commit comments