大家好,
我正在为我所有的 esp8266 开发一个更新服务器。
服务器(php 脚本)请求固件类型 [即。我有一个来自中国的 arduino 8relay 构建]并询问版本号。
然后脚本将检查是否有更新并开始更新。
但问题是:
在我想使用 ESPhttpUpdate.update(....) 进行 OTA 更新之前,我必须更新一些数据文件,这些数据文件已上传到 spiffs 文件系统。[IE。setup.html,其中包含图片上的页面]
现在我对 php 文件执行 HTTP 请求,这将发送一个包含要上传的文件的新标头:
代码:
全选func
tion 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);
}
在 ESP 上我也得到了文件大小,但我不会让它执行下载。
您能否给我一个提示,如何从以下 http 请求中获取文件流?
代码:
全选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));
在网络上,我只找到直接使用表单上传的解决方案。但这不起作用。我试过:
代码:
全选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));
}
} );
但这不会从 PHP 脚本中调用。
0