1

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?

3
  • 3
    yes, but why store it in SPIFFS? see the ESP8266HTTPUpdateServer and ESP8266httpUpdate libraries examples
    – Juraj
    Jul 28, 2020 at 18:55
  • I said I wanted no user interaction. Besides, I don't want a server in my ESP.
    – larsb
    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
    Jul 29, 2020 at 16:35

2 Answers 2

1

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() {     
}
1
  • Perfect! This is exactly what I was looking for. Also thanks for the suggestion of LittleFS, I will consider it.
    – larsb
    Jul 29, 2020 at 16:22
-1

Yes, it still works, but now you need to pass data as a pointer:

Update.write(&ibuffer, sizeof(ibuffer));
1
  • 1
    it is an array so it is a pointer already
    – Juraj
    Mar 15 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.