allow updating screen via web interface
This commit is contained in:
parent
d3de814d75
commit
8986c51d4d
4 changed files with 54 additions and 26 deletions
|
|
@ -24,8 +24,8 @@
|
|||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* Scratch buffer size for sending files to HTTP clients */
|
||||
#define SCRATCH_BUFSIZE 8192
|
||||
// Scratch buffer size for sending files to HTTP clients
|
||||
#define SCRATCH_BUFSIZE 2048
|
||||
|
||||
struct file_server_data {
|
||||
/* Scratch buffer for temporary storage during file transfer */
|
||||
|
|
@ -241,9 +241,7 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// READING STREAM
|
||||
int ret, remaining = req->content_len;
|
||||
|
||||
while (remaining > 0) {
|
||||
/* Read the data for the request */
|
||||
if ((ret = httpd_req_recv(req, buf,
|
||||
|
|
@ -255,8 +253,6 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Send back the same data */
|
||||
httpd_resp_send_chunk(req, buf, ret);
|
||||
remaining -= ret;
|
||||
|
||||
/* Log data received */
|
||||
|
|
@ -265,18 +261,29 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
ESP_LOGI(TAG, "====================================");
|
||||
}
|
||||
|
||||
// TODO: Error handling
|
||||
// Extract script from multipart-encoded POST body
|
||||
// NOTE: This will break as soon as you send more than just the script. Be careful!
|
||||
int first_lf = strcspn(buf, "\n") + 2; // get form boundary length
|
||||
buf[strlen(buf) - first_lf - 2] = 0; // remove form boundary at end
|
||||
memmove(buf, buf + first_lf, strlen(buf) - first_lf + 1);
|
||||
|
||||
// take only part after headers, which is designated by a dual linebreak
|
||||
int header_end = strcspn(buf, "\n\n") + 3;
|
||||
memmove(buf, buf + header_end, strlen(buf) - header_end + 1);
|
||||
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
|
||||
// TODO: Error handling; we could probably even notify about syntax errors?
|
||||
vTaskPrioritySet(NULL, tskIDLE_PRIORITY); // ensure that FreeRTOS task watchdog does not complain
|
||||
run_lua_string(buf, "E-Paper Script via HTTP");
|
||||
heap_caps_free(buf);
|
||||
|
||||
// Done reading
|
||||
char response[100];
|
||||
sprintf(
|
||||
response, "script drawn!"
|
||||
);
|
||||
sprintf(response, "Thanks, I updated my screen!");
|
||||
httpd_resp_set_type(req, "text/plain");
|
||||
httpd_resp_set_status(req, "200");
|
||||
httpd_resp_set_status(req, "301");
|
||||
httpd_resp_set_hdr(req, "Location", "/");
|
||||
httpd_resp_send(req, response, HTTPD_RESP_USE_STRLEN);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue