Updating Firmware Over WiFi (OTA)

Updated: Feb 27, 2020

  • Need to save firmware file with bin format at specified folder

  • Load below code and login to laptop with local IP shown on LCD display here 192.168.0.102/firmware

  • Then Login to with following credential

Username: - “admin”

Password: - “admin”



  • Press sign in to enter then following window will appear now choose appropriate bin fin of firmware and click “update firmware”



  • After successful updating browser will show Rebooting Text. now Firmware is successfully updated



Source code As Follows:-


#include <ESP8266WiFi.h>

#include <WiFiManager.h>

#include <ESP8266WebServer.h>

#include <LiquidCrystal_I2C.h>

#include <ESP8266HTTPUpdateServer.h>

#include <ESP8266mDNS.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

int counter_s;

int rstpin =D7;

const char* host = "esp8266-webupdate";

const char* update_path = "/firmware";

const char* update_username = "admin";

const char* update_password = "admin";

ESP8266HTTPUpdateServer httpUpdater;

ESP8266WebServer httpServer(80);


void setup()

{

lcd.begin();

lcd.backlight();

lcd.setCursor(0, 0);

delay(10);

lcd.print("connect AutoconnectAP");

lcd.setCursor(0, 1);

delay(1000);

lcd.print("type-192.168.4.1 in browser");

delay(400);


WiFiManager wifiManager;

wifiManager.setTimeout(10);

wifiManager.autoConnect("AutoConnectAP");

if(WiFi.status() != WL_CONNECTED)

{

lcd.clear();

lcd.print("connect AutoconnectAP");

delay(400);

lcd.setCursor(0, 1);

lcd.print("type-192.168.4.1 in browser");

delay(400);

for(counter_s=0;counter_s<45;counter_s++)

{

lcd.scrollDisplayLeft();

delay(400);

}

}

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("connect ");

delay(400);

lcd.setCursor(0, 0);

lcd.print("AutoconnectAP");

delay(400);

lcd.setCursor(0, 1);

lcd.print("In browser ");

delay(800);

lcd.setCursor(0, 1);

lcd.print("192.168.4.1");

delay(400);

if(!wifiManager.autoConnect("AutoConnectAP"))

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("failed to connect");

delay(3000);

//reset and try again, or maybe put it to deep sleep

ESP.reset();

delay(5000);

}


lcd.clear();

lcd.setCursor(0, 0);

lcd.print("WiFi connected");

delay(400);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("IP address: ");

delay(400);

lcd.setCursor(0, 1);

lcd.print(WiFi.localIP());

delay(400);

MDNS.begin(host);

httpUpdater.setup(&httpServer, update_path, update_username, update_password);

httpServer.begin();

MDNS.addService("http", "tcp", 80);

}



void loop()

{

if(digitalRead(rstpin)==HIGH)

{

WiFi.disconnect();

delay(5000);

}

httpServer.handleClient();

}


  • Circuit Diagram




80 views0 comments

Recent Posts

See All