Skip to content

Commit

Permalink
Merge pull request #6 from hpsaturn/sender_callback
Browse files Browse the repository at this point in the history
v0.1.2 Sender callback improv. !Now 9FPS with 24 of JPG quality!
  • Loading branch information
hpsaturn authored Jan 31, 2024
2 parents 1b585a8 + 66f8213 commit d18eb98
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ For `Arduino IDE` is a little bit more complicated because the Arduino IDE depen

## ESPNow Transmitter and Receiver

The last version has many improvements, and right now is stable. It needs some tiny changes but now it supports ~9FPS with JPG Quality 12.
The last version has many improvements, and right now is very stable. It needs some tiny changes but now it supports ~9FPS with JPG Quality 18.

![ESPNow Camera Video](https://raw.githubusercontent.com/hpsaturn/esp32s3-cam/master/pictures/espnow_video.gif)

Expand Down
4 changes: 3 additions & 1 deletion examples/freenove-basic-sender/freenove-basic-sender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ void setup() {
size_t psram_size = esp_spiram_get_size() / 1048576;
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
}


// uint8_t macRecv[6] = {0xB8,0xFF,0x09,0xC6,0x0E,0xCC};
// radio.setTarget(macRecv);
radio.init();

if (!Camera.begin()) {
Expand Down
2 changes: 1 addition & 1 deletion examples/freenove-hvga-sender/freenove-hvga-sender.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam Freenove ESPNow Transmitter
* ESPNowCam Freenove Transmitter
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand Down
2 changes: 1 addition & 1 deletion examples/m5core2-basic-receiver/m5core2-basic-receiver.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam video ESPNow Receiver
* ESPNowCam video Receiver
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand Down
3 changes: 2 additions & 1 deletion examples/m5core2-espnow-receiver/m5core2-espnow-receiver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam video ESPNow Receiver
* ESPNowCam video Receiver
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand All @@ -19,6 +19,7 @@ int32_t dw, dh;

void onDataReady(uint32_t lenght) {
M5.Display.drawJpg(fb, lenght , 0, 0, dw, dh);
printFPS("M5Core2:");
}

void setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam video ESPNow Receiver
* ESPNowCam video Receiver
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand Down
24 changes: 20 additions & 4 deletions examples/m5cores3-espnow-sender/m5cores3-espnow-sender.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam ESPNow Transmitter
* ESPNowCam video Transmitter
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand All @@ -13,14 +13,30 @@
ESPNowCam radio;
int32_t dw, dh;

static void drawFPS() {
static uint_least64_t timeStamp = 0;
frame++;
if (millis() - timeStamp > 1000) {
timeStamp = millis();
char bf [10];
sprintf(bf,"FPS: %i",frame);
CoreS3.Display.clear();
CoreS3.Display.drawString(String(bf), dw / 2, dh / 2);
// Serial.printf("%s %2d FPS\r\n",msg, frame);
frame = 0;
}
}

void processFrame() {
if (CoreS3.Camera.get()) {
uint8_t *out_jpg = NULL;
size_t out_jpg_len = 0;
frame2jpg(CoreS3.Camera.fb, 12, &out_jpg, &out_jpg_len);
CoreS3.Display.drawJpg(out_jpg, out_jpg_len, 0, 0, dw, dh);
frame2jpg(CoreS3.Camera.fb, 18, &out_jpg, &out_jpg_len);
// Serial.printf("JPG len %i\r\n",out_jpg_len);
// CoreS3.Display.drawJpg(out_jpg, out_jpg_len, 0, 0, dw, dh);
radio.sendData(out_jpg, out_jpg_len);
// printFPS("CAM:");
drawFPS();
free(out_jpg);
CoreS3.Camera.free();
}
Expand Down Expand Up @@ -49,7 +65,7 @@ void setup() {
if (!CoreS3.Camera.begin()) {
CoreS3.Display.drawString("Camera Init Fail", dw / 2, dh / 2);
}
CoreS3.Display.drawString("Camera Init Success", dw / 2, dh / 2);
// CoreS3.Display.drawString("Camera Init Success", dw / 2, dh / 2);
CoreS3.Camera.sensor->set_framesize(CoreS3.Camera.sensor, FRAMESIZE_QVGA);

delay(500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************
* ESP32Cam video ESPNow Receiver
* ESPNowCam video Receiver
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspNowCam",
"version": "0.1.1",
"version": "0.1.2",
"homepage":"https://github.com/hpsaturn/esp32s3-cam",
"keywords":
[
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESPNowCam
version=0.1.1
version=0.1.2
author=@hpsaturn
maintainer=Antonio Vanegas <[email protected]>
sentence=ESPNowCam, a straightforward video streamer for popular ESP32Cam models, leveraging the ESPNow protocol. No need for IPs, routers, or credentials—keeping it simple! :D
Expand Down
9 changes: 8 additions & 1 deletion src/ESPNowCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ uint8_t chunk_size = CHUNKSIZE;
uint32_t chunk_pos = 0;
uint8_t *outdata = NULL;
size_t outdata_len = 0;
bool msgReady = false;

bool sendMessage(uint32_t msglen, const uint8_t *mac);
size_t encodeMsg(Frame msg);
Expand All @@ -25,6 +26,10 @@ bool encode_uint8_array(pb_ostream_t *stream, const pb_field_t *field, void *con
return pb_encode_string(stream, (uint8_t *)(outdata + chunk_pos), chunk_size);
}

void msgSentCb(const uint8_t *macAddr, esp_now_send_status_t status) {
msgReady = true;
}

bool ESPNowCam::sendData(uint8_t *data, uint32_t lenght) {
outdata = data;
outdata_len = lenght;
Expand All @@ -40,13 +45,14 @@ bool ESPNowCam::sendData(uint8_t *data, uint32_t lenght) {
msg.lenght = 0;
}
msg.data.funcs.encode = &encode_uint8_array;
msgReady = false;
sendMessage(encodeMsg(msg), this->targetAddress);
while(!msgReady)delayMicroseconds(1);
chunk_pos = outdata_len - chunk_left;
if (msg.lenght == outdata_len) {
chunk_left = 0;
chunk_size = CHUNKSIZE;
}
delay(4);
}
chunk_pos = 0;
return true;
Expand Down Expand Up @@ -160,6 +166,7 @@ bool ESPNowCam::init() {
if (esp_now_init() == ESP_OK) {
Serial.println("ESPNow Init Success");
esp_now_register_recv_cb(msgReceiveCb);
esp_now_register_send_cb(msgSentCb);
return true;
} else {
Serial.println("ESPNow Init Failed");
Expand Down
4 changes: 2 additions & 2 deletions src/ESPNowCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef void (*RecvCb)(uint32_t lenght);

#define CHUNKSIZE 244

#define CSL_VERSION "0.1.1"
#define CSL_REVISION 089
#define CSL_VERSION "0.1.2"
#define CSL_REVISION 057

class ESPNowCam {
private:
Expand Down

0 comments on commit d18eb98

Please sign in to comment.