roleoroleo / yi-hack-Allwinner-v2

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

[y623] Unexpected motion recording behaviours on WIFI interruptions #852

Open AndreasBVB opened 2 months ago

AndreasBVB commented 2 months ago

Hi thank you very much for making this project available to us. It has been great with testing so far but I am running into an issue when there is a WIFI interruption.

The camera:

The HA integration:

My unit is Yi Pro 2K Home YFUS 12.0.51 on y623. Kindly suggest.

Configurations: config.zip

AndreasBVB commented 2 months ago

Just wondering: a quick notice/message on WIFI reconnection would be helpful enough because it can be captured by HA and trigger a camera reset through the curl command.

roleoroleo commented 2 months ago

A question: if a new motion is detected, does the cam restore its normal behavior? Or the sensor no longer works.

So the problem is that the motion stop is sent while the wifi is not connected. Correct?

AndreasBVB commented 2 months ago

When there are new motions after WIFI recovery:

I can't tell what the camera is doing when WIFI is disconnected b/c I don't know how to connect to it without WIFI. However when the WIFI is disconnected but not recovered, recording seems to be working according to SD card file storage.

roleoroleo commented 2 months ago

Please, check with a different mqtt clien (e.g. MQTT Explorer) if a new message is sent to the broker when a motion is detected.

AndreasBVB commented 2 months ago

I can confirm the MQTT messages are normal after WIFI recovery, even visible within HA-MQTT integration. However, not the case for camera recording. Screenshot_20240405-104433__01

AndreasBVB commented 2 months ago

Or do you want me to check if HA MQTT messages are fake? They sync up well with my motions so probably not.

roleoroleo commented 2 months ago

I think that the messages in ha are ok. The cam should recover properly after a new motion detection. About recording I don't know how to fix the problem because this feature is handled by yi processes. Could you check if the process mp4record is running?

AndreasBVB commented 2 months ago

The mp4record process is apparently there according to the top command but looks to me like a zombie process after WIFI recovery. The normal CPU consumption is about 2.5%+ depending on recording or not but after WIFI recovery its CPU usage is constantly 0.4% or 0.2%.

Any possibility to reboot the camera after WIFI recovery or send some MQTT signals like last WIFI connect timestamp for HA reboot camera automation?

AndreasBVB commented 2 months ago

Need to correct myself: Under normal conditions mp4record also consumes under 0.5% when not recording, and above 2.5% when recording.

After WIFI recovery mp4record CPU usage is constantly under 0.5% regardless of the motion sensor status, so probably still alive but not triggered.

roleoroleo commented 2 months ago

This is weird. If mqtt messages are sent, the system (rmm process) detects the motion and send the ipc messages. But mp4record don't handle this message. You could try (just a try) to restart mp4record after a wifi disconnection.

Any possibility to reboot the camera after WIFI recovery or send some MQTT signals like last WIFI connect timestamp for HA reboot camera automation?

If the problem is mp4record, you can call a web service and restart it. Or you can reboot the cam. There are no mqtt messages for this, at the moment. Just web services.

AndreasBVB commented 2 months ago

So what is the recommended method to restart mp4record?

Also I am looking for the signal of reconnected WIFI hoping for an automatic reset/reboot after the interruption. Manually I can certainly do that but I may not be always checking if recording is working.

roleoroleo commented 2 months ago

So what is the recommended method to restart mp4record?

Check the wiki: https://github.com/roleoroleo/yi-hack-Allwinner-v2/wiki/Web-services-description#service-start-and-stop

AndreasBVB commented 2 months ago

Thanks. After WIFI recovery, when the recording is dead, cgi-bin/service.sh?name=mp4record&action=status shows mp4record is "started".

I tried: cgi-bin/service.sh?name=mp4record&action=stop cgi-bin/service.sh?name=mp4record&action=start

mp4record still shows as "started" but the recording is not restored. I have to reset the camera to bring it back to normal.

roleoroleo commented 2 months ago

I think it's a bug of the yi firmware. You can check it removing temporarily the sdcard and testing the system without the hack.

AndreasBVB commented 2 months ago

2K model deployed to somewhere high up so I just tried with an older 1080p model with the same WIFI recovery interruption:

Factory system/firmware has no problem after WIFI reconnect and motion recording keeps working.

Yi 1080p Home, RFUS, 12.0.35 (upgraded from 9.0.35), y291ga

roleoroleo commented 2 months ago

This could confirm that the problem is related to the yi firmware. When you can access to the cam with the app, check if a yi firmware update is available.

At the momento, you could try to create a script to reboot the cam. Maybe something like:

Little example to schedule with cron:

#!/bin/sh

IP=192.168.0.254

ping -c 1 -w 1 $IP
if [ $? -eq 0 ]; then
    if [ -f /tmp/network_offline ]; then
        reboot
    fi
else
    touch /tmp/network_offline
fi
AndreasBVB commented 2 months ago

Cam survived WIFI disconnect/recovery with factory firmware, but not with hack. Maybe still something with the hack? Firmware is up-to-date in Yi app. I'll create some HA ping logic. Thanks :)

roleoroleo commented 2 months ago

So, please, let me summarize:

Is it correct?

AndreasBVB commented 2 months ago

y291ga the same as y623:

roleoroleo commented 2 months ago

Wow, it's a terrible problem to debug. I will try to understand the reason.

AndreasBVB commented 2 months ago

Thanks a lot for the work 🙏

roleoroleo commented 2 months ago

How do you simulate the wifi disconnection? Is there a method to replicate the problem. I tried to disconnect the cam from the router web page. After 10 seconds the cam reconnected but the motion continues to work. Any suggestion?

AndreasBVB commented 2 months ago

I simply rebooted my router from router management. That's my most common situation for WIFI interruption. Additionally my router assigns static IP to cams according to the MAC address. Could this be a problem?