ESP 8266 OTA(Over The Air) Update Firmware Demo :

 


My friend Sanket encourage me to do some stuff on ESP8266OTA.
No need of wire to upload Arduino sketch in ESP8266. OTA give you advantage of uploading sketch or upgrade firmware over the WiFi without any wired connection.
*Program uploading is Faster than regular arduino upload.

Requirement:
1) Go through previous tutorials of ESP8266on my blog
2) ESP8266

3) python27 installed on System from where your going to upload firmware.\

Step 1:
Download The library and tools required for OTA click here

Step 2:
Extract downloaded file and install arduino OTA library in Arduino IDE.

Step 3:
 Complile and Upload following sketch in ESP by our regular method through serial terminal. Its necessary to upload first time sketch with OTA suppot.
 #include < esp8266wifi.h >
#include < esp8266mdns .h >
#include < wifiudp .h >
#include < arduinoota .h >

const char* ssid = "WIFI ROUTER NAME";
const char* password = "WIFI ROUTER PASSWORD";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }
  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready v1.0"); //Change version for every new modification in firmaware
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(2,OUTPUT);
}

void loop() {
  ArduinoOTA.handle();
  digitalWrite(2,HIGH);
  delay(500);
  digitalWrite(2,LOW);
  delay(500);
}



Step 4 : 
Now your ESP8266is ready for OTA support.
How to test OTA is working ?
first you need new firm ware file OTA support two types of file i.e 1) .bin, 2 ) SPIFF
Here we are dealing with only .bin file.

modify above sketch withc some changes like
Serial.println("Ready v2.0"); //Change version for every new modification in firmaware
.

void loop() {
  ArduinoOTA.handle();
  digitalWrite(2,HIGH);
  delay(2000);
  digitalWrite(2,LOW);
  delay(2000);
}

here we change version of firmware and make some changes in program. That can be reflect after OTA update.


Now only Verify/Compile program in Arduino IDE do not Upload.

goto run > %temp% in temp folder find out your arduino build folder

Locate build folder
  
Locate .bin file 

 

copy .bin file path which is use in espota tool.

Step 5:
 Now prepare system which can access ESP8266in network.
In download rar file you will find espota.py script that can upload firmware in esp.

Open command prompt in espota.py file location by pressing shift key and right click > open command window here.

give this command
python espota.py -i 10.19.30.40 -p 8266 -f "C:\User\INDIA\AppData\Local\\Temp\builda0eb11f6003a2bd55895c96acd777afe.tmp\BasicOTA.ino.bin" -d -r

firmware upgradation will start

 

You can observe blinking speed of LED get changed.

If you have any questions please comment below.
Thank You.

Comments

  1. Nice blog Help me in my final year project.

    ReplyDelete
  2. Hello! Great write up but when I run the python command, my console only returns "No answer". I've tried modifying the commands to my local IP but I'm not sure if I'm doing something wrong. Not sure if you'll see this.

    ReplyDelete
  3. re obd simulator v2 ,

    where can i download the .ino file ??

    ReplyDelete

Post a Comment

Popular posts from this blog