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