FiveLeavesLeft / WyzeCameraLiveStream

Hack to allow live streaming from wyze cameras to vlc or mpv on your desktop.
MIT License
100 stars 7 forks source link

Synology Surveillance Station Integration #20

Open j-st1 opened 3 years ago

j-st1 commented 3 years ago

Hi, I'm trying to integrate the streaming hack into Synology Surveillance Station but for some reason it does not work: I configure the Camera as "Streaming - HTTP". When it tests the connection, it fails everytime. The "stream_hack.log" file on the camera prints the following:

CRB: Waiting... CRB: Accept... CRB: New client: 192.168.1.5 CRB: Client said: 'GET / HTTP/1.0 User-Agent: Synology Surveillance Station Auth' CRB: read failed, stopping client CRB: New client finished. CRB: connfd == client_fd CRB: Waiting... CRB: stream write error:No such file or directory CRB: shut down client

Any idea how to get it to work?

Thanks in advance!

FiveLeavesLeft commented 3 years ago

That looks like a bug in the streaming code. Do you have any way to control the http headers it sends?

j-st1 commented 3 years ago

I don't see any options to do that. Also a quick search gave me nothing, unfortunately..

FiveLeavesLeft commented 3 years ago

@j-st1 I think I have fixed this in the version I am hoping to upload in the next couple of days. Do you want to be a "guinea pig" and try out the new version before I release it? It has a new installation mechanism that may need some kinks worked out. Is your cam V2 or V3? Thanks.

j-st1 commented 3 years ago

@FiveLeavesLeft Wow, that was quick! I have a Wyze Cam V3. Yes I'll play guinea pig :).

FiveLeavesLeft commented 3 years ago

@j-st1 I just uploaded the new stuff to www.sonic.net/~crb/repo.tar

But I just realized it doesn't support 2FA if you have that turned on in your wyze account. I'll take a look at supporting that.

Thanks.

j-st1 commented 3 years ago

@FiveLeavesLeft Thanks! I dpn't have 2FA set up for now. The installation process works. There was a port-number mixup, I think in server.py saying 12354 instead of 12345, so that it yould not connect to pull the update at first. Unfortunately, I'm getting the same errer in the surveillance station, when trying to connect to the camera. VLC works fine. It seems like the log file is disabled in the code, so that I can't pin down the reason. Next week, I can try to set up the toolchain and do the modification myself and check if it's the same error.

FiveLeavesLeft commented 3 years ago

@j-st1 Thank you very much for that feedback. Very helpful.

I think if you 'grep CRB /tmp/zz' you'll see the output of the stream hack. (This has the stdout of iCamera too. ) Alternatively, in install/install.sh you can uncomment the line '#echo log=/tmp/stream.log >> /configs/stream_hack/config' and reinstall the hack the output should appear in /tmp/stream.log.

Odd that surveillance station is still failing. If it's still in that read(), the code is tcp.c/client_readln(). Maybe if you can capture the http GET request we can figure out why.

j-st1 commented 3 years ago

@FiveLeavesLeft Thanks for the hint. Here is the output:

CRB: Accept... CRB: New client: 192.168.1.5 CRB: Client said: 'GET / HTTP/1.0' CRB: Client said: 'User-Agent: Synology Surveillance Station' CRB: Client said: 'Authorization: Basic Og==' CRB: Client said: '' CRB: read failed, stopping client CRB: New client finished. CRB: connfd == client_fd CRB: Waiting... CRB: stream write error:No such file or directory CRB: shut down client

Looks like it's still failing in read(). I will do some more testing as soon as I can.

FiveLeavesLeft commented 3 years ago

@j-st1 I looked at the code and I don't see a bug per se, but the code is structured strangely for historical reasons -- being an http server was really an after thought, originally it had a little custom protocol with commands. So I changed the code to behave more like a proper http server and I expect that will your fix your issue. I hope to get that uploaded later today or tomorrow, I'm kinda busy right now.

j-st1 commented 3 years ago

@FiveLeavesLeft Thanks for the info. I also looked into it a little bit, and I don't see why I should not be working.. Maybe Synology expects a specific reponse or a different encoding.. Anyway, I'd gladly try your new server, as soon as it's ready. Thanks a lot for putting so much effort into it!

FiveLeavesLeft commented 3 years ago

@j-st1 Ok, I uploaded the new one. Same place, same install instructions. This one behaves more like an http server. The log file goes to /tmp/stream.log .

j-st1 commented 3 years ago

@FiveLeavesLeft Same result :( ..

CRB: Client said: 'GET / HTTP/1.0' CRB: Client said: 'User-Agent: Synology Surveillance Station' CRB: Client said: 'Authorization: Basic Og==' CRB: Client said: '' CRB: Client break CRB: do_client returns CRB: Waiting... CRB: stream write error:No such file or directory CRB: shut down client CRB: 0 clients left

I don't see why this should not be working.. I will try to find a Server, which works and then try to determine, what that one is doing differently.. Thanks again!

noelhibbard commented 3 years ago

FYI, this line from the Makefile:

HOST = $(shell python -c 'import socket;print(socket.gethostbyname(socket.gethostname()))')

returns 127.0.0.1

I'm running debian.

noelhibbard commented 3 years ago

I'm trying to install this version without luck. I installed WyzeHacks v0.5.06 (not your fork but the original). That is working properly and I have telnet access and the NFS mount is working. Then I downloaded repo.tar and installed it (after hard coding my server's IP address) but then the camera gets into a 10sec reboot loop until I rm /configs/wyze_hack.sh. At that point the reboot loop stops but then I loose telnet and have to reload WyzeHacks again. Previously I had streamhack loaded from commit 591df62. Is it possible something is left over from that which is causing my reboot loop with the new streamhack?

noelhibbard commented 3 years ago

Digging around it looks like all this version really does is create a config file and then updates the LD_LIBRARY_PATH so that it picks up the modified liblibimp.so and then calls wyze_hack.sh.orig. I changed the log output to write to /configs/stream.log and I see where it starts the server and then says it's waiting but then the camera restarts. When I get home and have physical access to the camera I am going to factory reset it with the SD card so I know I have a clean slate. BTW I am currently on FW: 4.36.2.5.

FiveLeavesLeft commented 3 years ago

@noelhibbard Yes, that's all it does on V3s. It might be interesting to look at the stdout of wyze_hacks.sh which would include the stdout of iCamera. That may shed some light on the reboots. Thanks.

j-st1 commented 3 years ago

I also had the wrong IP-address, forgot to mention it, but mine said 127.0.1.1 Had no issues with reboots, though.. I ran the commands from the readme-file in order to install WyzeHacks, should be version 0.5.05. I'm on Firmware 4.36.0.252

noelhibbard commented 3 years ago

@j-st1 yeah I suspect it's the firmware level causing the issue. I'm going to take it to the office with me today and snag the stdout from wyze_hacks.sh.orig for @FiveLeavesLeft and then flash it to 4.36.0.252 to see if it works better.

noelhibbard commented 3 years ago

So here it the contents of /tmp/ZZ

if [ -f /configs/wyze_hack.sh ]; then
    /configs/wyze_hack.sh &
umount: can't umount /etc: Invalid argument
WyzeHack: WyzeApp version:  4.36.2.5
WyzeHack: WyzeHack version: 0.5.06
ifconfig: wlan0: error fetching interface information: Device not found
WyzeHack: wlan0 not ready yet...
################## to wait wifi vendor id ####################
################## [vendor:0x024c] rtl8189ftv wifi #################
Updating device time to:
Fri May 14 05:50:06 EDT 2021
===========welcome to ver-comp tool=========
[ver-comp]dbg: appver:  4.36.2.5
[ver-comp]dbg: rootver: 4.36.0.112
[ver-comp]exec cmd: cp -rf /system/bin/app.ver /configs/
#######################
#   IS USER PROCESS   #
#######################
[FC] cd pin not found tfcard
[FC] Test.tar no exist
[FC] In [user] mode!
kernel.core_pattern = |/system/bin/ucoredmp_collector.sh --pid %p --signal %s --name %e --time %t --output-dir /media/mmc/cores
kernel.core_pipe_limit = 1
WyzeHack: wlan0 not ready yet...
          inet addr:10.1.0.102  Bcast:10.1.3.255  Mask:255.255.252.0
WyzeHack: 10.18.1.1:/data/cameras not mounted, try mounting to /mnt...

Maybe I am missing something but I don't see anything informative here. I'm going to roll back to 4.36.0.252 and see how that goes.

noelhibbard commented 3 years ago

Rolled back to 4.36.0.252 and then installed the stream hack successfully. After getting it working I decided to flash it back to 4.36.2.5 and sure enough it's back in a reboot loop.

I was able to spin up an RTMP server using Nginx and then was able to use ffmpeg to pull the HTTP stream and then push it over to Nginx. I was then able to pull the stream to VLC. I suspect this workaround would work for the Synology too.

I used this guide to build/configure Nginx: https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/

And then this command line to pull/push the stream: ffmpeg -i http://<CAMERAIP>:12345 -vcodec copy -f flv rtmp://<NGINX_IP>:1935/live/backyard

Then you simply play the stream using: rtmp://:1935/live/backyard

It has about a 6sec lag but maybe there is some tuning that could be done to improve that.

noelhibbard commented 3 years ago

I also wanted to point out, do not try this on the Wyze Doorbell. WyzeHack works and you can get in via telnet but once you install the stream hack it goes into a reboot loop without telnet access. This camera also doesn't have an SD slot so there is no way of recovering. It does have a hidden USB port inside. I am going to see if I can plug in a USB storage device via a Micro OTG cable and maybe recover that way. Only problem is I can't find any download links for the Doorbell firmware.

j-st1 commented 3 years ago

@noelhibbard Thanks for the hints. I ended up using this for now, which works with synology and has almost no lag at all: https://github.com/flaviostutz/rtsp-relay It uses around 0.5% of the NAS's CPU, which is working for me. Thanks @FiveLeavesLeft ! Should we close this issue?

noelhibbard commented 3 years ago

I've been keeping an eye on this project too: https://github.com/kroo/wyzecam

It pulls the native local stream from the camera without any hacks or firmware modifications. I was able to write a simple program that uses this package to pull the local stream and then pipe it to ffmpeg which then pushes the stream to an RTMP server (I'm using Nginx). So then use can use the stream in any software that supports RTMP. Nginx can also be configured to create HLS streams.

FiveLeavesLeft commented 3 years ago

@j-st1 Sure, close it if you like. Sorry I couldn't get working for you.