From 7f9cf22d0d3e84145898a3ed63e09a0ad1b0a5da Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 19 May 2024 19:35:14 +0300 Subject: [iot/goam] Write image data to SPIFFS file and webserver returns the file --- Year 3/Internet of things/goam/main/main.c | 16 ++++++++++------ Year 3/Internet of things/goam/main/webserver.c | 9 +++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Year 3/Internet of things/goam/main/main.c b/Year 3/Internet of things/goam/main/main.c index ee3e2d4..d3d3ee6 100644 --- a/Year 3/Internet of things/goam/main/main.c +++ b/Year 3/Internet of things/goam/main/main.c @@ -19,6 +19,7 @@ #include "display.h" #include "wifi.h" #include "webserver.h" +#include "spiffs.h" void print_chip_data() { /* Print chip information */ @@ -53,12 +54,13 @@ void take_photo() { ptc06_set_image_resolution(RES_160X120); char* image; size_t length = ptc06_get_image(&image); - for (int i = 0; i < length; i++) { - printf("%d ", image[i]); - if (i % 12 == 0) - printf("\n"); - } - printf("\n"); + spiffs_write("/spiffs/capture.jpeg", image, length); + /* for (int i = 0; i < length; i++) { */ + /* printf("%d ", image[i]); */ + /* if (i % 12 == 0) */ + /* printf("\n"); */ + /* } */ + /* printf("\n"); */ free(image); } @@ -71,6 +73,8 @@ void app_main(void) webserver_init(); wifi_start(); // Automatically starts server too + spiffs_init(); + ptc06_init(); buttons_init(); diff --git a/Year 3/Internet of things/goam/main/webserver.c b/Year 3/Internet of things/goam/main/webserver.c index c4eea5b..9baa5ec 100644 --- a/Year 3/Internet of things/goam/main/webserver.c +++ b/Year 3/Internet of things/goam/main/webserver.c @@ -13,6 +13,7 @@ #include #include "webserver.h" +#include "spiffs.h" static const char *TAG = "webserver"; @@ -70,8 +71,12 @@ static esp_err_t get_handler(httpd_req_t *req) /* Send response with custom headers and body set as the * string passed in user context*/ - const char resp_str[] = "HelloWorld"; - httpd_resp_send(req, resp_str, sizeof(resp_str)); + /* const char resp_str[] = "HelloWorld"; */ + char* resp_str = NULL; + size_t length = spiffs_read("/spiffs/capture.jpeg", &resp_str); + + httpd_resp_send(req, resp_str, length); + free(resp_str); /* After sending the HTTP response the old HTTP request * headers are lost. Check if HTTP request headers can be read now. */ -- cgit v1.3.1-26-gb76a