I am working on cutomizing a sketch I downloaded from GitHub and it contains activation of Arduino OTA. This is used from the IDE to upload new firmware as it is compiled. So far so good!
But since it sits there as a service on the ESP-12 I am using, I would like to be able to upload new f/w without having to fire up the IDE and recompiling it every time. I already have the bin file which I like to send to a number of devices easily.
Preferably I would like to access the ESP via the network using a browser suchg as FireFox and do the upload from there.
How can that be done?
Do I have to prepare the firmware with more stuff than what is there for the IDE to be able to upload?
Here is the setup_ota code which is executed from the setup() of the sketch:
// **********************************
// * Setup OTA *
// **********************************
void setup_ota()
{
Serial.println(F("Arduino OTA activated."));
// * Port defaults to 8266
ArduinoOTA.setPort(8266);
// * Set hostname for OTA
ArduinoOTA.setHostname(HOSTNAME);
ArduinoOTA.setPassword(OTA_PASSWORD);
ArduinoOTA.onStart([]()
{
Serial.println(F("Arduino OTA: Start"));
});
ArduinoOTA.onEnd([]()
{
Serial.println(F("Arduino OTA: End (Running reboot)"));
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
{
Serial.printf("Arduino OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error)
{
Serial.printf("Arduino OTA Error[%u]: ", error);
if (error == OTA_AUTH_ERROR)
Serial.println(F("Arduino OTA: Auth Failed"));
else if (error == OTA_BEGIN_ERROR)
Serial.println(F("Arduino OTA: Begin Failed"));
else if (error == OTA_CONNECT_ERROR)
Serial.println(F("Arduino OTA: Connect Failed"));
else if (error == OTA_RECEIVE_ERROR)
Serial.println(F("Arduino OTA: Receive Failed"));
else if (error == OTA_END_ERROR)
Serial.println(F("Arduino OTA: End Failed"));
});
ArduinoOTA.begin();
Serial.println(F("Arduino OTA finished"));
}
And here is how it is called from within the loop():
Obviously the OTA_PASSWORD is known to me in the code...
Is it possible to do or must I dig down and read hundreds of posts from Google to find out? I tried googling for it before coming here and ask, but I could not find the solution...
requires a compiled hex-file.
The hexfile is the code the microcontroller executes.
If you would like to have it without any compiler you can look into interpreted script languages
nodeMCU-Lua or micropython.
I have no experience with Lua /micropython. But the basic principle is:
An always the same interpreter-firmware resides in the microcontroller and the code (= the script) is a simple-texfile which is uploaded into the microcontroller
Thanks, but I think that the file to upload is not a hex file, instead it is a bin file!
Apart from that you are correct!
I have found the documentation for the updateserver but it was a bit dense for me.
So I finally found another howto, which was easier to follow.
And finally as you remarked, the library ESP8266HTTPUpdateServer on disk has deposited a simple example Webupdater, which I used to copy some code for my own sketch.
Here is that example, my own code is full of other stuff too so it is not so readable:
In my case I have set up a different port than 80 and added user/password login, but basically it is using the essentials from the example.
Just tested and it does work as far as I could re-upload the OTA enabled firmwware to the device and it restarted after a while. No feedback except for a bouncing dot on the FireFox tab title. But when it was done there was a confirmation message. And it connected to my MQTT broker just fine.
Is it possible (and if so how) to add one extra button to the page to request a device reset without uploading now firmware?
The screen looks like this now:
Another button that says [Reset Device] is what I need.
It would be good to have once the device has been deployed to the remote location.
just guessing:
as the page with the update buttons comes from the library ESP8266HTTPUpdateServer you will need to modify the library to get an additional button.
One reason more, why I would have done it with the other example
that is not a complete HTML, but most browsers will handle it.
You could extend this line to a full HTML5 and add a "Restart Button" or a Link (href) and execute a ESP.restart().
Do you have experience with the esp8266WebServer?