I'm searching for a way to flash an ESP8266 programmatically, i.e, without user interaction (and especially without the Arduino IDE).
Assuming I can put the program to be flashed on the SPIFFS filesystem, is there a way to flash the ESP with that file?
-
3yes, but why store it in SPIFFS? see the ESP8266HTTPUpdateServer and ESP8266httpUpdate libraries examplesJuraj– Juraj ♦2020年07月28日 18:55:53 +00:00Commented Jul 28, 2020 at 18:55
-
I said I wanted no user interaction. Besides, I don't want a server in my ESP.larsb– larsb2020年07月29日 16:21:56 +00:00Commented Jul 29, 2020 at 16:21
-
how do you get the file to SPIFFS? the ESP8266httpUpdate library downloads an update bin from a server and updates using the Updater object without storing the bin to SPIFFS.Juraj– Juraj ♦2020年07月29日 16:35:53 +00:00Commented Jul 29, 2020 at 16:35
2 Answers 2
Yes, it is (or at least WAS possible a few years ago) to have an ESP8266 self-program if you can get the file onto the file system, by using the Update
core that is used by OTA and httpUpdate. This was a example program to do it, but I don't know if it still works. I would also suggest that you look at using LittleFS instead of SPIFFS as the latter has been depreciated.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <FS.h>
void setup() {
Serial.begin(115200);
Serial.println();
SPIFFS.begin();
Dir dir = SPIFFS.openDir("/");
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, LOW);
File file = SPIFFS.open("/firmware-update.bin", "r");
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size
Update.printError(Serial);
Serial.println("ERROR");
}
while (file.available()) {
uint8_t ibuffer[128];
file.read((uint8_t *)ibuffer, 128);
Serial.println((char *)ibuffer);
Update.write(ibuffer, sizeof(ibuffer));
}
Serial.print(Update.end(true));
digitalWrite(BUILTIN_LED, HIGH);
file.close();
}
void loop() {
}
-
Perfect! This is exactly what I was looking for. Also thanks for the suggestion of LittleFS, I will consider it.larsb– larsb2020年07月29日 16:22:57 +00:00Commented Jul 29, 2020 at 16:22
Yes, it still works, but now you need to pass data as a pointer:
Update.write(&ibuffer, sizeof(ibuffer));
-
1it is an array so it is a pointer already2024年03月15日 10:13:59 +00:00Commented Mar 15, 2024 at 10:13