From d1c857f42832652138f33d77fac06d78fad8fe9d Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 28 Jan 2024 17:56:30 +0100 Subject: [PATCH 1/5] improved examples descriptions --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2b08858..9d3fa81 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,7 @@ Basic tests and examples over ESP32S3 Cameras. ## Examples and Tests ``` - examples - ├── core2-espnow-receiver - │   └── Video receiver via ESPNow - │ (Use with freenove espnow sample) + examples ├── freenove-basic │   └── Basic FPS and JPEG speed tester ├── freenove-espnow @@ -48,9 +45,12 @@ Basic tests and examples over ESP32S3 Cameras. │   └── ESPNow built-in camera transmitter ├── m5cores3-espnow-stats │   └── Basic stats via ESPNowJoystick library [1] - └── m5cores3-espnow-receiver -    └── Video receiver via ESPNow - (Use with freenove espnow sample) + ├─── m5cores3-espnow-receiver + │   └── Video receiver via ESPNow + │ Use with freenove or M5CoreS3 espnow sample + └─── core2-espnow-receiver +     └── Video receiver via ESPNow + Use with freenove or M5CoreS3 espnow sample ``` [1] For receive the stats, configure other ESP32 how is explained here: [ESPNowJoystick Library](https://github.com/hpsaturn/espnow-joystick#readme) From 4d2be967bd841444163c610a264cb3c7ec43809e Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 28 Jan 2024 17:56:47 +0100 Subject: [PATCH 2/5] trying packed and limited encoding options (failing) issue #1 --- examples/core2-espnow-receiver/core2-espnow-receiver.cpp | 2 +- examples/freenove-espnow/freenove-espnow.cpp | 2 +- lib/common/frame.proto | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/core2-espnow-receiver/core2-espnow-receiver.cpp b/examples/core2-espnow-receiver/core2-espnow-receiver.cpp index 354c633..5ab7bd8 100644 --- a/examples/core2-espnow-receiver/core2-espnow-receiver.cpp +++ b/examples/core2-espnow-receiver/core2-espnow-receiver.cpp @@ -37,7 +37,7 @@ bool decodeMessage(uint16_t message_length) { pb_istream_t stream = pb_istream_from_buffer(recv_buffer, message_length); msg.data.funcs.decode = &decode_data; // msg.data.arg = (void*) "array: \"%d\"\r\n"; - bool status = pb_decode(&stream, Frame_fields, &msg); + bool status = pb_decode_delimited(&stream, Frame_fields, &msg); if (!status) { Serial.printf("Decoding msg failed: %s\r\n", PB_GET_ERROR(&stream)); return false; diff --git a/examples/freenove-espnow/freenove-espnow.cpp b/examples/freenove-espnow/freenove-espnow.cpp index ae6cb86..de62cd9 100644 --- a/examples/freenove-espnow/freenove-espnow.cpp +++ b/examples/freenove-espnow/freenove-espnow.cpp @@ -61,7 +61,7 @@ void printFPS(const char *msg) { size_t encodeMsg(Frame msg) { pb_ostream_t stream = pb_ostream_from_buffer(send_buffer, sizeof(send_buffer)); - bool status = pb_encode(&stream, Frame_fields, &msg); + bool status = pb_encode_delimited(&stream, Frame_fields, &msg); size_t message_length = stream.bytes_written; if (!status) { printf("Encoding failed: %s\r\n", PB_GET_ERROR(&stream)); diff --git a/lib/common/frame.proto b/lib/common/frame.proto index 040551c..0629967 100644 --- a/lib/common/frame.proto +++ b/lib/common/frame.proto @@ -4,5 +4,5 @@ import "nanopb.proto"; message Frame { required uint32 lenght = 1 [(nanopb).int_size = IS_16]; - repeated uint32 data = 2 [(nanopb).int_size = IS_8]; + repeated uint32 data = 2 [(nanopb).int_size = IS_8, packed = true]; } From 385171bff928c9c2fff80d3dced2abc36a6ef69e Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 28 Jan 2024 23:50:32 +0100 Subject: [PATCH 3/5] improved example table and descriptions --- README.md | 55 +++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 9d3fa81..bea0a72 100644 --- a/README.md +++ b/README.md @@ -29,52 +29,31 @@ Basic tests and examples over ESP32S3 Cameras. ## Examples and Tests -``` - examples - ├── freenove-basic - │   └── Basic FPS and JPEG speed tester - ├── freenove-espnow - │   └── ESPNow camera transmitter - ├── freenove-espnow-stats - │   └── Basic stats via ESPNowJoystick library [1] - ├── freenove-webcam - │   └── Original Freenove example with improvements - ├── m5cores3-basic - │   └── Basic builtin Camera/Display test - ├── m5cores3-espnow - │   └── ESPNow built-in camera transmitter - ├── m5cores3-espnow-stats - │   └── Basic stats via ESPNowJoystick library [1] - ├─── m5cores3-espnow-receiver - │   └── Video receiver via ESPNow - │ Use with freenove or M5CoreS3 espnow sample - └─── core2-espnow-receiver -     └── Video receiver via ESPNow - Use with freenove or M5CoreS3 espnow sample -``` +| ENV Name | Target | Status | +|:-----------------|:--------------:|:----------:| +| freenove-basic | Basic FPS and JPEG speed tester | STABLE | +| freenove-espnow | ESPNow camera transmitter | INPROGRESS | +| freenove-espnow-stats | Basic stats via ESPNowJoystick [1] | STABLE | +| freenove-webcam | Original Freenove example with improvements | STABLE | +| m5cores3-basic | Basic builtin Camera/Display test | STABLE | +| m5cores3-espnow | ESPNow built-in camera transmitter | INPROGRESS | +| m5cores3-espnow-stats |Basic stats via ESPNowJoystick [1] | STABLE | +| m5cores3-espnow-receiver | Video receiver via ESPNow [2] |INPROGRESS | +| core2-espnow-receiver | Video receiver via ESPNow | INPROGRESS | +|||| + [1] For receive the stats, configure other ESP32 how is explained here: [ESPNowJoystick Library](https://github.com/hpsaturn/espnow-joystick#readme) +[2] Use with freenove or M5CoreS3 espnow sample + ## Usage and Install Please install first [PlatformIO](http://platformio.org/) open source ecosystem for IoT development compatible with **Arduino** IDE and its command line tools (Windows, MacOs and Linux). Also, you may need to install [git](http://git-scm.com/) in your system. -For compile and install each sample, only choose one and run the next command in the root of this project, like that: +For compile and install each sample, only choose one of them envs names in the table, and run the next command in the root of this project, like that: ```bash pio run -e m5cores3-espnow-receiver --target upload ``` - -Valid samples names are: - -```bash -m5cores3-espnow -m5cores3-espnow-receiver -m5cores3-espnow-stats -m5cores3-basic -freenove-espnow -freenove-webcam -freenove-espnow-stats -freenove-basic -core2-espnow-receiver -``` +--- \ No newline at end of file From d7188c22803dd2d1ab76eaca25633aa3c985cb1a Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 29 Jan 2024 00:03:30 +0100 Subject: [PATCH 4/5] added table and troubleshooting section --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bea0a72..ee7af06 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,17 @@ For compile and install each sample, only choose one of them envs names in the t ```bash pio run -e m5cores3-espnow-receiver --target upload ``` ---- \ No newline at end of file + +## TODO + +- [ ] NanoPb possible issue #1 (payload size) +- [ ] Unified ESPNow in an one class for all transmitters and receivers +- [ ] Migration to esp_wifi_80211_tx() to improve Payload + +## Troubleshooting + +The Freenove camera sometimes needs good power cable and also takes some seconds to stabilization, that means, that not worries for initial crashes. + +**This is a proof of concept and some basic tests and examples, don't hope to much** + +--- From 32fbedce1f89bd1d4912f7fed9010e621f2ec4c6 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 29 Jan 2024 00:03:52 +0100 Subject: [PATCH 5/5] some memory improvements on the receivers --- .../core2-espnow-receiver.cpp | 14 ++++++++------ examples/freenove-espnow/freenove-espnow.cpp | 4 ++-- .../m5cores3-espnow-receiver.cpp | 12 +++++++----- examples/m5cores3-espnow/m5cores3-espnow.cpp | 2 +- lib/common/frame.proto | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/core2-espnow-receiver/core2-espnow-receiver.cpp b/examples/core2-espnow-receiver/core2-espnow-receiver.cpp index 5ab7bd8..62e6644 100644 --- a/examples/core2-espnow-receiver/core2-espnow-receiver.cpp +++ b/examples/core2-espnow-receiver/core2-espnow-receiver.cpp @@ -18,6 +18,7 @@ int32_t dw, dh; uint8_t recv_buffer[256]; /// frame buffer uint8_t *fb; +bool is_new_frame = true; Frame msg = Frame_init_zero; @@ -37,7 +38,7 @@ bool decodeMessage(uint16_t message_length) { pb_istream_t stream = pb_istream_from_buffer(recv_buffer, message_length); msg.data.funcs.decode = &decode_data; // msg.data.arg = (void*) "array: \"%d\"\r\n"; - bool status = pb_decode_delimited(&stream, Frame_fields, &msg); + bool status = pb_decode(&stream, Frame_fields, &msg); if (!status) { Serial.printf("Decoding msg failed: %s\r\n", PB_GET_ERROR(&stream)); return false; @@ -65,16 +66,21 @@ void printFB(uint32_t len){ void msgReceiveCb(const uint8_t *macAddr, const uint8_t *data, int dataLen) { int msgLen = min(ESP_NOW_MAX_DATA_LEN, dataLen); + // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT + if (is_new_frame) fb = (uint8_t*) malloc(4000* sizeof( uint8_t ) ) ; memcpy(recv_buffer, data, msgLen); if (decodeMessage(msgLen)) { + is_new_frame = false; // Serial.println(); if (msg.lenght > 0 ) { // printFB(msg.lenght); // Serial.printf("\r\nfb size: %i msg lenght: %i cksum: %u\r\n",fbpos,msg.lenght,cksum); M5.Display.drawJpg(fb, msg.lenght , 0, 0, dw, dh); - // printFPS("ESPNow reception at:"); + free(fb); + is_new_frame = true; fbpos = 0; // cksum = 0; + printFPS("ESPNow reception at:"); } // Serial.printf("chunk len: %d\r\n",msg.lenght); } @@ -127,10 +133,6 @@ void setup() { size_t psram_size = esp_spiram_get_size() / 1048576; Serial.printf("PSRAM size: %dMb\r\n", psram_size); } - - // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT - fb = (uint8_t*) malloc(3500* sizeof( uint8_t ) ) ; - delay(1000); } diff --git a/examples/freenove-espnow/freenove-espnow.cpp b/examples/freenove-espnow/freenove-espnow.cpp index de62cd9..71a4f1d 100644 --- a/examples/freenove-espnow/freenove-espnow.cpp +++ b/examples/freenove-espnow/freenove-espnow.cpp @@ -61,7 +61,7 @@ void printFPS(const char *msg) { size_t encodeMsg(Frame msg) { pb_ostream_t stream = pb_ostream_from_buffer(send_buffer, sizeof(send_buffer)); - bool status = pb_encode_delimited(&stream, Frame_fields, &msg); + bool status = pb_encode(&stream, Frame_fields, &msg); size_t message_length = stream.bytes_written; if (!status) { printf("Encoding failed: %s\r\n", PB_GET_ERROR(&stream)); @@ -162,7 +162,7 @@ void printJPGFrame(){ void processFrame() { if (Camera.get()) { - frame2jpg(Camera.fb, 8, &out_jpg, &out_jpg_len); + frame2jpg(Camera.fb, 9, &out_jpg, &out_jpg_len); // Display.pushImage(0, 0, dw, dh, (uint16_t *)CoreS3.Camera.fb->buf); // printJPGFrame(); // Serial.println(); diff --git a/examples/m5cores3-espnow-receiver/m5cores3-espnow-receiver.cpp b/examples/m5cores3-espnow-receiver/m5cores3-espnow-receiver.cpp index 24abb08..54989b6 100644 --- a/examples/m5cores3-espnow-receiver/m5cores3-espnow-receiver.cpp +++ b/examples/m5cores3-espnow-receiver/m5cores3-espnow-receiver.cpp @@ -17,6 +17,7 @@ int32_t dw, dh; uint8_t recv_buffer[256]; /// frame buffer uint8_t *fb; +bool is_new_frame = true; Frame msg = Frame_init_zero; @@ -64,16 +65,21 @@ void printFB(uint32_t len){ void msgReceiveCb(const uint8_t *macAddr, const uint8_t *data, int dataLen) { int msgLen = min(ESP_NOW_MAX_DATA_LEN, dataLen); + // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT + if (is_new_frame) fb = (uint8_t*) malloc(4000* sizeof( uint8_t ) ) ; memcpy(recv_buffer, data, msgLen); if (decodeMessage(msgLen)) { + is_new_frame = false; // Serial.println(); if (msg.lenght > 0 ) { // printFB(msg.lenght); // Serial.printf("\r\nfb size: %i msg lenght: %i cksum: %u\r\n",fbpos,msg.lenght,cksum); CoreS3.Display.drawJpg(fb, msg.lenght , 0, 0, dw, dh); - // printFPS("ESPNow reception at:"); + free(fb); + is_new_frame = true; fbpos = 0; // cksum = 0; + printFPS("ESPNow reception at:"); } // Serial.printf("chunk len: %d\r\n",msg.lenght); } @@ -130,10 +136,6 @@ void setup() { size_t psram_size = esp_spiram_get_size() / 1048576; Serial.printf("PSRAM size: %dMb\r\n", psram_size); } - - // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT - fb = (uint8_t*) malloc(3500* sizeof( uint8_t ) ) ; - delay(1000); } diff --git a/examples/m5cores3-espnow/m5cores3-espnow.cpp b/examples/m5cores3-espnow/m5cores3-espnow.cpp index 2bc0eb0..ca27c9a 100644 --- a/examples/m5cores3-espnow/m5cores3-espnow.cpp +++ b/examples/m5cores3-espnow/m5cores3-espnow.cpp @@ -169,7 +169,7 @@ void printJPGFrame(){ void processFrame() { if (CoreS3.Camera.get()) { - frame2jpg(CoreS3.Camera.fb, 8, &out_jpg, &out_jpg_len); + frame2jpg(CoreS3.Camera.fb, 6, &out_jpg, &out_jpg_len); CoreS3.Display.drawJpg(out_jpg, out_jpg_len, 0, 0, dw, dh); // printJPGFrame(); // Serial.println(); diff --git a/lib/common/frame.proto b/lib/common/frame.proto index 0629967..46c2721 100644 --- a/lib/common/frame.proto +++ b/lib/common/frame.proto @@ -4,5 +4,5 @@ import "nanopb.proto"; message Frame { required uint32 lenght = 1 [(nanopb).int_size = IS_16]; - repeated uint32 data = 2 [(nanopb).int_size = IS_8, packed = true]; + repeated uint32 data = 2 [(nanopb).int_size = IS_8, (nanopb).max_size = 1]; }