i'm working on an updateserver for all of my esp8266.
The server (php script) requests for the Firmware Type [ie. i have one build for the arduino 8relay from china] and askes for the versions number.
then the Script will check, if there is an update and will start an update.
But here is the problem:
Before i want to do the OTA Update with ESPhttpUpdate.update(....), i have to update a few datafiles, which are uploaded to the spiffs filesystem. [ie. setup.html, which contains the page on the picture]
Now i do a HTTP Request to the php file and this will send a new header with the files to upload:
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);
}
(Testing on a Browser this works fine, i get a download with the file i need.)
On ESP i get the Filesize aswell, but i won't get it to perform a download.
Could you please give me a hint, how to get a Filestream from the following http request?
if (update) {
HTTPClient httpClient;
log ("Link: " + configDaten.soft_link);
httpClient.begin( configDaten.soft_link );
httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = httpClient.POST("checkUpdate=true&name=" + _soft_name);
String erg = httpClient.getString();
log ("Update Code: " + String(httpCode));
log ("Ergebnis: " + erg);
if( httpCode == 200 ) {
float newVersion = erg.toFloat();
log( "Current firmware version: " + _soft_version);
log( "Available firmware version: " + String(newVersion));
if (newVersion > _soft_serial.toFloat() ) {
log ("Update wird geladen....");
log ("Beginne mit SPIFFS Aktualisierung");
log ("Lade Anzahl SPIFFS FILES");
int httpCode = httpClient.POST("getNumberOfSpiffs=true&name=" + _soft_name + "&version=" + erg);
String numberofspiffs = httpClient.getString();
if (numberofspiffs.substring(0,3) != "ERR") {
int nfsp = numberofspiffs.toInt();
log (String(nfsp) + " gefunden.");
if (nfsp > 0) {
//for (int x=1; x < nfsp; x++) {
for (int x=1; x < 2; x++) {
log ("Beginne mit Download " + String (x) );
int httpCode = httpClient.POST("getSPIFFSFiles=true&name=" + _soft_name + "&id=" + String(x) + "&version=" + erg);
log ("HTTP Code für Download: " + String(httpCode));
log ("Size: " + String(httpClient.getSize()));
// *******************************
// Here i need a hint, what i can do next....
// How can i get a stream to upload to SPIFFS?!
// *******************************
}
} else
log ("SPIFFS Files sind nicht vorhanden!");
} else
log ("Number of Spiffs ERROR: " + numberofspiffs);
} else
log ("Version ist aktuell. Kein Update erforderlich.");
} else
log ("Fehler beim Updateserver: " + httpClient.errorToString(httpCode));
On the web i only find solutions for an upload directly with a form. But this doesn't work. I tried:
server.onFileUpload( [&] () {
log ("On File Upload aufgerufen.");
if(server.uri() != "/setup") return;
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
String filename = upload.filename;
if(!filename.startsWith("/")) filename = "/"+filename;
log("handleFileUpload Name: " + filename);
fsUploadFile = SPIFFS.open(filename, "w");
filename = String();
} else if(upload.status == UPLOAD_FILE_WRITE){
log("handleFileUpload Data: "+ String(upload.currentSize));
if(fsUploadFile)
fsUploadFile.write(upload.buf, upload.currentSize);
} else if(upload.status == UPLOAD_FILE_END){
if(fsUploadFile)
fsUploadFile.close();
log("handleFileUpload Size: " + String(upload.totalSize));
}
} );
But this will not get called from the PHP Script.
Thank you for helping!
If you need more code, just ask. I will send you much more!