mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ArduinoOTA: forward errors from Update.begin to espota.py
If Update.begin fails, instead of printing “No response from device”, espota.py will print the actual error message from the Updater.
This commit is contained in:
parent
01e1c586cb
commit
03baea27ef
@ -5,6 +5,7 @@
|
|||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include "ArduinoOTA.h"
|
#include "ArduinoOTA.h"
|
||||||
#include "MD5Builder.h"
|
#include "MD5Builder.h"
|
||||||
|
#include "StreamString.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
@ -180,6 +181,7 @@ void ArduinoOTAClass::_onRx(){
|
|||||||
_ota_ip = _udp_ota->getRemoteAddress();
|
_ota_ip = _udp_ota->getRemoteAddress();
|
||||||
_cmd = cmd;
|
_cmd = cmd;
|
||||||
_ota_port = parseInt();
|
_ota_port = parseInt();
|
||||||
|
_ota_udp_port = _udp_ota->getRemotePort();
|
||||||
_size = parseInt();
|
_size = parseInt();
|
||||||
_udp_ota->read();
|
_udp_ota->read();
|
||||||
_md5 = readStringUntil('\n');
|
_md5 = readStringUntil('\n');
|
||||||
@ -199,12 +201,10 @@ void ArduinoOTAClass::_onRx(){
|
|||||||
char auth_req[38];
|
char auth_req[38];
|
||||||
sprintf(auth_req, "AUTH %s", _nonce.c_str());
|
sprintf(auth_req, "AUTH %s", _nonce.c_str());
|
||||||
_udp_ota->append((const char *)auth_req, strlen(auth_req));
|
_udp_ota->append((const char *)auth_req, strlen(auth_req));
|
||||||
_udp_ota->send(&ota_ip, _udp_ota->getRemotePort());
|
_udp_ota->send(&ota_ip, _ota_udp_port);
|
||||||
_state = OTA_WAITAUTH;
|
_state = OTA_WAITAUTH;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_udp_ota->append("OK", 2);
|
|
||||||
_udp_ota->send(&ota_ip, _udp_ota->getRemotePort());
|
|
||||||
_state = OTA_RUNUPDATE;
|
_state = OTA_RUNUPDATE;
|
||||||
}
|
}
|
||||||
} else if (_state == OTA_WAITAUTH) {
|
} else if (_state == OTA_WAITAUTH) {
|
||||||
@ -230,12 +230,10 @@ void ArduinoOTAClass::_onRx(){
|
|||||||
|
|
||||||
ota_ip.addr = (uint32_t)_ota_ip;
|
ota_ip.addr = (uint32_t)_ota_ip;
|
||||||
if(result.equals(response)){
|
if(result.equals(response)){
|
||||||
_udp_ota->append("OK", 2);
|
|
||||||
_udp_ota->send(&ota_ip, _udp_ota->getRemotePort());
|
|
||||||
_state = OTA_RUNUPDATE;
|
_state = OTA_RUNUPDATE;
|
||||||
} else {
|
} else {
|
||||||
_udp_ota->append("Authentication Failed", 21);
|
_udp_ota->append("Authentication Failed", 21);
|
||||||
_udp_ota->send(&ota_ip, _udp_ota->getRemotePort());
|
_udp_ota->send(&ota_ip, _ota_udp_port);
|
||||||
if (_error_callback) _error_callback(OTA_AUTH_ERROR);
|
if (_error_callback) _error_callback(OTA_AUTH_ERROR);
|
||||||
_state = OTA_IDLE;
|
_state = OTA_IDLE;
|
||||||
}
|
}
|
||||||
@ -245,6 +243,9 @@ void ArduinoOTAClass::_onRx(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoOTAClass::_runUpdate() {
|
void ArduinoOTAClass::_runUpdate() {
|
||||||
|
ip_addr_t ota_ip;
|
||||||
|
ota_ip.addr = (uint32_t)_ota_ip;
|
||||||
|
|
||||||
if (!Update.begin(_size, _cmd)) {
|
if (!Update.begin(_size, _cmd)) {
|
||||||
#ifdef OTA_DEBUG
|
#ifdef OTA_DEBUG
|
||||||
OTA_DEBUG.println("Update Begin Error");
|
OTA_DEBUG.println("Update Begin Error");
|
||||||
@ -252,10 +253,21 @@ void ArduinoOTAClass::_runUpdate() {
|
|||||||
if (_error_callback) {
|
if (_error_callback) {
|
||||||
_error_callback(OTA_BEGIN_ERROR);
|
_error_callback(OTA_BEGIN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamString ss;
|
||||||
|
Update.printError(ss);
|
||||||
|
_udp_ota->append("ERR: ", 5);
|
||||||
|
_udp_ota->append(ss.c_str(), ss.length());
|
||||||
|
_udp_ota->send(&ota_ip, _ota_udp_port);
|
||||||
|
delay(100);
|
||||||
_udp_ota->listen(*IP_ADDR_ANY, _port);
|
_udp_ota->listen(*IP_ADDR_ANY, _port);
|
||||||
_state = OTA_IDLE;
|
_state = OTA_IDLE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_udp_ota->append("OK", 2);
|
||||||
|
_udp_ota->send(&ota_ip, _ota_udp_port);
|
||||||
|
delay(100);
|
||||||
|
|
||||||
Update.setMD5(_md5.c_str());
|
Update.setMD5(_md5.c_str());
|
||||||
WiFiUDP::stopAll();
|
WiFiUDP::stopAll();
|
||||||
WiFiClient::stopAll();
|
WiFiClient::stopAll();
|
||||||
|
@ -79,7 +79,8 @@ class ArduinoOTAClass
|
|||||||
ota_state_t _state;
|
ota_state_t _state;
|
||||||
int _size;
|
int _size;
|
||||||
int _cmd;
|
int _cmd;
|
||||||
int _ota_port;
|
uint16_t _ota_port;
|
||||||
|
uint16_t _ota_udp_port;
|
||||||
IPAddress _ota_ip;
|
IPAddress _ota_ip;
|
||||||
String _md5;
|
String _md5;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
|
|||||||
sent = sock2.sendto(message.encode(), remote_address)
|
sent = sock2.sendto(message.encode(), remote_address)
|
||||||
sock2.settimeout(10)
|
sock2.settimeout(10)
|
||||||
try:
|
try:
|
||||||
data = sock2.recv(37).decode()
|
data = sock2.recv(128).decode()
|
||||||
except:
|
except:
|
||||||
logging.error('No Answer')
|
logging.error('No Answer')
|
||||||
sock2.close()
|
sock2.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user