initial upload implementation draft

This commit is contained in:
Siwat Sirichai 2023-12-07 13:40:29 +07:00
parent 0c31060035
commit e2bf2610b3
3 changed files with 41 additions and 17 deletions

View File

@ -546,13 +546,21 @@ void ota_begin()
otaserver.sendHeader("Connection","close");
},[](){
HTTPUpload &upload = otaserver.upload();
size_t file_size = 0;
if(upload.status == UPLOAD_FILE_START) {
Serial.println(upload.totalSize);
for(int i=0;i<otaserver.headers();i++) {
if(!otaserver.headerName(i).compareTo("Content-Length")) {
Serial.printf("Content-Length: %s\n",otaserver.header(i).c_str());
file_size = otaserver.header(i).toInt();
}
}
Serial.println(file_size);
lcd_upload_start(file_size);
} else if (upload.status == UPLOAD_FILE_WRITE) {
for(int i = 0; i<upload.currentSize;i++)
Serial.print(upload.buf[i],HEX);
lcd_upload_write(upload.buf, upload.currentSize);
} else if (upload.status == UPLOAD_FILE_END) {
Serial.println("Upload End");
Serial.println("Upload END.");
}
});
otaserver.begin();

View File

@ -1,6 +1,8 @@
#include <user_code.hpp>
#include <espmega_iot_lcd.hpp>
int lcd_byte_counter = 0;
/**
* @brief Sends stop bit to LCD.
*
@ -70,9 +72,11 @@ bool lcd_upload_start(size_t size)
Serial.print("connect");
lcd_send_stop_bit();
delay(1000);
Serial.print("whmi-wri 1024,115200,res0");
Serial.print("whmi-wri ");
Serial.print(size);
Serial.print(",115200,res0");
lcd_send_stop_bit();
lcd_wait_ack();
return lcd_wait_ack();
}
/**
@ -87,9 +91,15 @@ bool lcd_upload_write(uint8_t *data, size_t size)
for (int i = 0; i < size; i++)
{
Serial.write(data[i]);
lcd_byte_counter++;
if (lcd_byte_counter == 4096)
{
lcd_wait_ack();
lcd_byte_counter = 0;
}
}
return true;
}
/**
* Waits for an acknowledgement signal from the LCD.
* @return true if acknowledgement signal is received, false otherwise.
@ -97,13 +107,16 @@ bool lcd_upload_write(uint8_t *data, size_t size)
bool lcd_wait_ack()
{
bool data_ok = false;
for (int i; i < 50; i++)
for (int i = 0; i < 50; i++)
{
if (Serial.available())
{
if (Serial.read() == 0x05)
{
data_ok = true;
break;
}
}
delay(100);
}
return data_ok;

View File

@ -28,6 +28,9 @@ R"=====(<button type="button" class="conf" onclick="window.location.href='config
data: data,
contentType: false,
processData: false,
headers: {
"Content-Length": data.length
},
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(