lasselukkari / aWOT

Arduino web server library.
MIT License
292 stars 42 forks source link

Provide ability to update firmware from a remote upload #63

Closed zcmack closed 4 years ago

zcmack commented 4 years ago

Great work -- one feature suggestion is to allow for remote updating, similar to the ESP8266HTTPUpdateServer module. github link

lasselukkari commented 4 years ago

Hi!

I'm trying to keep the library as simple and small as possible so I will not add this functionality to the library itself.

However this is rather straightforward to implement. Maybe it could be provided as an example

The http handler is simple. I'm using this with ESP32.

#include <Update.h>

void update(Request &req, Response &res) {
  int contentLength = req.left();

  if (!Update.begin(contentLength)) {
    return res.sendStatus(500);
  }

  if (Update.writeStream(req) != contentLength) {
    return res.sendStatus(500);
  }

  if (!Update.end()) {
    return res.sendStatus(500);
  }

  if (!Update.isFinished()) {
    return res.sendStatus(500);
  }

  res.sendStatus(204);
}

app.post("/update", &update);

Now you just need to upload the file with a post request. You need something like this in the frontend: https://github.com/lasselukkari/DuinoDCX/blob/master/src/Upload.js#L52-L67

zcmack commented 4 years ago

thanks for the quick feedback. i'll fork and give it a shot.