Skip to content

Commit 7ba3101

Browse files
authored
Update OTA HTTP Server Header Information (#7633)
The headers sent when an OTA update is requested of an HTTP server have changed in the code. This change is to update the documentation accordingly. PHP sample code was changed but not tested.
1 parent 01cfc54 commit 7ba3101

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

doc/ota_updates/readme.rst

+22-21
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,16 @@ Example header data:
571571

572572
::
573573

574-
[HTTP_USER_AGENT] => ESP8266-http-Update
575-
[HTTP_X_ESP8266_STA_MAC] => 18:FE:AA:AA:AA:AA
576-
[HTTP_X_ESP8266_AP_MAC] => 1A:FE:AA:AA:AA:AA
577-
[HTTP_X_ESP8266_FREE_SPACE] => 671744
578-
[HTTP_X_ESP8266_SKETCH_SIZE] => 373940
579-
[HTTP_X_ESP8266_SKETCH_MD5] => a56f8ef78a0bebd812f62067daf1408a
580-
[HTTP_X_ESP8266_CHIP_SIZE] => 4194304
581-
[HTTP_X_ESP8266_SDK_VERSION] => 1.3.0
582-
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
574+
[User-Agent] => ESP8266-http-Update
575+
[x-ESP8266-STA-MAC] => 18:FE:AA:AA:AA:AA
576+
[x-ESP8266-AP-MAC] => 1A:FE:AA:AA:AA:AA
577+
[x-ESP8266-free-space] => 671744
578+
[x-ESP8266-sketch-size] => 373940
579+
[x-ESP8266-sketch-md5] => a56f8ef78a0bebd812f62067daf1408a
580+
[x-ESP8266-chip-size] => 4194304
581+
[x-ESP8266-sdk-version] => 1.3.0
582+
[x-ESP8266-version] => DOOR-7-g14f53a19
583+
[x-ESP8266-mode] => sketch
583584

584585
With this information the script now can check if an update is needed. It is also possible to deliver different binaries based on the MAC address, as in the following example:
585586

@@ -608,20 +609,20 @@ With this information the script now can check if an update is needed. It is als
608609
readfile($path);
609610
}
610611
611-
if(!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
612+
if(!check_header('User-Agent', 'ESP8266-http-Update')) {
612613
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
613614
echo "only for ESP8266 updater!\n";
614615
exit();
615616
}
616617
617618
if(
618-
!check_header('HTTP_X_ESP8266_STA_MAC') ||
619-
!check_header('HTTP_X_ESP8266_AP_MAC') ||
620-
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
621-
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
622-
!check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
623-
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
624-
!check_header('HTTP_X_ESP8266_SDK_VERSION')
619+
!check_header('x-ESP8266-STA-MAC') ||
620+
!check_header('x-ESP8266-AP-MAC') ||
621+
!check_header('x-ESP8266-free-space') ||
622+
!check_header('x-ESP8266-sketch-size') ||
623+
!check_header('x-ESP8266-sketch-md5') ||
624+
!check_header('x-ESP8266-chip-size') ||
625+
!check_header('x-ESP8266-sdk-version')
625626
) {
626627
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
627628
echo "only for ESP8266 updater! (header)\n";
@@ -633,17 +634,17 @@ With this information the script now can check if an update is needed. It is als
633634
"18:FE:AA:AA:AA:BB" => "TEMP-1.0.0"
634635
);
635636
636-
if(!isset($db[$_SERVER['HTTP_X_ESP8266_STA_MAC']])) {
637+
if(!isset($db[$_SERVER['x-ESP8266-STA-MAC']])) {
637638
header($_SERVER["SERVER_PROTOCOL"].' 500 ESP MAC not configured for updates', true, 500);
638639
}
639640
640-
$localBinary = "./bin/".$db[$_SERVER['HTTP_X_ESP8266_STA_MAC']].".bin";
641+
$localBinary = "./bin/".$db[$_SERVER['x-ESP8266-STA-MAC']].".bin";
641642
642643
// Check if version has been set and does not match, if not, check if
643644
// MD5 hash between local binary and ESP8266 binary do not match if not.
644645
// then no update has been found.
645-
if((!check_header('HTTP_X_ESP8266_SDK_VERSION') && $db[$_SERVER['HTTP_X_ESP8266_STA_MAC']] != $_SERVER['HTTP_X_ESP8266_VERSION'])
646-
|| $_SERVER["HTTP_X_ESP8266_SKETCH_MD5"] != md5_file($localBinary)) {
646+
if((!check_header('x-ESP8266-sdk-version') && $db[$_SERVER['x-ESP8266-STA-MAC']] != $_SERVER['x-ESP8266-version'])
647+
|| $_SERVER["x-ESP8266-sketch-md5"] != md5_file($localBinary)) {
647648
sendFile($localBinary);
648649
} else {
649650
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);

0 commit comments

Comments
 (0)