-->
Page 4 of 4

Re: ESP updates another ESP using ESP8266HTTPUpdateServer

PostPosted: Wed Sep 13, 2017 7:09 am
by diffstorm
Hi All,

I have succeeded to realize a web server which shares .bin of the ESP, so I can download it successfully.

What I want is to add some headers for consistency like in the PHP script in the link above.

I'm sending the .bin the following way:

Code: Select all      httpServer.setContentLength(ESP.getSketchSize());
      //httpServer.send_P(200, "application/binary", "");
      httpServer.send_P(200, "application/octet-stream", "");

then
in loop several times :
Code: Select all      httpServer.sendContent_P(buffer, length);


I do not know how to send the MD5 of the file for consistency check in the second ESP.

I guess this code does this in PHP language:
Code: Select all                     response.writeHeader(200,
                        {"Content-Type": "application/octet-stream",
                        "Content-Disposition": "attachment;filename="+path.basename(full_path),
                        "Content-Length": ""+fs.statSync(full_path)["size"],
                        "x-MD5":  md5.sync(full_path)}); 

I understand that ESP8266httpUpdate class checks for "x-MD5" header somehow? is that correct?
So I need to send that header in first ESP?
Could you share some example code for it?

I didn't understand all these headers:
Code: Select all   if (!check_header(request, 'USER-AGENT', 'ESP8266-http-Update') ||
      !check_header(request, 'X-ESP8266-STA-MAC') ||
      !check_header(request, 'X-ESP8266-AP-MAC') ||
       !check_header(request, 'X-ESP8266-FREE-SPACE') ||
       !check_header(request, 'X-ESP8266-SKETCH-SIZE') ||
      !check_header(request, 'X-ESP8266-SKETCH-MD5') ||
       !check_header(request, 'X-ESP8266-CHIP-SIZE') ||
       !check_header(request, 'X-ESP8266-SDK-VERSION' ||
      !check_header(request, "X-ESP8266-VERSION"))) {

What they stand for? Can you redirect me to a documentation about this if exists?

Thanks in advance.

Re: ESP updates another ESP using ESP8266HTTPUpdateServer

PostPosted: Wed Sep 13, 2017 1:37 pm
by martinayotte
I don't think it is well documented.
But according to their names, some could be relevant.
I'm pretty sure you don't need to implement all of them, only few according to you needs.
You can even skip all those except the MD5, and it should work.

Re: ESP updates another ESP using ESP8266HTTPUpdateServer

PostPosted: Thu Sep 14, 2017 6:40 am
by diffstorm
Thank you all for your help.

I have succeeded it. Second ESP gets firmware of first ESP successfully.

Code: Select allhttpServer.setContentLength(sketch_size);
httpServer.send_P(200, "application/octet-stream", "");
httpServer.sendHeader("Content-Length", String(sketch_size));
httpServer.sendHeader("x-MD5", sketch_MD5);

for (offset = 0; offset < sketch_size;)
{
     /* read sketch data :: getSketch(buffer, &length); */
     httpServer.sendContent_P(buffer, length);
}

Re: ESP updates another ESP using ESP8266HTTPUpdateServer

PostPosted: Thu Sep 14, 2017 9:05 am
by martinayotte
Good ! Nice work !