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

Any plans to add live view and controls to the web server? #79

Open
lazibayer opened this issue Nov 9, 2017 · 60 comments
Open

Any plans to add live view and controls to the web server? #79

lazibayer opened this issue Nov 9, 2017 · 60 comments

Comments

@lazibayer
Copy link

I love the camera but I wish I can use it at places without ANY internet connection. I have an old Fujikam that allows me to do that by simply navigating a browser to its IP address.

@shadow-1
Copy link
Owner

@lazibayer
I do not plan on developing this feature any time soon.

However I am planning on developing RTSP support which will allow use at places without an Internet connection. However not through the web server but through a program running on a PC or through a smartphone app which will not require Internet access.

@lazibayer
Copy link
Author

That's good news! Thanks for your continuous effort!

@alexgorbatchev
Copy link

May I suggest a similar feature that could be "easier" to implement. A static JPEG url that could be accessed and which is updated every N seconds. This would integrate very well with home automation systems like openHAB which allow to display URL images on the monitors and refetch them every N seconds.

Thoughts?

@alexgorbatchev
Copy link

Also, this project allows RTSP streaming https://github.com/xmflsct/yi-hack-1080p

@Ben47
Copy link

Ben47 commented Nov 27, 2017

Hi, I have a camera yi dome 720p international. I put the firmware yi-hack-v3.
How can I access the video stream of my camera on a browser?
(ex -> http: // ip_camera :?) What are the internal and external TCP port numbers to use?
thank you in advance
Benoit
nat-pat

@lazibayer
Copy link
Author

Also, this project allows RTSP streaming https://github.com/xmflsct/yi-hack-1080p

I check that project and it seems that RTSP and Yi Home access are mutually exclusive. Will it be the same case for this project as well?

@kruschman
Copy link

It looks like that project is only for the 1080p version. Does anyone know if it will work with the 720p 27US version since they apparently have the same image sensor?

@shadow-1
Copy link
Owner

@alexgorbatchev
I will have to investigate whether an updating webpage will be easier to implement than RTSP.
I know of this project as I have had some input into it.

@Ben47
Unfortunately only the official Xiaomi apps are supported at this time (Android, iOS and Windows).

@lazibayer
I do not plan to make RTSP and Yi Home access mutually exclusive. However I will have to see how I go.

@kruschman
Yes this other project is specifically for the Yi 1080p Home camera. As far as I am aware, the 720p 27US version of the camera uses a different image sensor. Therefore to make this preliminary RTSP implementation work on the 720p cameras, it needs to be recompiled against the correct image sensor library.

@dvv
Copy link

dvv commented Nov 29, 2017

+1 for managing to obtain the static JPEG image.
This is beacuse if it is available somehow, it can be sent with periodic scripts, accessed via ftp polling, busybox's (more fat) httpd applet, hand-made poorman shell-based http server, used as the source for mjpeg-streamer's input_file.so etc etc etc you name it.

Just FYI, in motion detection mode /tmp/motion.jpg becomes available at motion start.

@shadow-1
Copy link
Owner

@dvv
Thank you for the information. I wonder if the JPEG image gets updated regularly or whether it gets created once per motion event.

@dvv
Copy link

dvv commented Nov 30, 2017

Once. It gets rid after several seconds and I had no chances to play with it more thoroughly. I believe it's sent to cloud then quickly removed.

I managed to (seemingly) robustly catch motion alarm start by the next script (by heart, no camera at hands):

tail -F /tmp/log.txt | awk '
/: got a new motion start/ {
  print "ALARM+"
  system("<START HERE A SHELL COMMAND TO NOTIFY OF ALARM HAS BEGUN>")
}
/: got a new motion stop/ {
  print "ALARM-"
  system("<START HERE A SHELL COMMAND TO NOTIFY OF ALARM HAS ENDED>")
}
'

Moreover, there are some debug info in /tmp/log.txt containing URLs the camera sends to the cloud -- may be it's worth to catch-proxy them for some kind of data or further kludges.

@nicolasplanchon
Copy link

@dvv could you tell us a little bit more regarding the way you implement your script please ? :)

@dvv
Copy link

dvv commented Dec 7, 2017

I added a script /home/yi-hack-v3/script/alarm.sh:

#!/bin/sh

exec tail -F /tmp/log.txt | awk '
/: got a new motion start/ {
  print "ALARM+"
  system("wget -q --spider \"http://192.168.43.1:8765/sms?phone=XXXXXXXXXX&text=cam4\"")
}
/: got a new motion stop/ {
  print "ALARM-"
}
'

and made it called from /home/yi-hack-v3/script/system.sh:

if [ -f "/home/yi-hack-v3/script/alarm.sh" ]; then
        sh /home/yi-hack-v3/script/alarm.sh &
fi

The camera is WiFi-ed via an android phone in WiFi hotspot mode, so the phone's IP is known to be 192.168.43.1.

I installed tasker on that phone with TNES plugin which listens to port 8765. I added the task to listen to incoming HTTP GET requests to /sms endpoint, extract phone and text variables from the querystring and send SMS.

It just does work )

@shadow-1
Copy link
Owner

shadow-1 commented Dec 8, 2017

@dvv
The work you have done is impressive. Being able to send a sms message upon motion detection is quite an achievement.

@dvv
Copy link

dvv commented Dec 9, 2017

Right, with https-powered wget in hands and robust detection of start of motion we can do very much.
I would post to telegram:

wget -q --spider 'https://api.telegram.org/bot<APIKEY>/sendMessage?chat_id=<CHAT>&text=ALARM!'

@dvv
Copy link

dvv commented Dec 9, 2017

The log.txt parser evolved:

#!/bin/sh

# Copyright 2017 Vladimir Dronnikov
# GPL

exec tail -F /tmp/log.txt | awk '
/: got a new motion start/ {
  # motion just started
  print "ALARM+"
  #system("wget -q --spider \"http://192.168.43.1:8765/sms?phone=9190504182&text=cam4\"")
}
/: cmd=\/home\/app\/cloudAPI -c 411 .* -filename \/tmp\/motion\.jpg\.crypt/ {
  # photo ready
  print "PHOTO"
  system("cp /tmp/motion.jpg /tmp/temp.jpg ; nc 192.168.34.10 1884 < /tmp/temp.jpg &")
}
/: cmd=\/home\/app\/cloudAPI -c 411 .* -filename \/tmp\/motion\.mp4\.crypt/ {
  # video ready
  print "VIDEO"
  system("cp /tmp/motion.mp4 /tmp/temp.mp4 ; nc 192.168.34.10 1885 < /tmp/temp.mp4 &")
}
/: got a new motion stop/ {
  # motion stopped, cleanup
  print "ALARM-"
  system("rm -f /tmp/temp.*")
}
/_____Gamma test for table 4__________/ {
  # daylight mode
}
/_____Gamma test for table 2__________/ {
  # night mode
}
'

I do miss https-enabled curl for uploading photo and video and replaced it with nc + some helper at another host in local net so far.

@shadow-1 couldn't you provide us with curl?

@dvv
Copy link

dvv commented Dec 9, 2017

I finally found that curl and now the script looks like:

#!/bin/sh

# Copyright 2017 Vladimir Dronnikov
# GPL

TELEGRAM_BOT_TOKEN=XXX
TELEGRAM_CHAT_ID=YYY

# NB: curl from https://github.com/utya1988/yi-hack/tree/master/sd/test/curl

exec tail -F /tmp/log.txt | awk -v TELEGRAM_BOT_TOKEN="${TELEGRAM_BOT_TOKEN}" -v TELEGRAM_CHAT_ID="${TELEGRAM_CHAT_ID}" '
# TODO: urlencode text
function sendText(text) {
  system("curl -k -q --data \"chat_id=" TELEGRAM_CHAT_ID "&text=" text "\" \"https://api.telegram.org/bot" TELEGRAM_BOT_TOKEN "/sendMessage\"")
}
function sendPhoto(file, text) {
  system("curl -k -q -F photo=@" file " \"https://api.telegram.org/bot" TELEGRAM_BOT_TOKEN "/sendPhoto?chat_id=" TELEGRAM_CHAT_ID "&caption=" text "\"")
}
function sendVideo(file, text) {
  system("curl -k -q -F video=@" file " \"https://api.telegram.org/bot" TELEGRAM_BOT_TOKEN "/sendVideo?chat_id=" TELEGRAM_CHAT_ID "&caption=" text "\"")
}
/: got a new motion start/ {
  # motion just started
  print "ALARM+"
  sendText("ALARM+")
}
/: cmd=\/home\/app\/cloudAPI -c 411 .* -filename \/tmp\/motion\.jpg\.crypt/ {
  # photo ready
  print "PHOTO"
  system("cp /tmp/motion.jpg /tmp/temp.jpg")
  sendPhoto("/tmp/temp.jpg", "PHOTO")
}
/: cmd=\/home\/app\/cloudAPI -c 411 .* -filename \/tmp\/motion\.mp4\.crypt/ {
  # video ready
  print "VIDEO"
  system("cp /tmp/motion.mp4 /tmp/temp.mp4")
  sendVideo("/tmp/temp.mp4", "VIDEO")
}
/: got a new motion stop/ {
  # motion stopped, cleanup
  print "ALARM-"
  sendText("ALARM-")
  system("rm -f /tmp/temp.*")
}
/_____Gamma test for table 4__________/ {
  # daylight mode
}
/_____Gamma test for table 2__________/ {
  # night mode
}
'

That's all for now.

@frekel
Copy link

frekel commented Jan 4, 2018

@dvv: I am trying to get your script working, but I can not use curl:

/home/yi-hack-v3/sbin# curl
curl: can't load library libz.so.1

Can you provide a small howto?

Thanks,
Frank

@dvv
Copy link

dvv commented Jan 4, 2018

@frekel try putting https://github.com/utya1988/yi-hack/blob/master/sd/test/curl/libusr/libz.so.1.2.8 as /home/yi-hack-v3/lib/libz.so.1 and use

LD_LIBRARY_PATH=/home/yi-hack-v3/lib curl ...

Does it work?

@frekel
Copy link

frekel commented Jan 4, 2018

~ # wget https://github.com/utya1988/yi-hack/raw/master/sd/test/curl/libusr/libz
.so.1.2.8
Connecting to github.com (192.30.253.113:443)
Connecting to raw.githubusercontent.com (151.101.36.133:443)
libz.so.1.2.8        100% |*******************************| 87531   0:00:00 ETA
~ # cp libz.so.1.2.8 /home/yi-hack-v3/lib/libz.so.1 
~ # cd /home/yi-hack-v3/sbin/
/home/yi-hack-v3/sbin # curl
curl: try 'curl --help' for more information

Works like a charm!

@dvv
Copy link

dvv commented Jan 4, 2018

\o/

@shadow-1
Copy link
Owner

shadow-1 commented Jan 4, 2018

curl can also be cross-compiled without compression support. This will eliminate the dependency with libz.

@josemonino
Copy link

josemonino commented Jan 6, 2018

@frekel

~ # wget https://github.com/utya1988/yi-hack/raw/master/sd/test/curl/libusr/libz.so.1.2.8
Connecting to github.com (192.30.253.113:443)
Connecting to raw.githubusercontent.com (151.101.36.133:443)
libz.so.1.2.8 100% |*******************************| 87531 0:00:00 ETA
~ # cp libz.so.1.2.8 /home/yi-hack-v3/lib/libz.so.1
~ # cd /home/yi-hack-v3/sbin/
/home/yi-hack-v3/sbin # curl
-sh: curl: not found

could you help me?
I don't know how to compile curl for the camera...

Thanks

@dvv
Copy link

dvv commented Jan 7, 2018

@josemonino it's referenced in the script above: # NB: curl from https://github.com/utya1988/yi-hack/tree/master/sd/test/curl

@josemonino
Copy link

@dvv Thanks a lot.

Your script is incredible. I'm looking forward to run it on my cam.
The problem is that I'm not able to get curl in my cam. What should I do?

I put https://github.com/utya1988/yi-hack/blob/master/sd/test/curl/curl into /home/yi-hack-v3/sbin/
And I put https://github.com/utya1988/yi-hack/blob/master/sd/test/curl/libusr/libz.so.1.2.8 as /home/yi-hack-v3/lib/libz.so.1
But still not working. With that files, I get Illegal instruction every time I try to execute curl.

Could you help me please?

@frekel
Copy link

frekel commented Jan 7, 2018

@josemonino:

Can you do a ls -l from /home/yi-hack-v3/lib and /home/yi-hack-v3/sbin?

Just to be sure we have the same enviroment....

@dvv
Copy link

dvv commented Jan 8, 2018

\o/

@frekel
Copy link

frekel commented Jan 8, 2018

Small succes!!!

screenshot from 2018-01-08 16-39-27

I have edited the script from @dvv:

photo() {
        cp $1 /tmp/sd/record/last.jpg
        curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto?chat_id=${TELEGRAM_CHAT
}

and run the following command to get a symlink:
mkdir /home/yi-hack-v3/www/img
ln -s /tmp/sd/record/last.jpg /home/yi-hack-v3/www/img/last.jpg

add the following to /home/yi-hack-v3/www/about.html (around line 82):

                <h2>Last picture</h2>                                                                
                <img src="img/last.jpg" alt="Last" class="img-thumbnail"> 

@frekel
Copy link

frekel commented Jan 8, 2018

@shadow-1: I am trying to create a pull request, but I'm unfamiliar with the c# (?) part of your sources...

Can you point me in the right direction?
See: frekel@2782048
or my PR: #117

@shadow-1
Copy link
Owner

shadow-1 commented Jan 9, 2018

@frekel
This firmware only uses (Straight) C, there is no C#. I will help you out in the pull request.

@nicolasplanchon
Copy link

nicolasplanchon commented Jan 25, 2018

Hi,
Just to be sure to understand:

I have to add your scripting code in /home/yi-hack-v3/script/alarm.sh and make it call with

if [ -f "/home/yi-hack-v3/script/alarm.sh" ]; then
sh /home/yi-hack-v3/script/alarm.sh &
fi

in /home/yi-hack-v3/script/system.sh

Right ?

@dvv
Copy link

dvv commented Jan 25, 2018

Right, that should work.

@josemonino
Copy link

@dvv Thanks a lot. It's working like a charm!!

@eryckm
Copy link

eryckm commented Jun 5, 2018

@frekel Have you got the images I can use with your ALARM modifications?

@frekel
Copy link

frekel commented Jun 5, 2018

@eryckm:
Take a look here: #117
I am using the last images (yi-hack-v3 0.1.5)

@xhemp
Copy link

xhemp commented Jun 5, 2018

Thanks, @frekel. I asked that because of "WIP: Adding alarm functionality (and last motion in webinterface (the changes to the C file) " but looks like you were not able to get that built with the change included.

@frekel
Copy link

frekel commented Jun 5, 2018

@xhemp: Unfortunately @shadow-1 hasn't had any time to continue... Sorry!

The PR is working but you can't set settings thru the webinterface. You need to ssh into the camera and update the config-files manually (aswell ftp the new source files!)

@dvv
Copy link

dvv commented Sep 21, 2018 via email

@jaxdao
Copy link

jaxdao commented Sep 22, 2018

HI @dvv ,
Is there a way to detect baby crying in Yi Home 1080p along with motion detection?
I found that there are 2 files created babycry.jpg and babycry.mp4 at /tmp/ while it was detecting baby crying

@dvv
Copy link

dvv commented Sep 25, 2018

@jaxdao I believe you should copy #79 (comment) and make it watch for these files instead of /tmp/sd/record/tmp.mp4.tmp

@gooman-uk
Copy link

gooman-uk commented Dec 27, 2018

The script isn't working for me. I have no folder /tmp/sd/record.

Even if I create it, there's no files created in there while it's recording.

I'm using the latest version of the v3 hack on firmware 1.8.7.0D_201708091510

[EDIT - I should also note that the Yi app notes in settings next to the MicroSD Card: "Abnormality detected, formatting required". I assume that this is because of the use of the SD card for the hack, but maybe not ...]

[SOLVED - The SD card was originally PC-formatted. I reformatted it from the camera itself, and now it recognises the card and saves recordings in /tmp/sd/record ]

@gooman-uk
Copy link

@dvv do you have a timeline for exactly when the motion.jpg/.mp4/.jpg.crypt/.mp4.crypt and /tmp/sd/record/tmp.mp4.tmp files get created and deleted?

I'm having intermittent results with your script, and I think it's a timing issue.

@dvv
Copy link

dvv commented Jan 14, 2019

@davidgurr No I don't. The script is just a reactive one -- it tries to catch these exact moments.
But it just works since creation/deletion takes more than 1 second which is the period of the script.

@jcconnell
Copy link

I'm trying to use the curl mentioned here in the Fritz Yi Hack. This is the error I get when trying to run that curl from the camera. Any ideas?

./curl: line 1: syntax error: unexpected word (expecting ")")

@xhemp
Copy link

xhemp commented May 13, 2019

@jcconnell this project is dead, there's a yi-hack-v4 from another dev, check it out: https://github.com/TheCrypt0/yi-hack-v4

@jcconnell
Copy link

I've reviewed that project but it appears he's accepting donations for RTSP functionality. RTSP is working fine for me using the project here: https://github.com/fritz-smh/yi-hack. My goal is to enable curl with HTTPS support so I can get motion notifications in Home Assistant.

@xhemp
Copy link

xhemp commented May 13, 2019

He is, yes but it's not the only thing that is being done. RTSP is already working and also MQTT. I do have motion notifications from all my cameras on HA. I did donate, yes, the minimum is £5 so not really a bank breaker :) ,anyway, it was just a heads up.

@Scope666
Copy link

I'll second what xhemp said, the Dev is crazy active and is making great progress. The improvements to the web UI alone were worth the donation.

@jcconnell
Copy link

You guys twisted my elbow. Curious if it's one donation per user or one donation per camera?

@xhemp
Copy link

xhemp commented May 13, 2019

Per user.

@jcconnell
Copy link

Done. Thanks for the heads up. Now to update 7 cameras...

@JoaquinBeceiro
Copy link

JoaquinBeceiro commented May 19, 2019

For install curl:

cd /home/yi-hack-v3/sbin/
wget https://github.com/utya1988/yi-hack/raw/master/sd/test/curl/curl
chmod +x /home/yi-hack-v3/sbin/curl
cd /home/yi-hack-v3/lib
wget https://github.com/utya1988/yi-hack/raw/master/sd/test/curl/libusr/libz.so.1.2.8 -O libz.so.1

I cant find /tmp/sd/record/last.jpg file. I need to do something before?

@Arkady23
Copy link

https://github.com/Arkady23/yi-hack-v3plus
Yi-hack-v3 now has an updated web-server, the necessary settings, a standard RTSP server (free), Network time service, setting a timezone, disabling the cloud, viewing recorded videos from an SD-card in a usual browser.

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

No branches or pull requests