samtap / fang-hacks

Collection of modifications for the XiaoFang WiFi Camera
1.67k stars 340 forks source link

Night vision distance #182

Open 4c1d8urn-eh opened 7 years ago

4c1d8urn-eh commented 7 years ago

screenshot_20170706-015212 Hi i have a problem with Night vision. in discription for XiaoFang is 9m but when my camera goes to night vision i don't see anything. My room has 5m width. Do i can regulate IR power in config?

wekii commented 7 years ago

It looks that you have camera with broken IR lights.

4c1d8urn-eh commented 7 years ago

At night IR light its on (I see two IR led that candle ) How do i can check IR it is ok?

06.07.2017 13:08 "wekii" notifications@github.com napisał(a):

It looks that you have camera with broken IR lights.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/samtap/fang-hacks/issues/182#issuecomment-313366348, or mute the thread https://github.com/notifications/unsubscribe-auth/AahFjxMU3PJPtFIx-c2hDLGg-vByFTSRks5sLMAUgaJpZM4OPACx .

wekii commented 7 years ago

Do you hear "click" when camera turns on or off night vision?

4c1d8urn-eh commented 7 years ago

Yes i hear specyfi click when camera goes to night Mode and 2 IR led is then blink img_20170706_145537

wekii commented 7 years ago

Then I don't have any idea what could be a problem. Is this camera hacked?

4c1d8urn-eh commented 7 years ago

Yes it is hacked. I change script from #61 issues and change wireless Mode to wireless client and check at night.

06.07.2017 15:03 "wekii" notifications@github.com napisał(a):

Then I don't have any idea what could be a problem. Is this camera hacked?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/samtap/fang-hacks/issues/182#issuecomment-313389846, or mute the thread https://github.com/notifications/unsubscribe-auth/AahFj7qUMCk3PYSfXpotlTgWyTti0Yehks5sLNszgaJpZM4OPACx .

samtap commented 7 years ago

Based on the first pic, I'd say the IR LEDs are off but the 2nd pic clearly shows they're on... If power supply is lacking LEDs will be not as bright. But maybe you're expecting too much of it, two leds are really not capable to reach 9mtrs (but they should be able to light your room, at least a couple of meters directly in front of the lens)

4c1d8urn-eh commented 7 years ago

I know that 9 meters is the manufacturer's declaration but in the room from camera to the wall I have 3 meters It seemed to me that it would brighten up.

Looking at screenshots of other users, it seems to me that something is wrong.

wekii commented 7 years ago

Did you had the same problem before hacking the camera?

4c1d8urn-eh commented 7 years ago

I don't know beacouse i can run camera outside China

wekii commented 7 years ago

Maybe you meant to say that you can not run camera outside China ? In wich country do you live?

4c1d8urn-eh commented 7 years ago

Yes Yes can not (Write on phone with dictionary) I live in Poland :-)

06.07.2017 16:03 "wekii" notifications@github.com napisał(a):

Maybe you meant to say that you can not run camera outside China ? In wich country do you live?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/samtap/fang-hacks/issues/182#issuecomment-313405566, or mute the thread https://github.com/notifications/unsubscribe-auth/AahFjwmRRk6yweEiw9zpwIRwkvhFaJywks5sLOlMgaJpZM4OPACx .

wekii commented 7 years ago

Maybe you should try to remove hack to see if there's any difference. You can use camera in Poland, but only when you are connected on you local wifi. https://github.com/samtap/fang-hacks/issues/122#issuecomment-309304465

For connection from outside of your LAN you need to have xiaomi router.

UPDATE Today I got Xiaomi Mi Router 3 and I can confirm that you still can NOT connect on XiaoFang camera (unhacked) when mobile phone is on 3G/4G.

louis-lau commented 6 years ago

@samtap There's definitely something going on related to the hacks.

This is a pic (from the rtsp stream) with cloud apps completely disabled:
cam 2 - 2017-08-01 02 32 05

This is a pic (from the rtsp stream) with cloud apps disabled after boot with the stop-cloud script:
cam 2 - 2017-08-01 02 28 02

As you can see with cloud enabled the picture becomes fuzzier, but brighter.

davidjb commented 6 years ago

I'm seeing the same result with my cameras as @louis-lau's results. With the hacks enabled the visible distance is incredible short, unfortunately making the cameras unusable in the dark. Suggestions of things to try would be great; otherwise I'll start poking around in the camera.

BlaY0 commented 6 years ago

I'm still analyzing this camera, I've just got it... My guess is that there are some camera host driver setting exposed through /proc/isp which are changed on iCamera app start. Check if there are any differences in those proc handle files between cloud-on and cloud-off mode.

davidjb commented 6 years ago

I diff'ed all the parts of /proc/isp over the last few days and found that /proc/isp/af/w0-sum notably different. With cloud apps enabled, the value is around 0x450 and cycles between 0x300 and 0x500. However, with cloud apps disabled, this value is steadily increasing over time.

Tonight, it started around 0xf4fa and has moved upwards and occasionally downwards, now being 0x9512 and still going. I wonder if this correlates with the fact that I'm visibly seeing the night vision getting worse the longer the camera is on. With cloud apps disabled, the camera started from cold boot with excellent IR -- the majority of my room was visible, and now at almost 30 mins later, it's almost entirely black. I can see the change slowly happening on the video stream and the AF W0-SUM values keep increasing (eg snx_isp_ctl --afget-sum -?). What does this value represent and is it possible to set or affect that value? snx_isp_ctl only has the ability to get/poll the value.

Otherwise, in the diff, I saw that /proc/isp/iq/nrn changed from 1 (with cloud apps) to 0 (without). Anyone know what /proc/isp/iq and /proc/isp/iq/nrn or /proc/isp/iq/nra are? Changing the settings seems to have little to no discernible difference. Also, /proc/isp/osd/1/{height,width} get adjusted but I doubt that's it; and the same with lots of various parts of /proc/isp/md/* for Motion Detection.

halfluck commented 6 years ago

@davidjb i'm impressed with your progress, it really seems like you might find an answer to this annoying issue.

I've been rebooting my cameras manually every night time, which i believe kicks in iCamera on boot, this works really well for me and the IR mode stays stable and vision is good.

Has anyone tried a simple bandaid hack to fang-ir-control.sh that does a /sbin/reboot on Day Stare Change? this would save me from manually rebooting.

Thanks Rob.

halfluck commented 6 years ago

for anyone that wants a quick fix for now, this is what I am doing

#!/bin/sh

echo "IR Reboot script started"

DAY="$(gpio_aud read 2)"
    if [ $DAY -eq 1 ]
    then 
        echo "Daytime"
        IR_ON=0
    else
        echo "Its Dark"
        IR_ON=1
    fi

while :
do
        DAY="$(gpio_aud read 2)"
        if [ $DAY -eq 1 ]
        then
                if [ $IR_ON -eq 1 ]
                then
                        echo "It was Dark Now Its Daytime so Reboot"
                        /sbin/reboot
#                        IR_ON=0
                fi
        else
                if [ $IR_ON -eq 0 ]
                then
                        echo "It was Daytime Now Its Dark so Reboot"
                        /sbin/reboot
#                        IR_ON=1
                fi
        fi
        sleep 3
done
samtap commented 6 years ago

It's quite silly to reboot and rely on iCamera to setup the hardware. Can't anybody figure out what iCamera does and the ir script doesn't do? Run something like find /proc/isp -type f -print -exec cat {} \; will print all isp settings.

BlaY0 commented 6 years ago

@samtap there are no differences in /proc/isp in both modes, @davidjb already tried that...

There's already a difference in quality if you power-on your camera when there's already dark. If you power it on during the day or when the lights are on, then when turning the lights off you get more grainy/noisy image. That's even with iCamera initialization.

So hacks enabled, cloud enabled, cloud apps stopped and powering camera on in the dark will give you good results (a little bit blurry/fuzzy image but without noise) and low bandwidth usage (under 100 kbps in 720p) while rtsp streaming. More grainy/noisy image gives you bigger bandwidth usage tho.

I played a little bit in cloud disabled mode, fiddling with sensor exposure and gain (with ISP AEC and AWB disabled) and I actually managed to get more light but wasn't able to reduce noise (the noise was horrible) thus bandwidth went haywire (from let say 300 kbps to 2500 and even more on a bw 720p image).

The next thing I'm planning to do is stracing that iCamera stuff...

BlaY0 commented 6 years ago

OK, stracing didn't get me anywhere but I have found few starting points after that...

That /proc/isp/iq/nrn is actually quite important. That iq handles control image quality sub module and nrn is actually enabling some sort of fuzzy/blury overlay so the image gets smoothened which is good for the low bitrate. As I said, more noise gives you way higher bitrate which just means bigger file or more bandwidth used without any quality gain.

Then there are handles for auto exposure submodule in /proc/isp/ae dir and these are adjusting automatically depending on intensity of the light source(s). But you can still play around with for example gain and as soon as you change the value of it, you see the result. At that point ae submodule is disabled even tho the enable handle still shows 1. If you want ae back, you have to disable it again via handle and then reenable it.

masterchop commented 6 years ago

no solution to this?

frol commented 5 years ago

I have the same problem, but I have two XiaoFang cameras and I clearly see that they have a drastic difference in IR lights.

Here is what I have:

The older camera produces the type of picture shown in the first message in this thread. When I replace the first camera with the second one, I get a perfect picture. Next, I powered on both cameras and the older camera started producing a great quality night vision picture as well and I can see that IR light goes from the second camera (I can see a flashlight effect on the video from my old camera when I turn my newer camera). The old camera still has its IR indicators on and even can light some items in a range of less than 1 meter (while the newer camera lights up the whole room which is ~3x4 meters).

It looks like a hardware problem and IR lights in my old camera just die. :(