I have been trying to do the OTA via the Arduino IDE. But after reading all remedies and trying nothing worked. I just have the network port shown but the " No response from Device " error persists. I am using a Wemos LOLIN D1
Then landed on a page which has three different types HERE
The Web updater seems easy and works ... the question is how to invoke this in real time ? Maybe I can have a switch and read it in Setup to decide if the Updater is to run or my Code is to run. But then it means i need to have physical access to the module to update code.
Any other method to do this ... maybe a time delay ? But then the code waits for that time to get going with regular code.
I like the way its implemented in ESP32 ... once the OTA code is flashed it is there ready to be invoked and the regular code execution goes on normally.
I was wanting to know if something similar is possible with ESP8266 also !
The code below works as expected. It also gives an option to Upload File System Right now I dont know whatit is for and hence only uploading the Firmware. All well.
Download the required header files from This Github location
The board used in this code is a LOLIN(WEMOS) D2 R2&mini
/*
08 June 2020
This code is the template for ESP8266 OTA. Using board LOLIN(WEMOS)D1 R2&mini
Any code required to have OTA facility must include the code
as in setup() and loop().
Your PC must be on the same WiFi network as this ESP8266. Open the Sktech menu in the
final code that you want to upload and choose "Export Compiled Binary "
You just have to open a Chrome broswer and type in this : http://esp8266-webupdate.local/update
Now you have to choose the bin file to upload and click update Firmware. You are done.
No progress % update is shown. But in the end you just get a Upload Success message.
Then the ESP8266 takes a while to reboot into the new code .
( It also opens up a FileSystem upload option. No idea what it is for !)
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#ifndef STASSID
#define STASSID "ABCDEFG"
#define STAPSK "123456"
#endif
const char* host = "esp8266-webupdate";
const char* ssid = STASSID;
const char* password = STAPSK;
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup(void) {
Serial.begin(9600);
Serial.println();
Serial.println("Booting Sketch...");
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
WiFi.begin(ssid, password);
Serial.println("WiFi failed, retrying.");
}
MDNS.begin(host);
httpUpdater.setup(&httpServer);
httpServer.begin();
MDNS.addService("http", "tcp", 80);
Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void loop(void) {
httpServer.handleClient();
MDNS.update();
blinkLED(LED_BUILTIN, 1000, 1000);
}
//##########################################
void blinkLED( byte ledPin, int onMillisec, int offMillisec)
{
static long old_ms;
pinMode(ledPin, OUTPUT);
if ( (millis() - old_ms) < offMillisec)
{
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
}
if ( (millis() - old_ms) > offMillisec+onMillisec )
{
digitalWrite(ledPin, LOW);
old_ms = millis();
}
}
//##########################################