internal mutex
This commit is contained in:
parent
fdf32d8503
commit
0b1ca17351
4 changed files with 125 additions and 69 deletions
|
@ -56,19 +56,26 @@ void ESPMegaDisplayOTA::otaUpdateWriteHandler(AsyncWebServerRequest *request, Js
|
|||
// - size: the size of the update in bytes
|
||||
// - data: the data to write
|
||||
|
||||
Serial.println("OTA Update Write Handler Begin");
|
||||
Serial.println("Parsing JSON");
|
||||
//Parse the JSON object
|
||||
JsonObject content = json.as<JsonObject>();
|
||||
// Check if the size and data fields are present
|
||||
if(!content.containsKey("size") || !content.containsKey("data"))
|
||||
request->send(500, "application/json", "{\"status\": \"error\", \"message\": \"The size or data field is missing\"}");
|
||||
return;
|
||||
// // Check if the size and data fields are present
|
||||
// Serial.println("Checking if size and data fields are present");
|
||||
// if(!content.containsKey("size") || !content.containsKey("data"))
|
||||
// Serial.println("Size or data field is missing");
|
||||
// request->send(500, "application/json", "{\"status\": \"error\", \"message\": \"The size or data field is missing\"}");
|
||||
// return;
|
||||
// Serial.println("Size and data fields are present, getting size");
|
||||
// Get the size field
|
||||
size_t size = content["size"].as<size_t>();
|
||||
Serial.printf("Size: %d\n", size);
|
||||
if(size>4096) {
|
||||
// If the size is greater than 4096 bytes, return an error
|
||||
request->send(500, "application/json", "{\"status\": \"error\", \"message\": \"The size of the update is too big\"}");
|
||||
return;
|
||||
}
|
||||
Serial.println("Getting data field");
|
||||
// Get the data field
|
||||
JsonArray data = content["data"].as<JsonArray>();
|
||||
if(this->updateProgress+size>this->updateSize) {
|
||||
|
@ -76,17 +83,21 @@ void ESPMegaDisplayOTA::otaUpdateWriteHandler(AsyncWebServerRequest *request, Js
|
|||
request->send(500, "application/json", "{\"status\": \"error\", \"message\": \"The update chunk is too big\"}");
|
||||
return;
|
||||
}
|
||||
Serial.println("Converting JsonArray to uint8_t*");
|
||||
// Convert JsonArray to uint8_t*
|
||||
uint8_t data_array[4096];
|
||||
for(size_t i=0; i<size; i++) {
|
||||
data_array[i] = data[i].as<uint8_t>();
|
||||
}
|
||||
Serial.println("Writing data to display");
|
||||
// Write the data to the display
|
||||
display->writeUpdate(data_array, size);
|
||||
request->send(200, "application/json", "{\"status\": \"success\"}");
|
||||
}
|
||||
void ESPMegaDisplayOTA::otaUpdateEndHandler(AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
this->webServer->checkAuthentication(request);
|
||||
display->endUpdate();
|
||||
request->send(200, "application/json", "{\"status\": \"success\"}");
|
||||
}
|
||||
|
||||
void ESPMegaDisplayOTA::displayWebPageHandler(AsyncWebServerRequest *request) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue