ghoost82 / mijia-720p-hack

Xiaomi Mijia-720P camera hack
253 stars 59 forks source link

PTZ control #3

Open max5962 opened 6 years ago

max5962 commented 6 years ago

Can you add this project ? :) https://github.com/cck56/mijia-720p-ctrl

ghoost82 commented 6 years ago

Hi,

hear the first time about this project. I will try to add it to my hack.

Regards -jan

max5962 commented 6 years ago

Awesome thnaks :)

alphasylvain commented 6 years ago

hello

i wait ...... lol

thank ghoost82

couz23 commented 6 years ago

Is there a way to turn On and Off the Sleep Mode with the hack?

jkleczkowski commented 6 years ago

Hi, Any progress?

ghoost82 commented 6 years ago

Sorry not yet. I had no time to investigate the problem further. Currently I still geting the pwm init failed error.

omardesu commented 6 years ago

Is there a way I can help with this? I can’t compile, but I can try playing around with it if you provide some files.

ghoost82 commented 6 years ago

I had some time to test this. I have found what prevented me from starting the program. I also improved the code a little bit and have created a PR to commit the changes. Next step is implement this somehow in the firmware hack.

max5962 commented 6 years ago

@ghoost82 any news ?

max5962 commented 6 years ago

@ghoost82 any news about that hacks ? I want my ptz control back :D thanks

brtwrs commented 6 years ago

@max5962 here is the mijia_ctrl file I compiled: https://bartwijers.stackstorage.com/s/8yV3j3hpqShpayb Put it on your cam and run it.

You can control your cam with this command from another device in your network: echo -n "MOVE,10,10" | nc -4u -q1 -w1 [cam ip] 8888

I know its not perfect but at least you can control you cam again;)

pekidi commented 6 years ago

i am a afraid that this project is doomed. Too bad, i would be very happy if we can get a new update of mijia-720p-hack with improvements of rtsp server, option with enabled night vision and so on...

brtwrs commented 6 years ago

@pekidi why is it domed? Because @ghoost82 hasn't got time to work on this (for free) in his spare time? I perfectly understand @ghoost82. I think he provided us with a very good starting point for further development. You're free to fork the project and add all the features you want if development is not fast enough for you;)

pekidi commented 6 years ago

thanx a million times to @ghoost82 for this project but i understand that @ghoost82 is busy, but everyone can take 15seconds of own time and answer to users, how the project is going :) or maybe we can (users) help somehow :)

haimn commented 6 years ago

@pekidi I don't see any Pull requests, if you have some code improvement you can submit it via pull request. I'm sure when @ghoost82 will have something to share he will do it, until then, you can wait or contribute the project yourself (you can even fork it if you want).

Usually when a project is dead someone fork it and continue the work, you are more than welcome to do it.

max5962 commented 6 years ago

@brtwrs awesome its working ! Now i have to integrate cam moving scripts to my home assistant : ) thanks a lot.

After launching the binary mijia-ctrl, night mode is totaly disable so all the screen is black : (

brtwrs commented 6 years ago

@max5962 nice! You can control the IR-led, nightmode and IR-cut from mijia-ctrl as well. Look at the README on the project page. Works perfect for me! Maybe you can release your HA scripts so other people can use them too:)

This is my bachscript for turning on and off Night mode:

! /bin/bash

if [ $1 = 1 ]; then echo "Night mode.." echo -n "IRCUT,0" | nc -4u -q1 -w2 192.168.10.112 8888 echo -n "IRLED,255" | nc -4u -q1 -w2 192.168.10.112 8888 echo -n "DAYNIGHT,1" | nc -4u -q1 -w1 192.168.10.112 8888 else echo "Day mode.." echo -n "IRCUT,1" | nc -4u -q1 -w2 192.168.10.112 8888 echo -n "IRLED,0" | nc -4u -q1 -w2 192.168.10.112 8888 echo -n "DAYNIGHT,0" | nc -4u -q1 -w1 192.168.10.112 8888 fi exit 0

It would be cool to run the commands on the cam it self to localhost, being triggered from a button on the webinterface (or a simple http get request). Did some tests and nc to localhost works

Djowie commented 6 years ago

I can see @ghoost82 has created a few updates including the possibility to now use ptz commands. Super thrilled about this :). However I’m having difficulties building the new binaries :(. Can’t really find a good explanation how to do this :(.

The release hosted on github is still with the old binary files and therefor I’m unable to use this. Can anyone help me or point me in the right direction )

Paziat commented 6 years ago

Can somebody do a precompiled release because I'm unable to build the new binaries. Thanks!

mindcont commented 6 years ago

any update?

ghoost82 commented 6 years ago

Just uploaded a new release with prebuild binaries. This release has included the mijia_ctrl binary and is able to move the camera. Without a working Web UI currently it is only possible to move the motor via cammandline.

bmwm69 commented 6 years ago

@ghoost82 It's possible update readme file with ptz commands and night mode ?

Paziat commented 6 years ago

Thank you for the new release...Unfortunatly I encounter a strange issue. My wifi is provided by one devolo CPL (dlan 500 AV wireless +). when I try to connect the camera, my wifi is killed and I need to shut of the camera and restart my CPL.....Any idea? Many thanks.

max5962 commented 6 years ago

@ghoost82 using new release port 8888 is disable you have to use command line.

some crappy code in order to retreive web PTZ access :

New script file :

cat /tmp/sd/mijia-720p-hack/scripts/motor.sh
. /tmp/sd/mijia-720p-hack/scripts/functions.sh
motor $1

New ugly Php file:

cat /tmp/sd/mijia-720p-hack/www/motor.php
<html>
        <head>
                <meta charset="utf-8">
                        <meta name="viewport" content="width=device-width" />
                        <title>Mijia 720P hack</title>
                        <link rel="stylesheet" href="mijia.css">
                        </head>
                        <body>
                                <ul class="topnav">
                                        <li>
                                                <a href="index.html">Home</a>
                                        </li>
                                        <li>
                                                <a href="settings.html">Settings</a>
                                        </li>
                                        <li>
                                                <a href="motor.php" class="active">PTZ control</a>
                                        </li>
                                        <li class="right">
                                                <a href="about.html">About</a>
                                        </li>
                                </ul>

                                <?php
                        if(isset($_POST))
                        {
                          if(isset($_GET['action']))
                          {
                                $direction=$_GET['action'];
                                $cmd = exec(escapeshellcmd("sh /tmp/sd/mijia-720p-hack/scripts/motor.sh $direction"));
                          }
                        }

                        echo '
                                <form method="GET" action="motor.php?action=right">
                                        <input type="submit" value="right" />
                                </form>
                                <form method="GET" action="motor.php?action=left">
                                        <input type="submit" value="left" />
                                </form>
                                <form method="GET" action="motor.php?action=up">
                                        <input type="submit" value="up" />
                                </form>
                                <form method="GET" action="motor.php?action=down">
                                        <input type="submit" value="down" />
                                </form>
                                ';
                ?>
                        </body>
                </html>

some commands (right/left/up/down) :

curl -d "action=right" -X POST http://IP/motor.php?action=right

Djowie commented 6 years ago

@max5962 Thanks this works :D. Except for the form, I think you should just set the input type action in the forms to name="action"

Ezloopz commented 6 years ago

If i do /tmp/sd/mijia-720p-hack/scripts/functions.sh motor left something should happen, right? tried some of the other functions aswell, nothing seemed to work. also tried @max5962 motor.php thing which seems to make use of that, same result: nothing got no problem using mijia_ctrl (if that helps) any ideas?

max5962 commented 6 years ago

@Djowie You are welcome. Exact. It's a crappy code. I did it 15 minutes, just to retrieve access to my camera : ) @ghoost82 you can use and improve the code. : )

@Ezloopz Nope, function.sh just define function so they need to be define in the exécution context. Thats why i created a motor.sh :
/tmp/sd/mijia-720p-hack/scripts/motor.sh left Whitout that script, nothing works : )

Ezloopz commented 6 years ago

@max5962 aha ok, yup that works :) i didnt try it like that yesterday.. strange that it didnt work through motor.php then (motor.sh was in place)?? and still dont. But just to be clear about the scripts: By looking at motor.php and motor.sh i assumed i could do /tmp/sd/mijia-720p-hack/scripts/functions.sh motor left But, motor.sh runs INSIDE functions.sh? and not passing "runtime params"? if that makes sense xD i never really got into shell scripts. EDIT: sry for getting kinda OT

  1. EDIT: i can also curl it, but still not through browser
max5962 commented 6 years ago

@Ezloopz don't be sorry :) motor.php only call "sh /tmp/sd/mijia-720p-hack/scripts/motor.sh left" so if that command work, motor.php has to work.

functions.sh define shell functions ( like the function motor() ) if you do "functions.sh motor left", you are running the "functions.sh" script with variables "Motor" and "left".

But functions.sh does not handle variable ( only define functions ). motor.sh :

#Define all functions ( specially _motor_ ) in the "." context
. /tmp/sd/mijia-720p-hack/scripts/functions.sh

# RUN the shell function "_motor_" with the first variable
motor $1
omardesu commented 6 years ago

@max5962 good stuff! it took me almost a day to figure out what @Djowie was saying since I have no coding skills whatsoever...

Just add in name="action" to the input string and then the browser control buttons function properly after adding for each direction as such (for example, right):

<form method="GET" action="motor.php?action=right"> <input type="submit" value="right" name="action" /> </form>

I don't even know how to write formatted responses... Oh well... this will work good enough for me!!!

ioldfish commented 6 years ago

@brtwrs awesome its working ! Now i have to integrate cam moving scripts to my home assistant : ) thanks a lot.

After launching the binary mijia-ctrl, night mode is totaly disable so all the screen is black : (

I'm also in need it to my home assistant,can you share your config file,thanks

sunflowerABB commented 5 years ago

Remotely controlling the motor using the standard command works: echo -n "MOVE,10,0" | nc -4u -q1 -w1 192.168.1.18 8888

when I try to run the motor.sh script as listed above however (same with the php file in my browser) I get the following result - any clues?

sh /tmp/sd/mijia-720p-hack/scripts/motor.sh left

sh: bad number sh: bad number sh: bad number sh: bad number sh: bad number sh: bad number

ondrejb86 commented 5 years ago

Have done - motor.php , motor.sh everything is working fine... but camera wont go to the left... even by "sh /tmp/sd/mijia-720p-hack/scripts/motor.sh left" command. Other directions and "calibrate" is working fine. Camera is turning left during the calibrating session, that means there is no hw issue. Any idea? THX

joten75 commented 5 years ago

please evryone can post a full guide to made ptz work . i'm a total new.. i'm using home assistant too, if somebody can share config I would appreciate it very much!! :) thank you guys for this work!!

sunflowerABB commented 5 years ago

Placing the mijia_crtl file in the /bin folder, the motor.php file in the /www folder and the motor.sh file in the /script folder I am able to see the simple web GUI when manually entering the motor.php URL but it doesn't work yet. When running the motor.sh script via ssh on the cam I can calibrate the cam despite various error messages (see below) but again no motion is possible:

# sh motor.sh calibrate sh: bad number sh: bad number sh: bad number sh: bad number Failed to open /dev/ftpwmtmr010 PWM initialization failed ^[[AFailed to open /dev/ftpwmtmr010 PWM initialization failed Failed to open /dev/ftpwmtmr010 PWM initialization failed sh: bad number

Would also love to have this hack finished with PTZ control :-)

max5962 commented 5 years ago

Hello everyone, It seems that my crappy code is not east enough for everyone : ) I will do a PR with a good UI.

ondrejb86 commented 5 years ago

please evryone can post a full guide to made ptz work . i'm a total new.. i'm using home assistant too, if somebody can share config I would appreciate it very much!! :) thank you guys for this work!!

OK, I've get it to work, here is what I've did:

1, Downgraded fw you can download it here https://c720p-recovery.pekidi.com/ There are 3 versions, I've used that unziped one. After downgrade I did reset, and paired again with Mii Home. There was problem to scan QR code, I was trying it more than 15 minutes to sucess.

2, I've downloaded release v0.95 here https://github.com/ghoost82/mijia-720p-hack/releases and move content of SD folder to sd card. Changed Wifi SSID and PSK in mijiaxxxx.cfg

3, After that, I've created new textfile with . /tmp/sd/mijia-720p-hack/scripts/functions.sh motor $1 And renamed to motor.sh

4, Created new file motor.php with that crapy codee above. " cat xxxx " is linux command to create file, you have to use only code from blablablabla some crappy code on the end.

5, Open cameraip/motor.php ant there it is.

In my case, motor function and IR restarting was workin properly, but every 10s there was picture disintegration described here: https://github.com/ghoost82/mijia-720p-hack/issues/4#issuecomment-428452184

sunflowerABB commented 5 years ago

One more critical point which I just discovered while debugging some more: the mijia_crtl binary must be running for all of this work!


/tmp/sd/mijia-720p-hack/bin/mijia_ctrl

UDP server started on 0.0.0.0:8888 Exit with Ctrl+C

Now how to autostart this server so that it always runs while the rtsp server is running? Should I modify the "S99rtsp" daemon file? For now I simply telnet into the camera and run:

nohup /tmp/sd/mijia-720p-hack/bin/mijia_ctrl &

fliphess commented 5 years ago

That's only partly true: if you add no command line arguments it will start the socket server which you can control using telnet. Using the cli flags you can use the tool as well without starting the socket server:

Have a look using

 /tmp/sd/mijia-720p-hack/bin/mijia_ctrl IRLED,0
 /tmp/sd/mijia-720p-hack/bin/mijia_ctrl IRCUT,<value>

... etc

More info: /tmp/sd/mijia-720p-hack/bin/mijia_ctrl -h