Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit7f9cf22d0d3e84145898a3ed63e09a0ad1b0a5da (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-05-19 19:35:14 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-05-19 19:35:14 +0300
Files2620b3066e7c501754855aa8cd5d58d58700a8ad
uni-projects-7f9cf22d0d3e84145898a3ed63e09a0ad1b0a5da.tar
uni-projects-7f9cf22d0d3e84145898a3ed63e09a0ad1b0a5da.tar.gz
uni-projects-7f9cf22d0d3e84145898a3ed63e09a0ad1b0a5da.zip
Parent05e24f5a44df53a9e36c363012d502f4ed2b9771 (diff)
[iot/goam] Write image data to SPIFFS file and webserver returns the file
2 files changed, 17 insertions, 8 deletions
-rw-r--r--Year 3/Internet of things/goam/main/main.c16
-rw-r--r--Year 3/Internet of things/goam/main/webserver.c9
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 <esp_wifi.h>
#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[] = "<html><head><title>Hello</title></head><body>World</body></html>";
- httpd_resp_send(req, resp_str, sizeof(resp_str));
+ /* const char resp_str[] = "<html><head><title>Hello</title></head><body>World</body></html>"; */
+ 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. */