Skip to content

Commit

Permalink
Merge pull request #2 from hpsaturn/fix1_uint8_nanopb_issue
Browse files Browse the repository at this point in the history
Fix1 uint8 nanopb issue
  • Loading branch information
hpsaturn authored Jan 28, 2024
2 parents 2149430 + 32fbedc commit 1135ca1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 49 deletions.
64 changes: 28 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,44 @@ Basic tests and examples over ESP32S3 Cameras.

## Examples and Tests

```
examples
├── core2-espnow-receiver
│   └── Video receiver via ESPNow
│ (Use with freenove espnow sample)
├── 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 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:
## TODO

```bash
m5cores3-espnow
m5cores3-espnow-receiver
m5cores3-espnow-stats
m5cores3-basic
freenove-espnow
freenove-webcam
freenove-espnow-stats
freenove-basic
core2-espnow-receiver
```
- [ ] 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**

---
12 changes: 7 additions & 5 deletions examples/core2-espnow-receiver/core2-espnow-receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/freenove-espnow/freenove-espnow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions examples/m5cores3-espnow-receiver/m5cores3-espnow-receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/m5cores3-espnow/m5cores3-espnow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/frame.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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, (nanopb).max_size = 1];
}

0 comments on commit 1135ca1

Please sign in to comment.