imgupload performance / Norway dayahead codes

This commit is contained in:
Nic Limper
2024-01-30 11:23:58 +01:00
parent 72c1b7bf40
commit b71844eac0
3 changed files with 61 additions and 18 deletions

View File

@@ -1462,7 +1462,7 @@ bool getDayAheadFeed(String &filename, JsonObject &cfgobj, tagRecord *&taginfo,
getTemplate(loc, 27, taginfo->hwType);
// This is a link to a Google Apps Script script, which fetches (and caches) the tariff from https://transparency.entsoe.eu/
// Please don't use this link in any other projects.
// I made it available to provide easy access to the data, but please don't use this link in any projects other than OpenEpaperLink.
String URL = "https://script.google.com/macros/s/AKfycbwMmeGAaPrWzVZrESSpmPmD--O132PzW_acnBsuEottKNATTqCRn6h8zN0Yts7S56ggsg/exec?country=" + cfgobj["country"].as<String>();
time_t now;

View File

@@ -693,40 +693,77 @@ void init_web() {
server.begin();
}
#define UPLOAD_BUFFER_SIZE 32768
struct UploadInfo {
String filename;
uint8_t buffer[UPLOAD_BUFFER_SIZE];
size_t bufferSize;
};
void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
Serial.println("upload part " + String(index));
String uploadfilename;
if (!index) {
if (config.runStatus != RUNSTATUS_RUN) {
request->send(409, "text/plain", "Come back later");
return;
}
if (request->hasParam("mac", true)) {
uploadfilename = request->getParam("mac", true)->value() + "_" + String(millis()) + ".jpg";
} else {
if (!request->hasParam("mac", true)) {
request->send(400, "text/plain", "parameters incomplete");
return;
}
logLine("http imageUpload " + uploadfilename);
request->_tempObject = (void *)new String(uploadfilename);
uploadfilename = request->getParam("mac", true)->value() + "_" + String(millis()) + ".jpg";
File file = contentFS->open("/temp/" + uploadfilename, "w");
file.close();
Serial.println("upload started " + uploadfilename);
UploadInfo *uploadInfo = new UploadInfo{uploadfilename, {}, 0};
request->_tempObject = (void *)uploadInfo;
}
String *savedFilename = static_cast<String *>(request->_tempObject);
if (savedFilename != nullptr) {
uploadfilename = *savedFilename;
UploadInfo *uploadInfo = static_cast<UploadInfo *>(request->_tempObject);
if (uploadInfo != nullptr) {
uploadfilename = uploadInfo->filename;
if (len) {
xSemaphoreTake(fsMutex, portMAX_DELAY);
File file = contentFS->open("/temp/" + uploadfilename, "a");
if (file) {
file.seek(index);
file.write(data, len);
file.close();
if (uploadInfo->bufferSize + len <= UPLOAD_BUFFER_SIZE) {
memcpy(&uploadInfo->buffer[uploadInfo->bufferSize], data, len);
uploadInfo->bufferSize += len;
} else {
logLine("Failed to open file for appending: " + uploadfilename);
xSemaphoreTake(fsMutex, portMAX_DELAY);
File file = contentFS->open("/temp/" + uploadfilename, "a");
if (file) {
file.write(uploadInfo->buffer, uploadInfo->bufferSize);
file.close();
uploadInfo->bufferSize = 0;
} else {
logLine("Failed to open file for appending: " + uploadfilename);
}
xSemaphoreGive(fsMutex);
memcpy(uploadInfo->buffer, data, len);
uploadInfo->bufferSize = len;
}
xSemaphoreGive(fsMutex);
}
if (final) {
Serial.println("upload final");
if (uploadInfo->bufferSize > 0) {
xSemaphoreTake(fsMutex, portMAX_DELAY);
File file = contentFS->open("/temp/" + uploadfilename, "a");
if (file) {
file.write(uploadInfo->buffer, uploadInfo->bufferSize);
file.close();
} else {
logLine("Failed to open file for appending: " + uploadfilename);
}
xSemaphoreGive(fsMutex);
request->_tempObject = nullptr;
delete uploadInfo;
}
if (request->hasParam("mac", true)) {
String dst = request->getParam("mac", true)->value();
uint8_t mac[8];
@@ -757,6 +794,7 @@ void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index
} else {
taginfo->contentMode = 24;
}
Serial.println("upload finished " + uploadfilename);
taginfo->nextupdate = 0;
wsSendTaginfo(mac, SYNC_USERCFG);
request->send(200, "text/plain", "Ok, saved");

View File

@@ -304,6 +304,11 @@
"LT": "Lithuania",
"LV": "Latvia",
"NL": "Netherlands",
"NO1": "Norway NO1",
"NO2": "Norway NO2",
"NO3": "Norway NO3",
"NO4": "Norway NO4",
"NO5": "Norway NO5",
"PL": "Poland",
"RO": "Romania",
"SI": "Slovenia",