Tune support for MQTT Settings save/restore

This commit is contained in:
Theo Arends 2021-05-09 11:43:29 +02:00
parent 22b95e64c1
commit c70ad4101f

View File

@ -1417,10 +1417,14 @@ void CmndStateRetain(void) {
}
void CmndFileUpload(void) {
// FileUpload 0 - Abort current upload
// FileUpload {"File":"Config_wemos10_9.4.0.3.dmp","Id":1620385091,"Type":2,"Size":4096,"Md5":"496fcbb433bbca89833063174d2c5747"}
// FileUpload {"Id":1620385091,"Data":"CRJcTQ9fYGF ... OT1BRUlNUVVZXWFk="}
/*
Upload (binary) max 700 bytes chunks of data base64 encoded with MD5 hash over base64 decoded data
FileUpload 0 - Abort current upload
FileUpload {"File":"Config_wemos10_9.4.0.3.dmp","Id":1620385091,"Type":2,"Size":4096}
FileUpload {"Id":1620385091,"Data":"CRJcTQ9fYGF ... OT1BRUlNUVVZXWFk="}
FileUpload {"Id":1620385091,"Data":" ... "}
FileUpload {"Id":1620385091,"Md5":"496fcbb433bbca89833063174d2c5747"}
*/
const char* base64_data = nullptr;
uint32_t rcv_id = 0;
@ -1476,7 +1480,7 @@ void CmndFileUpload(void) {
}
if (Mqtt.file_buffer) {
if (base64_data) {
if ((Mqtt.file_pos < Mqtt.file_size) && base64_data) {
// Save upload into buffer - Handle possible buffer overflows
uint32_t rcvd_bytes = decode_base64_length((unsigned char*)base64_data);
unsigned char decode_output[rcvd_bytes];
@ -1491,7 +1495,7 @@ void CmndFileUpload(void) {
Mqtt.file_pos += read_bytes;
}
if (Mqtt.file_pos < Mqtt.file_size) {
if ((Mqtt.file_pos < Mqtt.file_size) || (Mqtt.file_md5.length() != 32)) {
ResponseCmndChar(PSTR(D_JSON_ACK));
} else {
Mqtt.md5.calculate();
@ -1519,16 +1523,20 @@ void CmndFileUpload(void) {
Mqtt.file_id = 0;
Mqtt.file_size = 0;
Mqtt.file_type = 0;
Mqtt.file_md5 = (const char*) nullptr; // Force deallocation of the String internal memory
}
MqttPublishPrefixTopic_P(STAT, XdrvMailbox.command); // Enforce stat/wemos10/FILEUPLOAD
ResponseClear();
}
void CmndFileDownload(void) {
// Filedownload 0 - Abort current download
// FileDownload 2 - Start download of settings file
// FileDownload - Continue downloading data
/*
Download (binary) max 700 bytes chunks of data base64 encoded with MD5 hash over base64 decoded data
Currently supports Settings (file type 2)
Filedownload 0 - Abort current download
FileDownload 2 - Start download of settings file
FileDownload - Continue downloading data until reception of MD5 hash
*/
if (Mqtt.file_id && Mqtt.file_buffer) {
bool finished = false;