5
5
#include < WiFiUdp.h>
6
6
#include " ArduinoOTA.h"
7
7
#include " MD5Builder.h"
8
+ #include " StreamString.h"
8
9
9
10
extern " C" {
10
11
#include " osapi.h"
@@ -180,6 +181,7 @@ void ArduinoOTAClass::_onRx(){
180
181
_ota_ip = _udp_ota->getRemoteAddress ();
181
182
_cmd = cmd;
182
183
_ota_port = parseInt ();
184
+ _ota_udp_port = _udp_ota->getRemotePort ();
183
185
_size = parseInt ();
184
186
_udp_ota->read ();
185
187
_md5 = readStringUntil (' \n ' );
@@ -199,12 +201,10 @@ void ArduinoOTAClass::_onRx(){
199
201
char auth_req[38 ];
200
202
sprintf (auth_req, " AUTH %s" , _nonce.c_str ());
201
203
_udp_ota->append ((const char *)auth_req, strlen (auth_req));
202
- _udp_ota->send (&ota_ip, _udp_ota-> getRemotePort () );
204
+ _udp_ota->send (&ota_ip, _ota_udp_port );
203
205
_state = OTA_WAITAUTH;
204
206
return ;
205
207
} else {
206
- _udp_ota->append (" OK" , 2 );
207
- _udp_ota->send (&ota_ip, _udp_ota->getRemotePort ());
208
208
_state = OTA_RUNUPDATE;
209
209
}
210
210
} else if (_state == OTA_WAITAUTH) {
@@ -230,12 +230,10 @@ void ArduinoOTAClass::_onRx(){
230
230
231
231
ota_ip.addr = (uint32_t )_ota_ip;
232
232
if (result.equals (response)){
233
- _udp_ota->append (" OK" , 2 );
234
- _udp_ota->send (&ota_ip, _udp_ota->getRemotePort ());
235
233
_state = OTA_RUNUPDATE;
236
234
} else {
237
235
_udp_ota->append (" Authentication Failed" , 21 );
238
- _udp_ota->send (&ota_ip, _udp_ota-> getRemotePort () );
236
+ _udp_ota->send (&ota_ip, _ota_udp_port );
239
237
if (_error_callback) _error_callback (OTA_AUTH_ERROR);
240
238
_state = OTA_IDLE;
241
239
}
@@ -245,17 +243,31 @@ void ArduinoOTAClass::_onRx(){
245
243
}
246
244
247
245
void ArduinoOTAClass::_runUpdate () {
246
+ ip_addr_t ota_ip;
247
+ ota_ip.addr = (uint32_t )_ota_ip;
248
+
248
249
if (!Update.begin (_size, _cmd)) {
249
250
#ifdef OTA_DEBUG
250
251
OTA_DEBUG.println (" Update Begin Error" );
251
252
#endif
252
253
if (_error_callback) {
253
254
_error_callback (OTA_BEGIN_ERROR);
254
255
}
256
+
257
+ StreamString ss;
258
+ Update.printError (ss);
259
+ _udp_ota->append (" ERR: " , 5 );
260
+ _udp_ota->append (ss.c_str (), ss.length ());
261
+ _udp_ota->send (&ota_ip, _ota_udp_port);
262
+ delay (100 );
255
263
_udp_ota->listen (*IP_ADDR_ANY, _port);
256
264
_state = OTA_IDLE;
257
265
return ;
258
266
}
267
+ _udp_ota->append (" OK" , 2 );
268
+ _udp_ota->send (&ota_ip, _ota_udp_port);
269
+ delay (100 );
270
+
259
271
Update.setMD5 (_md5.c_str ());
260
272
WiFiUDP::stopAll ();
261
273
WiFiClient::stopAll ();
0 commit comments