roleoroleo / yi-hack-Allwinner

Custom firmware for Yi 1080p camera based on Allwinner platform
MIT License
437 stars 66 forks source link

Kami Baby Support #413

Closed osh123 closed 2 months ago

osh123 commented 9 months ago

Continuing the ticket in the roleoroleo/yi-hack-Allwinner-v2 project.

I would like to test a beta version for Kami Baby. Serial number is starting with LFUS, firmware version is 1.3.0.0C. Firmware backup: https://drive.google.com/file/d/1rSXdw0ar4VVb0X1-tJpdtiU8fOVGA9sa/view?usp=sharing Also, this camera has temperature and humidity sensors, any chance I can read them and expose them to Home Assistant integration? The camera also has night vision support, will it also work? will it be possible to control it?

Thanks a lot!

roleoroleo commented 9 months ago

Please, try this new beta firmware: y501gc_0.3.6.tar.gz

Also, this camera has temperature and humidity sensors, any chance I can read them and expose them to Home Assistant integration?

At the moment it's not possible, and without a cam under my hands it's very difficult to develop this feature.

The camera also has night vision support, will it also work? will it be possible to control it?

You can control the enable/disable, but when you enable it the cam will switch on/off automatically.

osh123 commented 9 months ago

Hi,

Thank you for the firmware! I've managed to load it into the camera, but I'm unable to view the rtsp stream or take a snapshot.

osh123 commented 9 months ago

Adding the I was able to see the temperature and humidity value with dmesg:

[  133.684747] ----sht3x temperature(26833), humidity(56146)----
root@yi-d203:~/bin#
osh123 commented 9 months ago

Hi,

I Wrote a small script that fetches the temp data from dmesg and publishes it in MQTT:

#!/bin/sh

YI_HACK_PREFIX="/home/yi-hack"
CAMERA_CONF_FILE="$YI_HACK_PREFIX/etc/camera.conf"
MQTT_CONF_FILE="$YI_HACK_PREFIX/etc/mqttv4.conf"

. $MQTT_CONF_FILE

if [ -z "$MQTT_IP" ]; then
    exit
fi
if [ -z "$MQTT_PORT" ]; then
    exit
fi

if [ ! -z "$MQTT_USER" ]; then
    MQTT_USER="-u $MQTT_USER"
fi

if [ ! -z "$MQTT_PASSWORD" ]; then
    MQTT_PASSWORD="-P $MQTT_PASSWORD"
fi

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$YI_HACK_PREFIX/lib

TEMPERTURE=$(dmesg | tail -n 1 | grep -Eo '[0-9][0-9]+' | sed -n '3,3p')
TEMPERTURE=$(echo "scale=2; $TEMPERTURE/1000"| bc -l)

HUMIDITY=$(dmesg | tail -n 1 | grep -Eo '[0-9][0-9]+' | sed -n '4,4p')
HUMIDITY=$(echo "scale=2; $HUMIDITY/1000"| bc -l)

$YI_HACK_PREFIX/bin/mosquitto_pub -h "$MQTT_IP" -p "$MQTT_PORT" $MQTT_USER $MQTT_PASSWORD -t $MQTT_PREFIX/temperature -m "{\"temperature\": $TEMPERTURE, \"humidity\": $HUMIDITY}" -r

More than that, the camera also has a light that i would really like to control from HA, I've ran ipc_read while toggling the light switch in app, the strange thing is that I'm getting the same message for both on and off, does it make sense to you? If so, I'll try to compile ip_cmd with it and try to run it, can it cause damage to the camera? This is the ipc_read output:

IPC message. Len: 16. Status: No error information!
Parsing message
40 00 00 00 01 00 00 00 ff 00 ff 00 00 00 00 00
@
roleoroleo commented 9 months ago

I Wrote a small script that fetches the temp data from dmesg and publishes it in MQTT:

Ok, I will try to add to the hack.

More than that, the camera also has a light that i would really like to control from HA, I've ran ipc_read while toggling the light switch in app, the strange thing is that I'm getting the same message for both on and off, does it make sense to you?

Probably the message you sniffed is not related to this function but you can try.

If so, I'll try to compile ip_cmd with it and try to run it

It's not necessary, you can load a message from file with ipc_cmd. Save the file in binary mode with: echo -ne '\x40\x00 ....' > /tmp/sd/message.bin

can it cause damage to the camera?

I can't be sure but it's never happened to me. And I have executed many commands...

roleoroleo commented 9 months ago

About the stream, please send me a copy of your buffer /dev/shm/fshare_frame_buf

osh123 commented 9 months ago

About the stream, please send me a copy of your buffer /dev/shm/fshare_frame_buf

https://drive.google.com/file/d/1-K7e7LzqW91J6t0hKw_Dx4UXc3wZGa-z/view?usp=sharing

It's not necessary, you can load a message from file with ipc_cmd. Save the file in binary mode with: echo -ne '\x40\x00 ....' > /tmp/sd/message.bin

That's great! Thanks! I didn't work with that message, but now it will be easier to research.

osh123 commented 9 months ago

Another update: The correct message for light on is: \x01\x00\x00\x00\x08\x00\x00\x00\x22\x40\x01\x00\x01\x00\x00\x00\x01 For light off its: \x01\x00\x00\x00\x08\x00\x00\x00\x22\x40\x01\x00\x01\x00\x00\x00\x00

The light also has an option to control the brightness and it has a physical button as well.
I'll try to compile the code and implement it as a light entity in HA.

Thanks for all the help.

roleoroleo commented 9 months ago

Another update: The correct message for light on is: \x01\x00\x00\x00\x08\x00\x00\x00\x22\x40\x01\x00\x01\x00\x00\x00\x01 For light off its: \x01\x00\x00\x00\x08\x00\x00\x00\x22\x40\x01\x00\x01\x00\x00\x00\x00

The light also has an option to control the brightness and it has a physical button as well. I'll try to compile the code and implement it as a light entity in HA.

Thanks for all the help.

Great! Keep me updated. About the stream, try to overwrite the standard binaries with the content of this archive. It should work, both rtsp and snapshot. kami_stream_prg.tar.gz

osh123 commented 9 months ago

Great! Keep me updated. About the stream, try to overwrite the standard binaries with the content of this archive. It should work, both rtsp and snapshot. kami_stream_prg.tar.gz

Still, doesn't stream either RTSP or snapshot. Running the RTSP (and h264grabber_h) server with -d 3 gives the following error:

root@kami-baby:~/bin# rRTSPServer -m y501gc -r high -d 3
1695465909804: the size of the buffer is 1786224
1695465909805: mapping file fshare_frame_buf, size 1786224, to b6c11000
1695465909806: closing the file fshare_frame_buf
1695465909806: starting capture main loop
1695466018218: warning - -1 frame(s) lost
roleoroleo commented 9 months ago

h264grabber is not needed anymore to run rRTSPServer.

It seems that rRTSPServer is not able to detect the type of stream. Please try low res stream.

osh123 commented 9 months ago

h264grabber is not needed anymore to run rRTSPServer.

It seems that rRTSPServer is not able to detect the type of stream. Please try low res stream.

Same result with the low res stream. It doesn't seem to even listen to 554. Any other logs that could be useful for you?

osh123 commented 9 months ago

https://drive.google.com/file/d/1BDX-IPlz9tgViZYksVgZZOIKqz1OoO2E/view?usp=sharing This is another stream i captured (last one was with nc, maybe it was incorrect?) Any other way you recommend to capture it?

Thanks!

roleoroleo commented 9 months ago

Ok, try this one: kami_stream_prg_2.tar.gz

osh123 commented 9 months ago

Ok, try this one: kami_stream_prg_2.tar.gz

Seems to be working! low res is working smoothly (both stream and snapshot). high res stream is showing a gray screen every 10 secs or so, and high res snapshot is not working. But that's good for me :) Could it be that the high res stream is heavy on the camera resources?

Thank you!

roleoroleo commented 9 months ago

Could it be that the high res stream is heavy on the camera resources?

Maybe but I will check again. High res snapshot should work. Did you enable swap space?

roleoroleo commented 9 months ago

Oh, I found a problem in the ffmpeg compilation flags. Try this: imggrabber.gz

osh123 commented 9 months ago

Oh, I found a problem in the ffmpeg compilation flags. Try this: imggrabber.gz

Worked :) Thank you!

roleoroleo commented 9 months ago

I will add Kami Baby to the next release.

osh123 commented 9 months ago

Can you wait for my light control implementation? 🙃

roleoroleo commented 9 months ago

Yes, no problem. Could you check if temperature and humidity values are available in any ipc message?

osh123 commented 9 months ago

Will do 😃

osh123 commented 9 months ago

Another small issue with the snapshot service: calling snapshot.sh with watermark=no causes the snapshot to fail.

roleoroleo commented 9 months ago

This is strange. Did you try 2 or 3 times? It may happen that the cam is busy and returns error.

osh123 commented 9 months ago

Tried multiple times, didn't work. Also, the high res stream seems very unstable, I'm getting a gray screen every few seconds. VLC is reporting about a lot of lost frames: around 57 frame for 20 seconds of running.

roleoroleo commented 9 months ago

I will release a new versione of RTSP server. If you want, I can share a beta.

But it's a common problem with all cam that use hevc. Maybe a performance issue.

osh123 commented 9 months ago

Sure, I can test it. It will be compatible with my model?

roleoroleo commented 9 months ago

Yes it is. rRTSPServer.gz

osh123 commented 9 months ago

Hi,

Installed the new version, still seeing some hangs. Any logs i can supply to help you understand the problem?

Thanks!

roleoroleo commented 9 months ago

Yes, try to run this version with -d 15. Connect the client and post the output.

osh123 commented 9 months ago

See here: https://drive.google.com/file/d/1gX95aNLal256TpZQGAPFbYJ8GLn5XXRW/view?usp=sharing

roleoroleo commented 9 months ago

Apart from a few lost frames at the beginning there are no errors in the log. All frames are properly processed. Please try:

osh123 commented 9 months ago
roleoroleo commented 8 months ago

I will check the code.

Is low res stream ok?

osh123 commented 8 months ago

Low res stream seems stable.

roleoroleo commented 8 months ago

If you can, please try a test with the camera close to the router. Did you enable swap space?

roleoroleo commented 8 months ago

Please, try this binary: rRTSPServer.gz

osh123 commented 8 months ago

If you can, please try a test with the camera close to the router. Did you enable swap space?

I tried testing it close to the router - still it happens - gray screen. swap space is enabled.

Please, try this binary: rRTSPServer.gz

It seems much more stable, the gray screens are much less frequent.

Thank you

roleoroleo commented 8 months ago

Ok, send me a log of the rtsp server. Stop the watchdog, stop the server and start the server in debug mode:

killall wd_rtsp.sh
killall rRTSPServer
rRTSPServer -m y501gc -r high -a no -p 554 -d 3

Finally, post the output.

osh123 commented 8 months ago

https://drive.google.com/file/d/1Y5CXaQ8jzB_5Ky4cg2dN_XP4Dh5ihNTM/view?usp=sharing

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.