mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +03:00
Fix example sketch, espota output and failing updater
I get 100% success with OTA now
This commit is contained in:
parent
83b035d3a1
commit
e613e42249
@ -103,7 +103,7 @@ class UpdaterClass {
|
||||
}
|
||||
if(remaining() == 0)
|
||||
return written;
|
||||
yield();
|
||||
delay(1);
|
||||
available = data.available();
|
||||
}
|
||||
return written;
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
const char* host = "esp8266-ota";
|
||||
const char* ssid = "**********";
|
||||
const char* pass = "**********";
|
||||
const uint16_t aport = 8266;
|
||||
const uint16_t ota_port = 8266;
|
||||
const char* ota_pass = "1234";
|
||||
|
||||
WiFiServer TelnetServer(aport);
|
||||
WiFiClient Telnet;
|
||||
WiFiUDP OTA;
|
||||
WiFiServer MonitorServer(ota_port);
|
||||
WiFiClient Monitor;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("");
|
||||
Serial.println("Arduino OTA Test");
|
||||
Serial.println("Bare Minimum Arduino OTA");
|
||||
|
||||
Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
|
||||
Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
|
||||
@ -22,45 +22,52 @@ void setup() {
|
||||
WiFi.begin(ssid, pass);
|
||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||
MDNS.begin(host);
|
||||
MDNS.addService("arduino", "tcp", aport);
|
||||
OTA.begin(aport);
|
||||
TelnetServer.begin();
|
||||
TelnetServer.setNoDelay(true);
|
||||
MDNS.enableArduino(ota_port, true);
|
||||
OTA.begin(ota_port);
|
||||
MonitorServer.begin();
|
||||
MonitorServer.setNoDelay(true);
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
} else {
|
||||
Serial.println("WiFi Connect Failed");
|
||||
delay(10000);
|
||||
ESP.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//OTA Sketch
|
||||
if (OTA.parsePacket()) {
|
||||
IPAddress remote = OTA.remoteIP();
|
||||
String pass = OTA.readStringUntil(' ');
|
||||
int cmd = OTA.parseInt();
|
||||
int port = OTA.parseInt();
|
||||
int size = OTA.parseInt();
|
||||
|
||||
if(!pass.equals(String(ota_pass))){
|
||||
Serial.println("ERROR: Wrong Password");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Update Start: ip:");
|
||||
Serial.print(remote);
|
||||
Serial.printf(", port:%d, size:%d\n", port, size);
|
||||
uint32_t startTime = millis();
|
||||
|
||||
WiFiUDP::stopAll();
|
||||
|
||||
if(!Update.begin(size)){
|
||||
Serial.println("Update Begin Error");
|
||||
Update.printError(Serial);
|
||||
return;
|
||||
}
|
||||
|
||||
WiFiUDP::stopAll();
|
||||
WiFiClient::stopAll();
|
||||
|
||||
WiFiClient client;
|
||||
if (client.connect(remote, port)) {
|
||||
|
||||
uint32_t written;
|
||||
while(!Update.isFinished()){
|
||||
written = Update.write(client);
|
||||
if(written > 0) client.print(written, DEC);
|
||||
}
|
||||
Serial.setDebugOutput(false);
|
||||
|
||||
if(Update.end()){
|
||||
client.println("OK");
|
||||
Serial.printf("Update Success: %u\nRebooting...\n", millis() - startTime);
|
||||
@ -74,28 +81,27 @@ void loop() {
|
||||
}
|
||||
}
|
||||
//IDE Monitor (connected to Serial)
|
||||
if (TelnetServer.hasClient()){
|
||||
if (!Telnet || !Telnet.connected()){
|
||||
if(Telnet) Telnet.stop();
|
||||
Telnet = TelnetServer.available();
|
||||
if (MonitorServer.hasClient()){
|
||||
if (!Monitor || !Monitor.connected()){
|
||||
if(Monitor) Monitor.stop();
|
||||
Monitor = MonitorServer.available();
|
||||
} else {
|
||||
WiFiClient toKill = TelnetServer.available();
|
||||
toKill.stop();
|
||||
MonitorServer.available().stop();
|
||||
}
|
||||
}
|
||||
if (Telnet && Telnet.connected() && Telnet.available()){
|
||||
while(Telnet.available())
|
||||
Serial.write(Telnet.read());
|
||||
if (Monitor && Monitor.connected() && Monitor.available()){
|
||||
while(Monitor.available())
|
||||
Serial.write(Monitor.read());
|
||||
}
|
||||
if(Serial.available()){
|
||||
size_t len = Serial.available();
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len);
|
||||
Serial.readBytes(sbuf, len);
|
||||
if (Telnet && Telnet.connected()){
|
||||
Telnet.write((uint8_t *)sbuf, len);
|
||||
yield();
|
||||
if (Monitor && Monitor.connected()){
|
||||
Monitor.write((uint8_t *)sbuf, len);
|
||||
delay(0);
|
||||
}
|
||||
free(sbuf);
|
||||
}
|
||||
delay(1);
|
||||
delay(0);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
||||
sent = sock2.sendto(message, remote_address)
|
||||
sock2.close()
|
||||
|
||||
logging.info('Waiting for device...\n')
|
||||
logging.info('Waiting for device...')
|
||||
try:
|
||||
sock.settimeout(10)
|
||||
connection, client_address = sock.accept()
|
||||
@ -78,13 +78,15 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
||||
connection.sendall(chunk)
|
||||
res = connection.recv(4)
|
||||
except:
|
||||
logging.error('\nError Uploading')
|
||||
sys.stderr.write('\n')
|
||||
logging.error('Error Uploading')
|
||||
connection.close()
|
||||
f.close()
|
||||
sock.close()
|
||||
return 1
|
||||
|
||||
logging.info('\nWaiting for result...\n')
|
||||
sys.stderr.write('\n')
|
||||
logging.info('Waiting for result...')
|
||||
try:
|
||||
connection.settimeout(60)
|
||||
data = connection.recv(32)
|
||||
|
Loading…
x
Reference in New Issue
Block a user