httpUpdateSPIFFS.ino 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * httpUpdateSPIFFS.ino
  3. *
  4. * Created on: 27.11.2017
  5. *
  6. */
  7. #include <Arduino.h>
  8. #include <WiFi.h>
  9. #include <HTTPClient.h>
  10. #include <ESP32httpUpdate.h>
  11. #define USE_SERIAL Serial
  12. void setup() {
  13. USE_SERIAL.begin(115200);
  14. // USE_SERIAL.setDebugOutput(true);
  15. USE_SERIAL.println();
  16. USE_SERIAL.println();
  17. USE_SERIAL.println();
  18. for(uint8_t t = 4; t > 0; t--) {
  19. USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
  20. USE_SERIAL.flush();
  21. delay(1000);
  22. }
  23. WiFi.begin("SSID", "PASSWORD");
  24. }
  25. void loop() {
  26. // wait for WiFi connection
  27. if((WiFi.status() == WL_CONNECTED)) {
  28. USE_SERIAL.println("Update SPIFFS...");
  29. t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs("http://server/spiffs.bin");
  30. if(ret == HTTP_UPDATE_OK) {
  31. USE_SERIAL.println("Update sketch...");
  32. ret = ESPhttpUpdate.update("http://server/file.bin");
  33. switch(ret) {
  34. case HTTP_UPDATE_FAILED:
  35. USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
  36. break;
  37. case HTTP_UPDATE_NO_UPDATES:
  38. USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
  39. break;
  40. case HTTP_UPDATE_OK:
  41. USE_SERIAL.println("HTTP_UPDATE_OK");
  42. break;
  43. }
  44. }
  45. }
  46. }