Home

Simple Arduino ESP8266 OTA from server

The following sketch is fully based on the ESP8266httpUpdate.h library and allow to update the firmware
from the http server. It is minimized, it lacks a lot of requirements, but it is functional. For more information,
visit https://arduino-esp8266.readthedocs.io/en/2.4.0/ota_updates/readme.html too.
#include <ESP8266httpUpdate.h>
const char* ssid =     "YourSSID";     // Set your router SSID
const char* password = "YourPassword"; // Set your router password
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  /*connection to WiFi*/
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }
  /* warning - the update is done after each reboot now */
  t_httpUpdate_return ret = ESPhttpUpdate.update("http://server/file.bin"); //Location of your binary file
  //t_httpUpdate_return  ret = ESPhttpUpdate.update("https://server/file.bin");
  /*upload information only */
  switch (ret) {
    case HTTP_UPDATE_FAILED:
      Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
      break;
    case HTTP_UPDATE_NO_UPDATES:
      Serial.println("HTTP_UPDATE_NO_UPDATES");
      break;
    case HTTP_UPDATE_OK:
      Serial.println("HTTP_UPDATE_OK");
      break;
  }
}
void loop() {
// ...
}

Forum

Feb / 2018

UP