Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By julienrat86
#53075 Hi !
i'm trying to update a new firmware from spiffs by creating a little web server et update esp via ESPhttpUpdate.update("localhost", 80, "/blinkESP.bin");
But it doesn't work ..
There is a way to update new firmware form SD card or spiffs ?
Thanks
julien
User avatar
By martinayotte
#53083 The ESPhttpUpdate example is fetching the new firmware from a remote server and update the flash directly.
Doing an Updater taking the firmware from SPIFFS or SD would be possible, but I don't think there is one around already writen. You would need to write one using Updater base class found in the core.
User avatar
By julienrat86
#53123 Thx Martin for your tip ... so now i'm trying to use "Update.write" to flash new firmware ...
So now i have an another problem, Esp reboot and bug when i want to put file object in a uint8_t buffer...

Here is my code ..
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#include "FS.h"

const char *ssid = "CaptoBox";


ESP8266WebServer server(80); // create server

void setup() {
  Serial.begin(115200);
  Serial.println();
  SPIFFS.begin();
  Dir dir = SPIFFS.openDir("/");
  serveur();
  server.begin();
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);
}

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

void serveur() {
  server.on("/flash", HTTP_GET, []() {
    digitalWrite(BUILTIN_LED, LOW);
    //handleFileRead("/blinkESP.bin");
    Serial.println("mise a jour");
    server.send(200, "text/plain", "Update");

    File file = SPIFFS.open("/blinkESP.bin", "r");
    size_t len = file.size();

    Serial.println(file.size());

    uint8_t *buff;

    file.read(buff, len) ; ////here is my problem

    uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
    if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size
      Update.printError(Serial);
    }
    //   Update.write(buff,len);
    file.close();

  });
}


User avatar
By julienrat86
#53130 So it's done ;-) !
here is the code to flash new firmware from spiffs at boot (eg blinkESP.bin).
Code: Select all#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("/blinkESP.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() {
 
}