Skip to content

Commit

Permalink
Add support for OTA mode.
Browse files Browse the repository at this point in the history
Now you can update the ESP32RET firmware over wifi!
  • Loading branch information
collin80 committed Jun 12, 2018
1 parent 75c0300 commit f2ca90b
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions ESP32RET.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <SPI.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "ELM327_Emulator.h"

#include "EEPROM.h"
Expand Down Expand Up @@ -997,7 +1000,7 @@ void loop()
bool isConnected = false;
int serialCnt;
uint8_t in_byte;
boolean needServerInit = false;
boolean needServerInit = false;

if (settings.wifiMode > 0)
{
Expand Down Expand Up @@ -1027,14 +1030,46 @@ void loop()
{
SysSettings.isWifiConnected = true;
wifiServer.begin();
wifiServer.setNoDelay(true);
wifiServer.setNoDelay(true);
}
else
{
Serial.println("Starting UDP Server");
SysSettings.isWifiConnected = true;
//wifiUDPServer.begin(17222);
}
ArduinoOTA.setPort(3232);
ArduinoOTA.setHostname("ESPRET");
// No authentication by default
//ArduinoOTA.setPassword("admin");

ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";

// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});

ArduinoOTA.begin();
}
}
else
Expand Down Expand Up @@ -1238,5 +1273,6 @@ void loop()

Logger::loop();
//elmEmulator.loop();
ArduinoOTA.handle();
}

0 comments on commit f2ca90b

Please sign in to comment.