ESP8266httpUpdate Issue PHP server

Good,

I am using the ESP8266httpUpdate library with the php example to communicate with the server and if the .bin file has a different md5, install the new .bin.

I can't get it to work, in arduino the serial monitor I get:

I get HTTP_UPDATE_FAILD Error (-104): Wrong HTTP Code
13: 04: 55.613 -> CALLBACK: HTTP update fatal error code -104

This is my PHP code:

<?PHP

header('Content-type: text/plain; charset=utf8', true);

function check_header($name, $value = false) {
    if(!isset($_SERVER[$name])) {
        return false;
    }
    if($value && $_SERVER[$name] != $value) {
        return false;
    }
    return true;
}

function sendFile($path) {
    header($_SERVER["SERVER_PROTOCOL"].' 200 OK', true, 200);
    header('Content-Type: application/octet-stream', true);
    header('Content-Disposition: attachment; filename='.basename($path));
    header('Content-Length: '.filesize($path), true);
    header('x-MD5: '.md5_file($path), true);
    readfile($path);
}

if(
    !check_header('HTTP_X_ESP8266_STA_MAC') ||
    !check_header('HTTP_X_ESP8266_AP_MAC') ||
    !check_header('HTTP_X_ESP8266_FREE_SPACE') ||
    !check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
    !check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
    !check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
    !check_header('HTTP_X_ESP8266_SDK_VERSION')
) {
    header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden', true, 403);
    echo "only for ESP8266 updater! (header)\n";
    exit();
}

$localBinary = "/var/www/vhosts/domain.com/httpdocs/folder/arduino.bin";

// Check if version has been set and does not match, if not, check if
// MD5 hash between local binary and ESP8266 binary do not match if not.
// then no update has been found.
if(($_SERVER["HTTP_X_ESP8266_SKETCH_MD5"] != md5_file($localBinary)) {
    sendFile($localBinary)
} else {
    header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified', true, 304);
}

Maybe the problem is in the path of the localBinary .bin file, but I don't know how to solve it.

Thanks a lot

EDIT: acces_log file:

 [`14/Aug/2021:13:16:14 +0200] "GET /folder/arduino_check_updates.php HTTP/1.0" 500 177 "-" "ESP8266-http-Update"`

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.