My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ota.cpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifdef ARDUINO_ARCH_ESP32
  20. #include "../../inc/MarlinConfigPre.h"
  21. #if BOTH(WIFISUPPORT, OTASUPPORT)
  22. #include <WiFi.h>
  23. #include <ESPmDNS.h>
  24. #include <WiFiUdp.h>
  25. #include <ArduinoOTA.h>
  26. #include <driver/timer.h>
  27. void OTA_init() {
  28. ArduinoOTA
  29. .onStart([]() {
  30. timer_pause(TIMER_GROUP_0, TIMER_0);
  31. timer_pause(TIMER_GROUP_0, TIMER_1);
  32. // U_FLASH or U_SPIFFS
  33. String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
  34. // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  35. Serial.println("Start updating " + type);
  36. })
  37. .onEnd([]() {
  38. Serial.println("\nEnd");
  39. })
  40. .onProgress([](unsigned int progress, unsigned int total) {
  41. Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  42. })
  43. .onError([](ota_error_t error) {
  44. Serial.printf("Error[%u]: ", error);
  45. char *str;
  46. switch (error) {
  47. case OTA_AUTH_ERROR: str = "Auth Failed"; break;
  48. case OTA_BEGIN_ERROR: str = "Begin Failed"; break;
  49. case OTA_CONNECT_ERROR: str = "Connect Failed"; break;
  50. case OTA_RECEIVE_ERROR: str = "Receive Failed"; break;
  51. case OTA_END_ERROR: str = "End Failed"; break;
  52. }
  53. Serial.println(str);
  54. });
  55. ArduinoOTA.begin();
  56. }
  57. void OTA_handle() {
  58. ArduinoOTA.handle();
  59. }
  60. #endif // WIFISUPPORT && OTASUPPORT
  61. #endif // ARDUINO_ARCH_ESP32