2017-10-08 18:38:10 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-10-08 18:38:10 +02:00
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-07-28 08:04:44 +02:00
|
|
|
*
|
2017-10-08 18:38:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-01-11 00:15:05 +01:00
|
|
|
#if BOTH(WIFISUPPORT, OTASUPPORT)
|
2017-10-08 18:38:10 +02:00
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <ESPmDNS.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include <ArduinoOTA.h>
|
2019-11-13 05:16:54 +01:00
|
|
|
#include <driver/timer.h>
|
2017-10-08 18:38:10 +02:00
|
|
|
|
|
|
|
void OTA_init() {
|
|
|
|
ArduinoOTA
|
|
|
|
.onStart([]() {
|
|
|
|
timer_pause(TIMER_GROUP_0, TIMER_0);
|
|
|
|
timer_pause(TIMER_GROUP_0, TIMER_1);
|
|
|
|
|
|
|
|
// U_FLASH or U_SPIFFS
|
|
|
|
String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "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);
|
|
|
|
char *str;
|
|
|
|
switch (error) {
|
|
|
|
case OTA_AUTH_ERROR: str = "Auth Failed"; break;
|
|
|
|
case OTA_BEGIN_ERROR: str = "Begin Failed"; break;
|
|
|
|
case OTA_CONNECT_ERROR: str = "Connect Failed"; break;
|
|
|
|
case OTA_RECEIVE_ERROR: str = "Receive Failed"; break;
|
|
|
|
case OTA_END_ERROR: str = "End Failed"; break;
|
|
|
|
}
|
|
|
|
Serial.println(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
ArduinoOTA.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OTA_handle() {
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
}
|
|
|
|
|
2020-01-11 00:15:05 +01:00
|
|
|
#endif // WIFISUPPORT && OTASUPPORT
|
2017-10-08 18:38:10 +02:00
|
|
|
#endif // ARDUINO_ARCH_ESP32
|