Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High Load Issues & Accessing Camera Data Without Node-Red #25

Open
andyg2 opened this issue Feb 1, 2025 · 9 comments
Open

High Load Issues & Accessing Camera Data Without Node-Red #25

andyg2 opened this issue Feb 1, 2025 · 9 comments

Comments

@andyg2
Copy link

andyg2 commented Feb 1, 2025

Issue Summary

Node-Red is struggling to run on my reCamera due to high CPU and memory usage. My system consistently has a high load average:

Mem: 187140K used, 8208K free, 236K shrd, 7248K buff, 79480K cached
CPU:  58% usr  15% sys   0% nic  21% idle   0% io   0% irq   4% sirq
Load average: 6.78 6.77 4.97 2/152 1983
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  167     1 recamera R     174m  91%  48% node-red
  553     1 root     S    34204  17%  18% /usr/local/bin/sscma-node --start

I'm hoping I can deploy a lot of these in the Philippines but hammering the CPU never ends well in this climate.

Since Node-Red is consuming significant system resources, I want to access the camera data directly without running Node-Red.

What I've learned so far

Setting Up MQTT Access
I have configured Mosquitto to allow remote connections:

/etc/mosquitto/mosquitto.conf

listener 1883 0.0.0.0
# for testing only
allow_anonymous true

Exploring Available HTTP Endpoints

I found the following HTTP endpoints, but I'm unsure if they are needed for direct camera access:

  • GET http://{ip}/api/deviceMgr/getModelInfo
  • GET http://{ip}/api/deviceMgr/getModelList
  • GET http://{ip}/api/deviceMgr/getDeviceList
  • GET http://{ip}/api/deviceMgr/queryDeviceInfo
  • GET http://{ip}/api/userMgr/queryUserInfo
  • GET http://{ip}/api/version

Modifying System Startup Scripts

I discovered that /userdata/auto.sh is executed via /etc/init.d/S99user.
This might allow me to customize the startup behavior without bricking the device.

Questions

How does Node-Red communicate with the underlying sscma service?

  • Does it use HTTP, WebSockets, or another protocol?
  • Is there any documentation available for this communication?

Can I start the camera without Node-Red?

  • Is there a way to manually configure /etc/sscma.conf or maybe /etc/avahi/avahi-daemon.conf to achieve this?
  • Is this related to the AT protocol from Seeed Studio? SSCMA AT Protocol
    • If so, this may be too low-level for me but I'm willing to try if it can be used to configure the camera more directly :)

Steps to Achieve My Goal

  • Step 1: Disable Node-Red
  • Step 2: Call an endpoint, or create a /userdata/auto.sh shell script
  • Step 3: Ensure the camera sends data to the local MQTT broker or WebSockets

Any guidance would be greatly appreciated!

@LynnL4
Copy link
Member

LynnL4 commented Feb 1, 2025

Wow, your understanding of Recamera is impressive! First, all the code is publicly available in this repository https://github.com/Seeed-Studio/sscma-example-sg200x, so feel free to explore it further. At the moment, WebSocket is not supported, but it is something we can consider for a future release. Additionally, the protocol documentation will be made available as soon as the Chinese New Year holidays are over. Thanks for your support!

@LynnL4
Copy link
Member

LynnL4 commented Feb 1, 2025

  • Can I start the camera without Node-Red?
    -> you can just remove /etc/init.d/S03node-red

@andyg2
Copy link
Author

andyg2 commented Feb 1, 2025

  • Can I start the camera without Node-Red?
    -> you can just remove /etc/init.d/S03node-red

Thanks, that sounds like a great start. But how can I configure a model - is there a config file for that somewhere?

Can I configure the model via the MQTT broker - maybe with this? How does the control protocol function?

@itssead
Copy link

itssead commented Feb 3, 2025

you maybe also find information at outer sources:
https://github.com/milkv-duo/duo-buildroot-sdk-v2/ or https://github.com/milkv-duo/duo-buildroot-sdk

I think reCamera RTSP streaming (seems only to be enabled with the streaming node red module) seems to be based on a software called live555. If you search the milkv sources (v1) you will find https://github.com/milkv-duo/duo-buildroot-sdk/blob/8e970aa49decfddc6f7f5bd66d0e798ffcf712c4/buildroot-2021.05/package/live555/0001-Add-a-pkg-config-file-for-the-shared-libraries.patch and in the milkv sources (v2) looks more promising https://github.com/search?q=repo%3Amilkv-duo%2Fduo-buildroot-sdk-v2%20rtsp&type=code seems to include native RTSP streaming listener(!) support in cvi lib cvi_rtsp/src/api.cpp

In my opinion live555 might be very outdated, same as buildroot 2021 and I would like to see some major version updates for recamera OS soon. Specially since RISC CPU support in linux components has improved a lot in the last years.

@andyg2
Copy link
Author

andyg2 commented Feb 3, 2025

you maybe also find information at outer sources: https://github.com/milkv-duo/duo-buildroot-sdk-v2/ or https://github.com/milkv-duo/duo-buildroot-sdk

Thanks for the sources I'll check those out. I'm familiar with openRTSP which will allow me to access the camera feed but it involves the overhead of running the RTSP server and also introduces a buffering delay which makes alert snapshots a challenge.

[Assumption 1] From what I've been able to figure out so far, there's a sscma-node server running (/usr/local/bin/sscma-node) which is independent from Node Red. I believe this sscma server functions as the bridge between Node Red and the camera board - as such it should be capable of everything that Node Red can achieve.

[Assumption 2] So if Node Red is disabled, I need to manually communicate with the sscma server to configure the camera/model.

[Assumption 3] I found python-sscma, a Python library to communicate with the sscma server via MQTT. If I can find the correct device ID I should be able to communicate with the camera without the need for Node Red.

sscma.cli client --broker mqtt.broker.com --username username --password xxxxxxxx --device ????????

I monitor the reCamera internal MQTT broker and I can see the AT commands arriving from python-sscma but I think they're landing in the wrong topic. I have tried many device IDs (which affect the topic) e.g. (0, 1, recamera, reCamera, recamera/0, recamera/1, recamera/node, recamera/node/in etc) but all of them result in Waiting for device to be ready.

I feel like I'm really close to achieving communication with the camera from the local network - without the resource hungry Node Red - the camera runs far too hot to touch and frequently lags with Node Red running, and it's fine without it.

@LynnL4
Copy link
Member

LynnL4 commented Feb 5, 2025

I have put the protocol documentation https://github.com/Seeed-Studio/sscma-example-sg200x/blob/main/docs/sscma-node-protocol.md. sscma-node's write a sscma-micro is not the same as the protocol he designed to communicate with node-red. Currently there is no interaction other than node-red. So python-sscma doesn't work.

@andyg2
Copy link
Author

andyg2 commented Feb 5, 2025

Currently there is no interaction other than node-red.

Thank you for updating the docs, that will be useful to many I'm sure.

However I have a camera that frequently resets if the ambient temperature is over 30C and cannot keep pace with the camera frames - after 10 minutes, the MQTT lag is around 10 seconds.

Image

Image

Minimal setup

Image

Is there any way to run inference on the default model without Node Red?
Via any protocol or interface:

  • RTSP with event metadata-
  • WebSockets
  • MQTT
  • HTTP
  • Unix Socket
  • File handle
  • Stream to text file
  • anything at all?

I only need the bounding boxes and label (person), no video or images.

If I can get this working reliably I'll recommend installing these as an alternative to a large estate of Vivotek/OnCam/Hanwha and Ganz AI box devices.

Many thanks fort your help.

@LynnL4
Copy link
Member

LynnL4 commented Feb 5, 2025

Hi,

I’m not sure about your familiarity with C/C++ development. If you're comfortable with it, you can use the following example to develop the program you need. However, if you're not familiar with C/C++, we may need to discuss further to better understand how to adapt it to your specific application. I’ll add this issue to the TODO list for now.

https://github.com/Seeed-Studio/sscma-example-sg200x/tree/main/solutions/sscma-model

https://github.com/Seeed-Studio/sscma-example-sg200x/tree/main/solutions/sscma-at (not ready yet)

@LynnL4 LynnL4 moved this to Todo in Issues and PR Assemble Feb 5, 2025
@LynnL4
Copy link
Member

LynnL4 commented Feb 5, 2025

I am currently working on a Python script to simulate Node-RED via MQTT to retrieve inference results. This might be suitable for your scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants