Skip to content

Commit c65bd2b

Browse files
committed
Move opening of update file to the very beginning of the OTA function (makes error handling easier - see next step).
1 parent 867a6ac commit c65bd2b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/utility/ota/OTA-nano-rp2040.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,19 @@ void URI::parse(const string& url_s)
8080

8181
int rp2040_connect_onOTARequest(char const * ota_url)
8282
{
83+
mbed_watchdog_reset();
84+
8385
SFU::begin();
8486

85-
remove("/ota/UPDATE.BIN.LZSS");
87+
mbed_watchdog_reset();
88+
89+
FILE * file = fopen("/ota/UPDATE.BIN.LZSS", "wb");
90+
if (!file)
91+
{
92+
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
93+
fclose(file);
94+
return static_cast<int>(OTAError::RP2040_ErrorOpenUpdateFile);
95+
}
8696

8797
mbed_watchdog_reset();
8898

@@ -103,9 +113,9 @@ int rp2040_connect_onOTARequest(char const * ota_url)
103113

104114
mbed_watchdog_reset();
105115

106-
int ret = client->connect(url.host_.c_str(), port);
107-
if (!ret)
116+
if (!client->connect(url.host_.c_str(), port))
108117
{
118+
fclose(file);
109119
DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str());
110120
return static_cast<int>(OTAError::RP2040_ServerConnectError);
111121
}
@@ -119,14 +129,6 @@ int rp2040_connect_onOTARequest(char const * ota_url)
119129

120130
mbed_watchdog_reset();
121131

122-
FILE * file = fopen("/ota/UPDATE.BIN.LZSS", "wb");
123-
if (!file)
124-
{
125-
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
126-
fclose(file);
127-
return static_cast<int>(OTAError::RP2040_ErrorOpenUpdateFile);
128-
}
129-
130132
/* Receive HTTP header. */
131133
String http_header;
132134
bool is_header_complete = false,

0 commit comments

Comments
 (0)