Skip to content

Commit

Permalink
Debug ESP OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
zipou committed Oct 29, 2018
1 parent f77ba4b commit abcf50c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/OTA/src/OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

int _port;

void OTA::init(int port) {
const char* serverIndex = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";


void IRAM_ATTR OTA::init(int port) {
Serial.println("Init OTA server");
_port = port;
// Serial.println(_port);
Expand All @@ -14,7 +17,7 @@ void OTA::init(int port) {
_WebServer->on("/", HTTP_GET, [&](){
Serial.println('HTTP GET');
_WebServer->sendHeader("Connection", "close");
_WebServer->send(200, "text/html", "HELLO");
_WebServer->send(200, "text/html", "TUTU");
});

_WebServer->on("/update", HTTP_POST, [&](){
Expand All @@ -29,17 +32,20 @@ void OTA::init(int port) {
// WiFiUDP::stopAll();
Serial.printf("Update: %s\n", upload.filename.c_str());
// uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if(!Update.begin(0xFFFFFFFF)){//start with max available size
if(!Update.begin()){
Serial.println("Error after begin");
Update.printError(Serial);
}
} else if(upload.status == UPLOAD_FILE_WRITE){
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize){
// Serial.println("Error after write");
Update.printError(Serial);
}
} else if(upload.status == UPLOAD_FILE_END){
if(Update.end(true)){ //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Serial.println("Error Unknonw");
Update.printError(Serial);
}
Serial.setDebugOutput(false);
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ platform = espressif32
; platform = https://github.com/platformio/platform-espressif32.git#feature/stage
board = node32s
framework = arduino
build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
;lib_extra_dirs = /Users/zipou/Documents/Arduino
upload_speed = 921600
; upload_flags = --auth=myesp8266
Expand Down

0 comments on commit abcf50c

Please sign in to comment.