Welcome to your inkblot. You can use the text field below to enter and send Lua scripts that will change what is displayed on your screen. At the bottom of the screen you can get a short list of functions available for drawing.
-
How to draw
@@ -141,12 +168,6 @@
paper.draw_line(x1, y1, x2, y2, color)
Draw a line from (x1,y1) to (x2,y2) in the given color.
-
paper.draw_hline(x, y, length, color)
-
Draw a horizontal line from (x,y) with the given length in the given color.
-
-
paper.draw_vline(x, y, length, color)
-
Draw a vertical line from (x,y) with the given length in the given color.
-
paper.draw_circle(x, y, radius, color) / paper.fill_circle(x, y, radius, color)
Draw an outline around a circle at (x,y) with the given radius in the given color. fill_circle draws the same circle with a solid filling.
diff --git a/assets/scripts/post_test.lua b/assets/scripts/post_test.lua
index 364eb85..9588269 100644
--- a/assets/scripts/post_test.lua
+++ b/assets/scripts/post_test.lua
@@ -1,5 +1,5 @@
-local math = require('math')
-local paper = require('paper')
+local math = require("math")
+local paper = require("paper")
paper.init()
paper.set_rotation("portrait")
diff --git a/main/inkpot.c b/main/inkpot.c
index 3c70111..00269aa 100644
--- a/main/inkpot.c
+++ b/main/inkpot.c
@@ -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;
}
diff --git a/sdkconfig b/sdkconfig
index 30927da..47e64a2 100644
--- a/sdkconfig
+++ b/sdkconfig
@@ -765,7 +765,7 @@ CONFIG_ESP_HTTP_CLIENT_EVENT_POST_TIMEOUT=2000
#
# HTTP Server
#
-CONFIG_HTTPD_MAX_REQ_HDR_LEN=512
+CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32