httpUpdate.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * httpUpdate.ino
  3. *
  4. * Created on: 27.11.2015
  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. t_httpUpdate_return ret = ESPhttpUpdate.update("http://server/file.bin");
  29. switch(ret) {
  30. case HTTP_UPDATE_FAILED:
  31. USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
  32. break;
  33. case HTTP_UPDATE_NO_UPDATES:
  34. USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
  35. break;
  36. case HTTP_UPDATE_OK:
  37. USE_SERIAL.println("HTTP_UPDATE_OK");
  38. break;
  39. }
  40. }
  41. }