Understanding NODEMCU/8266 OTA

I have an application running on a NODEMCU that normally acts as a AP. I would like to be able to do OTA from a laptop or, better yet, a cellphone or tablet, WITHOUT having to run the IDE.

Is there a way to do that?

I assume that, at a minimum, I would have to re-start the NODEMCU in STA mode, so it could connect to an external network and find the "OTA server".

there is ArduinoOTA library to receive the update from IDE upload to network port with espota tool
there is a library with webserver for OTA upload from browser page
there is a httpupdate library to download the binary from some server

if your device connects to SoftAP of the esp, it can do OTA upload to the esp

Will the web-based OTA work with a cell phone or tablet as the "OTA server", or does it require some Arduino-specific service to be running on the "OTA server" device?

read again Juraj answer carefully.

there is a library with webserver for OTA upload from browser page

this means if you connect with your smartphone to the ESP, you can initiate the OTA upload on the nodemcu webserver.

there is a httpupdate library to download the binary from some server

this means that you need to have a server available in the WIFI which was opened by the nodemcu in AP-Mode. You need a server in that wifi where you store the new binary.

If the smartphone is the only additional device in this WIFI, you need a server on your smartphone so the Nodemcu can download the update from this server (on the smartphone).

As alternative you could initiate in AP-Mode (either by a webform or a physical button) a restart in STA-Mode - then let connect the nodemcu to an other wifi - with a server holding the new binary and start the OTA upload, reboot and bring back the Nodemcu to AP-Mode.

More on the web server method: the ElegantOTA library allows you to do an update from any browser, provided that the device the browser is running on has access to the new code's binary file.

How you generate the binary and get it to that device is up to you. For example, you could use the Arduino IDE on your desktop computer to create the binary, then email it to your phone, and then use your phone's browser to upload it.

There's also an Android app called ArduinoDroid that can compile C++ code. Not sure if it gives access to the binary, but if it does, you should be able to do everything on your phone. If you don't mind tiny keys.

OK, so if the "network" is ONLY the NODEMCU and a cell phone, then OTA is not possible? IOW, doing OTA requires a Windows or Linux PC? Or, I'd have to figure out how to port the "server" to run on the cell phone (which I have ZERO interest in even attempting)?

RayLivingston:
Will the web-based OTA work with a cell phone or tablet as the "OTA server", or does it require some Arduino-specific service to be running on the "OTA server" device?

I expect it requires a web server serving the update binary. I never used it.

RayLivingston:
OK, so if the "network" is ONLY the NODEMCU and a cell phone, then OTA is not possible? IOW, doing OTA requires a Windows or Linux PC? Or, I'd have to figure out how to port the "server" to run on the cell phone (which I have ZERO interest in even attempting)?

but with http update server on esp, you can upload from browser.
you can connect a PC to esp SoftAP

DaveEvans:
More on the web server method: the ElegantOTA library allows you to do an update from any browser, provided that the device the browser is running on has access to the new code's binary file.

How you generate the binary and get it to that device is up to you. For example, you could use the Arduino IDE on your desktop computer to create the binary, then email it to your phone, and then use your phone's browser to upload it.

There's also an Android app called ArduinoDroid that can compile C++ code. Not sure if it gives access to the binary, but if it does, you should be able to do everything on your phone. If you don't mind tiny keys.

That sounds promising. I have no problem creating the image on the PC, but I want to be able to e-mail it to, ideally, an Android phone or tablet, connect that to the NODEMCU, and do the update.

So ElegantOTA makes that possible WITHOUT loading an app on the Android device? Or does ElegantOTA run as an app or service on the Android device? It's not clear to me how it works....

RayLivingston:
That sounds promising. I have no problem creating the image on the PC, but I want to be able to e-mail it to, ideally, an Android phone or tablet, connect that to the NODEMCU, and do the update.

So ElegantOTA makes that possible WITHOUT loading an app on the Android device? Or does ElegantOTA run as an app or service on the Android device? It's not clear to me how it works....

you upload from web browser. the esp is a server

RayLivingston:
So ElegantOTA makes that possible WITHOUT loading an app on the Android device?

Yes. ElegantOTA is a library that you include in your sketch, along with very minimal code. See the library example.

ElegantOTA is PERFECT! Worked flawlessly on the very first try!

Thank you all!

New question - I need to be able to update the files in the LittleFS FLASH file system on the NODEMCU. Is there a way to do that, or do I need to build that myself?

Hmmmm..... A problem with ElegantOTA - For reasons I cannot fathom, it uses a strange compressed/encoded HTML, and I think other files, along with some widgets that it downloads at runtime from some server on the net. Problem is, my device cannot have Internet access. I would like to just include ALL the necessary files in the FFS, rather than using some of them in compressed form, and downloading the others. But, I don't know how to accomplish that...

I suppose I could just use the file transfer code from ElegantOTA, and put my own UI on it, but I do like the way their UI works.

There is a way to load the UI locally, but I haven't tried to use it that way. Check out the install config options

you can use the bundled ESP8266HTTPUpdateServer

I can't see anything the even hints at the ability to store the entire UI locally. I can't even figure out how the bloody UI works at all. It seems to be built around something called "Vue", which I can't make heads or tails of. Web design is really not my thing. And the "Vue" files are filled with references to external files. I can handle simple things, but this whole UI is way beyond my current knowledge.

I started out using the httpUpdateServer.h and it worked just fine, first go in combination with arduinoOTA.h and ESPwebServer.h Either connecting to the ESP_as_AP or on my network. I never actually tried to use my phone, but i'm quite sure it works, since all it needs is a browser and access to the binary file (i couldn't be bothered to first copy that file to my phone..)

I need to be able to update the files in the LittleFS FLASH file system on the NODEMCU. Is there a way to do that, or do I need to build that myself?

I found a link that explains how to upload files, but it was quite tricky to get it going properly, specifically how to get the browser to show a page after upload (i had to use a re-direct which i had not done before) and i only upload 1 file at a time. I would include the link, but i think it might be better if i just include the modified code upon request.

Maybe I'm not understanding properly, but it appears to me using httpUpdateServer REQUIRES a dedicated server running on the device with the browser, and a hard-coded path to the bin file? There is no reasonable way to do that on a some unknown phone.

I would really like to understand how ElegantOTA actually works "under the skin", because it does exactly what I need, at least in terms of transferring the bin file. But the whole UI is so obtuse, I can't make any sense at al out of it, and I am equally mystified as to how the actual file transfer is done. If I could put a new, self-contained UI on ElegantOTA, I could easily put the SPIFFS files in the bin file, and extract them when the new image is moved to the active program FLASH area.

Maybe I’m not understanding properly,

i think so. All it does is create html webpage on the ESP8255webserver where you can select a file (binary) and loads that into the free space in flash just as normal.
I had to check to see if i can actually manage so i can post you an example (i will indulge in the complications of what that means on my system, my main working laptop has a non functioning Bluetooth, but anyway.)

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>

const char* apname = "ThisAp";
const char* appass = "";

ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;

void setup(void) {

  Serial.begin(115200);
  Serial.println();
  Serial.println("Booting Sketch...");
  WiFi.softAP(apname, appass);

  httpUpdater.setup(&httpServer);
  httpServer.on("/", HandleRoot);
  httpServer.begin();

  Serial.println("HTTPUpdateServer ready! Open 192.168.4.1/update in your AP");
}

void loop() {
  httpServer.handleClient();
}

void HandleRoot() {
  String s = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  s += "<html><head><title>AP Updater</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" ></head>";
  s += "<body style=\"color: dimgray; background-color: palegoldenrod; font-size: 12pt; font-family: sans-serif;\">";
  s += "<h1>This is the Root</h1>";
  s += "HTTPUpdateServer ready! Open 192.168.4.1/update in your AP";
  // s += "
This is the new version of the sketch";
  s += "</body></html>";
  httpServer.send(200, "text/html", s);
}

this i uploaded onto an ESP via Serial. It is a modified version of the ESP8266HTTPUpdateServer.h WebUpdater example (but just creates an AP and does not connect to your network)
Then i reset the ESP (or it stays in boot mode)
I then uncommented the line that adds “This is the new version of the sketch”
saved the sketch, and exported the binary, and exported the binary file to my phone.
Then i connected to the AP (ThisAp) on my phone, and typed 192.168.4.1/update and choose file, and hit update.
Good luck ! i got it to work.