Introduction: IoT Over the Air Update (OTA) ESP8266
In This project I am going to explain steps of make ESP8266 ready for OTA update. We use here Arduino IDE for programe ESP8266 first time for giving support of OTA boot loader
Step 1: Install Python on Your System
You need to install python27 on your system in order to program ESP8266 from your system you need to run OTA script. Install python27 on System from where your going to upload firmware.
Step 2: Download and Install Arduino OTA Library
Download The library and tools required for OTA click here
Install "ArduinoOTa.zip" in arduino library.
Step 3: Upload Sketch With OTA Bootloader
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: Create New Bin File for Test Working of OTA
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 used for espota tool.
Step 5: Upgrade Firmware OTA and Verify OTA Is Working
Now prepare system which can access ESP8266 in 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 up-gradation will start
For detail procedure follow this blog zenelectro.blogspot.in