hpsaturn / ESPNowCam

ESPNowCam, a straightforward video streamer for popular ESP32Cam models, leveraging the ESPNow protocol. No need for IPs, routers, or credentials—keeping it simple! :D
GNU General Public License v3.0
100 stars 10 forks source link

Many-to-one connection #10

Closed beniroquai closed 6 months ago

beniroquai commented 7 months ago

Hey @hpsaturn, I stumbled upon your project while screening youtube for some ideas regarding mesh-networking multiple ESP (Xiao) cameras. I have the idea that you have exactly what I was looking for! :) I'm developing a 24 camera microscope based on the little xiao devices and tried everything (further reading on reddit:

My gut feeling tells me that the ESP-NOW is a promising zero-installation way of connecting multiple devices (e.g. 4 in one "subnetwork") without configuring much in advance. The idea would be to bundle 4 cameras and let them create a mesh and stream frames (any framerate near 1fps is already great) to a "master". Your youtube video shows the opposite - one camera to multiple screens, hence my question: would your approach also allow many cameras to one display work?

Thanks a lot for making this project open source! :)

hpsaturn commented 7 months ago

mmm, good question 🧐

This library is for general purpose, as it receives pointers to data, such as buffers, strings, images, or any byte-formatted, but when you are using it one-to-many way, we are using broadcasting feature of ESPNow. mmm I think that is possible, your idea, using maybe an ID and one ESP32 or algorithm that handled when each device should be sending, because the receptor should know how to re-build the data. Each camera should have registered the mac-address of the receptor too. Let me check the details..

beniroquai commented 7 months ago

That would be really cool. I have tried a very first prototype (I'm completely new to ESP-NOW) last night REceiver and Sender They connect, send data, but it does not look like a frame ;D

Looking forward to your thoughts! :)

beniroquai commented 7 months ago

Hey @hpsaturn may I kindly ask you if you found a way to make this work? :)

hpsaturn commented 7 months ago

Yes sure, I know how, I think that like I described before is possible. Using IDs. But right now my time is so short, I was only fixing some XIAO camera issues and I was in other project. I hope return again soon to this idea. Meanwhile, do you have working the current samples of this library in your cameras?

hpsaturn commented 7 months ago

The idea is similar to this post: https://randomnerdtutorials.com/esp-now-many-to-one-esp32/

My esp32cam has support for send to specific receiver using the mac address, like is described in the article. Something like this example that I did:

https://github.com/hpsaturn/esp32s3-cam/blob/master/examples/freenove-tank/freenove-tank.cpp#L336-L338

there, each camera could configure the receiver. And also they using an ID in the message. Well, here I use Protos to improve the structs. But is similar. I think that is the way..

beniroquai commented 7 months ago

Thank you so much for your quick reply! I'm working with the Xiao camera (in fact 24 of these 😁) I'm looking for a way to transfer as many frames as possible with a mesh-like structure (I think the ESP-NOW is perfect..). I wanted to start with 4 cameras to one receiver..

If you tell me where I should have a look, I can try more on my own. I'm not really familiar with the ESP-NOW protocol, but I'm happy to learn! :)

beniroquai commented 7 months ago

So theoretically, If I set the same target MAC on all cameras, I should already be able to make a many-to-one network, no?

hpsaturn commented 7 months ago

Yes. Wow, do you have XIAO cameras? nice to know that because I have a very bad issue around it:

https://github.com/limengdu/SeeedStudio-XIAO-ESP32S3-Sense-camera/issues/8

Maybe can you help me testing the basic sample for XIAO Camera? and try to replicate it? or maybe confirm with that, that my camera has problems.. I only have two cameras, the Freenove and this XIAO for testing.

The sample to test is this: https://github.com/hpsaturn/esp32s3-cam/tree/master/examples/xiao-espnow-sender

But is very simple, install PlatformIO core and its CLI and run:

pio run -e xiao-espnow-sender --target upload

and also you need run a receiver sample in other TFT device.

beniroquai commented 7 months ago

Hey @hpsaturn, I uploaded the sample already and get a funky error:

09:19:55.247 > processFrame
09:19:55.437 > processFrame
09:19:55.558 > processFrame
09:19:55.676 > CAM:  8 FPS
09:19:55.677 > processFrame
09:19:55.809 > processFrame
09:19:55.940 > processFrame
09:19:56.074 > processFrame
09:19:56.189 > processFrame
09:19:56.322 > processFrame
09:19:56.471 > processFrame
09:19:56.637 > processFrame
09:19:56.730 > Decoding msg failed: zero tag
09:19:56.766 > CAM:  8 FPS
09:19:56.766 > processFrame
09:19:56.936 > processFrame
09:19:57.076 > processFrame
09:19:57.256 > processFrame
09:19:57.414 > processFrame
09:19:57.551 > processFrame
09:19:57.730 > processFrame
09:19:57.901 > CAM:  7 FPS
09:19:57.902 > processFrame
09:19:58.051 > processFrame
09:19:58.235 > processFrame
09:19:58.415 > processFrame
09:19:58.561 > processFrame
09:19:58.756 > processFrame
09:19:58.894 > processFrame
09:19:59.123 > CAM:  7 FPS
09:19:59.123 > processFrame
09:19:59.310 > processFrame
09:19:59.533 > processFrame
09:19:59.661 > processFrame
09:19:59.759 > processFrame
09:19:59.864 > processFrame
09:19:59.959 > processFrame
09:20:00.060 > processFrame
09:20:00.262 > CAM:  8 FPS
09:20:00.262 > processFrame
09:20:00.351 > processFrame
09:20:00.478 > processFrame
09:20:00.566 > Decoding msg failed: zero tag
09:20:00.594 > processFrame
09:20:00.834 > processFrame
09:20:01.042 > processFrame
09:20:01.226 > processFrame
09:20:01.403 > CAM:  7 FPS
09:20:01.403 > processFrame
09:20:01.559 > processFrame
09:20:01.755 > processFrame
09:20:01.960 > processFrame
09:20:02.119 > processFrame
09:20:02.356 > processFrame
09:20:02.500 > CAM:  6 FPS
09:20:02.500 > processFrame
09:20:02.640 > processFrame
09:20:02.827 > processFrame
09:20:03.014 > processFrame
09:20:03.071 > Decoding msg failed: zero tag
09:20:03.215 > processFrame
09:20:03.428 > processFrame
09:20:03.549 > CAM:  6 FPS
09:20:03.549 > processFrame
09:20:03.706 > processFrame
09:20:03.847 > processFrame
09:20:04.071 > processFrame
09:20:04.253 > processFrame
09:20:04.438 > processFrame
09:20:04.491 > cam_hal: EV-VSYNC-OVF
09:20:04.585 > CAM:  6 FPS
09:20:04.585 > processFrame
09:20:04.844 > processFrame
09:20:05.096 > processFrame
09:20:05.366 > processFrame
09:20:05.630 > CAM:  4 FPS
09:20:05.631 > processFrame
09:20:05.828 > processFrame
09:20:05.926 > processFrame
09:20:06.027 > processFrame
09:20:06.212 > processFrame
09:20:06.358 > processFrame
09:20:06.490 > processFrame
09:20:06.611 > processFrame
09:20:06.767 > CAM:  8 FPS
09:20:06.767 > processFrame
09:20:06.875 > Decoding msg failed: zero tag
09:20:07.039 > processFrame
09:20:07.353 > processFrame
09:20:07.567 > processFrame
09:20:07.870 > CAM:  4 FPS
09:20:07.870 > processFrame
09:20:08.061 > processFrame
09:20:08.237 > processFrame
09:20:08.416 > processFrame
09:20:08.579 > processFrame
09:20:08.804 > processFrame
09:20:08.937 > CAM:  6 FPS
09:20:08.937 > processFrame
09:20:09.110 > processFrame
09:20:09.285 > processFrame
09:20:09.380 > Decoding msg failed: zero tag
09:20:09.546 > processFrame
09:20:09.665 > processFrame
09:20:09.843 > processFrame
09:20:10.001 > CAM:  6 FPS
09:20:10.001 > processFrame
09:20:10.184 > processFrame
09:20:10.347 > processFrame
09:20:10.591 > processFrame
09:20:10.756 > processFrame
09:20:10.987 > processFrame
09:20:11.131 > CAM:  6 FPS
09:20:11.131 > processFrame
09:20:11.288 > processFrame
09:20:11.535 > processFrame
09:20:11.733 > processFrame
09:20:11.808 > cam_hal: EV-VSYNC-OVF
09:20:11.856 > processFrame
09:20:12.041 > processFrame
09:20:12.217 > CAM:  6 FPS
09:20:12.217 > processFrame
09:20:12.432 > processFrame
09:20:12.577 > processFrame
09:20:12.742 > processFrame
09:20:12.961 > processFrame
09:20:13.206 > Decoding msg failed: zero tag
09:20:13.213 > processFrame
09:20:13.406 > CAM:  6 FPS
09:20:13.406 > processFrame
09:20:13.618 > processFrame
09:20:13.839 > processFrame
09:20:14.027 > processFrame
09:20:14.170 > processFrame
09:20:14.289 > processFrame
09:20:14.585 > CAM:  6 FPS
09:20:14.585 > processFrame
09:20:14.774 > processFrame
09:20:14.940 > processFrame
09:20:15.189 > processFrame
09:20:15.394 > processFrame
09:20:15.625 > CAM:  5 FPS
09:20:15.625 > processFrame
09:20:15.717 > Decoding msg failed: zero tag
09:20:15.816 > processFrame
09:20:15.980 > processFrame
09:20:16.262 > processFrame
09:20:16.508 > processFrame
09:20:16.692 > CAM:  5 FPS
09:20:16.692 > processFrame
09:20:16.750 > ESP-ROM:esp32s3-20210327
09:20:16.750 > Build:Mar 27 2021
09:20:16.751 > rst:0x15 (USB_UART_CHIP_RESET),boot:0x3 (DOWNLOAD(USB/UART0))
09:20:16.751 > Saved PC:0x4207b5ce
09:20:16.752 > waiting for download
09:20:16.853 >  � � � � � � � �ESP-ROM:esp32s3-20210327
09:20:38.080 > Build:Mar 27 2021
09:20:38.080 > rst:0x15 (USB_UART_CHIP_RESET),boot:0x3 (DOWNLOAD(USB/UART0))
09:20:38.081 > Saved PC:0x40048ee0
09:20:38.081 > waiting for download
09:20:38.181 >  �� � � � � � � � � � �ESP-ROM:esp32s3-20210327
09:20:56.722 > Build:Mar 27 2021
09:20:56.723 > rst:0x15 (USB_UART_CHIP_RESET),boot:0x3 (DOWNLOAD(USB/UART0))
09:20:56.723 > Saved PC:0x40048de8
09:20:56.723 > waiting for download
09:20:56.823 >  � � � � � � �ESP-ROM:esp32s3-20210327
09:21:15.216 > Build:Mar 27 2021
09:21:15.217 > rst:0x15 (USB_UART_CHIP_RESET),boot:0x3 (DOWNLOAD(USB/UART0))
09:21:15.217 > Saved PC:0x40048de8
09:21:15.217 > waiting for download
09:21:15.319 >  � � � � � � �

Never had that. It goes to download mode by software, how did that happen? I do not press any buttons. You could try testing your camera with our "espressoscope" firmware: https://matchboxscope.github.io/firmware/FLASH.html

(more information: https://matchboxscope.github.io/)

In my case the receiver should "spit out" data via serial to be translated into python in the computer side, but should not be an issue.

I have written down what I'm trying to achieve here: https://www.reddit.com/r/esp32/comments/1943anz/connecting_24_esp32_seeed_xiao_sense_cameras_over/

What I tried:

hpsaturn commented 7 months ago

Very weir this that you mentioned around the it changes to the upload mode. Is crazy. Well, good news, I changed the camera sensor and my XIAO is working very well, without any issue. On the other hand, I did some tests with a old camera without PSRAM [1], and it is working with the library good too. That means that I could have two cameras to test and implement the solution to this issue.

[1] https://github.com/hpsaturn/esp32s3-cam/pull/19

hpsaturn commented 6 months ago

Current proof of concept in this PR #34

beniroquai commented 6 months ago

Great @hpsaturn ! I can confirm (at least first test), that I can send some data from 3 xiaos to one single receiver. It would indeed be great to solve the MAC address issue.. Tracking changes: https://github.com/beniroquai/esp32s3-cam-now/tree/multicam_singlereceiver

hpsaturn commented 6 months ago

Thanks to test it. Please, you should notice that we already have an example to test this feature, the name is multi-camera-one-receiver. Please sync with devel branch, and feels free to report any Issue. Today in the night I'm going to publish more improvements, because I fixed some glitches.

beniroquai commented 6 months ago

Great! Thanks. I'll test - unforutnately my USB Hun broke, I have to find a solution to get multiple cameras on power now ;D

beniroquai commented 6 months ago

Last question: I case I don't have access to the Mac addresses of the camera but only the receiver, would this still work?

On Tue, May 7, 2024, 17:15 hpsaturn @.***> wrote:

Closed #10 https://github.com/hpsaturn/ESPNowCam/issues/10 as completed.

— Reply to this email directly, view it on GitHub https://github.com/hpsaturn/ESPNowCam/issues/10#event-12735481631, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OECYYIO2FLQXOA2U2LZBFAAZAVCNFSM6AAAAABF3TFPU2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSG4ZTKNBYGE3DGMI . You are receiving this because you authored the thread.Message ID: @.***>

hpsaturn commented 6 months ago

Not last question :D, please feels free to do more questions or report more issues. Sorry for close this issue without any comment yesterday. Well, it is necessary, because it is the only way to filter the incoming messages for now, for this reason the method prototype is this:

/**
 * @brief Callback and framebuffer setter filtered by MAC address
 *        Only for multiple sources (N:1)
 * @param fb buffer pointer to receive the whole frame data
 * @param macAddr source device MAC address to filter
 * @param cb frame data callback for this source device
 */
void ESPNowCam::setRecvFilter(uint8_t *fb, const uint8_t *macAddr, RecvCb cb) {
  saveReceiver(macAddr, fb, cb);
}

On the other hand, without configure the cameras without an only MAC target, it generate a lot the noise and glitches.

hpsaturn commented 6 months ago

I forgot say that the last demo is ready in the main README:

Multi camera - Video demo