motioneye-project / motioneyeos

A Video Surveillance OS For Single-board Computers
Other
7.8k stars 888 forks source link

Request: external trigger recording #842

Closed iceboatLen closed 2 years ago

iceboatLen commented 7 years ago

Hello, Would it be possible to add a feature where a camera will record when prompted by an external trigger on a GPIO of the Pi, such as a PIR sensor.

Thanks Ben.

jasaw commented 4 years ago

@vinceemail That requires changes in the motion software. I agree that it would be nice to have an independent "forced recording" mode, rather than depend on "emulate_motion". Can you please create a new feature request in motion project?

joseluissegura commented 4 years ago

have you @vinceemail @jasaw tried? using: http://192.168.1.14:7999/1/detection/start http://192.168.1.14:7999/1/detection/pause

where 192.168.1.14:7999 is the ip:port of your rpi

I saw that while http://192.168.1.14:7999/1/detection/status is "pause" the

http://192.168.1.14:7999/1/config/set?emulate_motion=1 http://192.168.1.14:7999/1/config/set?emulate_motion=0

where able to execute correctly saving pictures, movies, sending emails etc

saving pictures only when emulate_motion is set to 1 and not when the the Pi is actively processing the video stream, and detecting motion in the image

joseluissegura commented 4 years ago

another possibility could be that the PIR set the camera to active processing the video stream (http://192.168.1.14:7999/1/detection/start) and then back to "pause" (http://192.168.1.14:7999/1/detection/pause)

reducing the false positives and the heating of the PI due to the active processing of videos all the time

vpmotion commented 4 years ago

@jasaw @ccrisan Hi I wonder if you could possibly help me. I currently have 3 raspberry pi zero with the motioneyeos installed and all 3 configured as fast network camera, I then have a raspberry pi 3b+ with motioneye installed alongside the raspberian buster. I have put the above code for external trigger on the pi 3b+ and works with no issues. What i would like to know is there a way that i could get the external trigger and the working schedule to work together.

The problem i am facing is that when i set the schedule to not trigger at certain times and i send a external trigger the motioneye still records weather or not i have set the working schedule.

any and all help would be much appreciated.

vpmotion commented 4 years ago

Can someone point me to where the schedule part of the code is. I think I might need to somehow add a bit of extra code there to pause or stop any readings coming in from the GPIO pins?

vpmotion commented 4 years ago

Hi

Can anyone please help with the above I would really really appreciate all the help or direction I can get please.

jasaw commented 4 years ago

@vpmotion Look here for working schedule function: https://github.com/ccrisan/motioneye/blob/78a89fbc2e2d2c284408f8eb1037c8598b4e715a/motioneye/wsswitch.py#L34

vpmotion commented 4 years ago

@Jasaw

Thanks for that. Would there be a way to get the wsswitch to run a script instead of triggering the motion detection on and off?

vinceemail commented 4 years ago

have you @vinceemail @jasaw tried? using: http://192.168.1.14:7999/1/detection/start http://192.168.1.14:7999/1/detection/pause

where 192.168.1.14:7999 is the ip:port of your rpi

I saw that while http://192.168.1.14:7999/1/detection/status is "pause" the

http://192.168.1.14:7999/1/config/set?emulate_motion=1 http://192.168.1.14:7999/1/config/set?emulate_motion=0

where able to execute correctly saving pictures, movies, sending emails etc

saving pictures only when emulate_motion is set to 1 and not when the the Pi is actively processing the video stream, and detecting motion in the image

What a great idea!! I'll give it a shot! Thank you! :)

Right now, I am actually using a really simple hand written script, which just records and uploads a video to google drive while PIR motion is detected. It's working really well, with flawless framerates, even on a PiZero (that always seemed to be an issue for me on MotionEyeOS).

But, I'll give this a shot!

Thanks again!

jasaw commented 4 years ago

@vinceemail Thank you for sharing. That is an easier way of doing it.

smcgann99 commented 4 years ago

@vinceemail I have tried the using the above and seem to get correct responses eg emulate_motion = 1 Done but i do not see any files created, any ideas please?

jedtrently commented 4 years ago

have you @vinceemail @jasaw tried? using: http://192.168.1.14:7999/1/detection/start http://192.168.1.14:7999/1/detection/pause

where 192.168.1.14:7999 is the ip:port of your rpi

I saw that while http://192.168.1.14:7999/1/detection/status is "pause" the

http://192.168.1.14:7999/1/config/set?emulate_motion=1 http://192.168.1.14:7999/1/config/set?emulate_motion=0

where able to execute correctly saving pictures, movies, sending emails etc

saving pictures only when emulate_motion is set to 1 and not when the the Pi is actively processing the video stream, and detecting motion in the image

What I would like to do is constantly stream using MotionEye whilst using a PIR sensor connected to the GPIO to trigger video recording for a certain timeframe AFTER motion is detected, like how Motion does with the post_capture and post_gap settings.

Is this possible by using the above method? Or another suggested by @jasaw ?

Thanks! I'd really appreciate the help, I'm just learning RPi and just have the last piece of the puzzle to make my Bird box stream work!! :)

avanc commented 4 years ago

I added @jasaw 's script with some modifications to a git repository to have all the information spread across issues (https://github.com/ccrisan/motioneye/issues/31) at a central place: https://github.com/avanc/motioneye-pir

Feedback is always welcome!

Interestingly, it also works if motion detection is deactivated within motionEye. This is in contrast to the observations at https://github.com/ccrisan/motioneyeos/issues/842#issuecomment-513788717

jedtrently commented 4 years ago

I added @jasaw 's script with some modifications to a git repository to have all the information spread across issues (ccrisan/motioneye#31) at a central place: https://github.com/avanc/motioneye-pir

Feedback is always welcome!

Interestingly, it also works if motion detection is deactivated within motionEye. This is in contrast to the observations at #842 (comment)

Thank you very much! I will definitely implement this when the current system is renewed!!

enry86cami commented 2 years ago

@stefi01 If you want your PIR sensor to trigger motion detection and start recording, do this:

  1. Write some python code that reads the GPIO of your PIR output.
  2. On PIR trigger, run curl "http://localhost:7999/1/config/set?emulate_motion=1".
  3. When PIR stops triggering, run curl "http://localhost:7999/1/config/set?emulate_motion=0".

Hello, I'm trying to start a recording with: curl "http://192.168.0.10:8085/1/config/set?emulate_motion=1" where 192.168.0.10 is the ip of my raspberry running motioneye and 8085 is the port of the camera. In motioneye I configured the file storage root directory: /home/pi/mnt/video_nas/Sala and the motioneye created correctly the folder. After that I "switched on" the "movies" ; under "record mode" I selected: motion triggered

By cmd on my pc I type: curl "http://192.168.0.10:8085/1/config/set?emulate_motion=1" and I receive: "Warning: Binary output can mess up your terminal. Use "--output -" to tell Warning: curl to output it to your terminal anyway, or consider "--output Warning: " to save to a file."

And nothing happens in the folder....

starbasessd commented 2 years ago

The control port is 7999. The stream port is 8085. To turn on or off functions you need to use port 7999.

enry86cami commented 2 years ago

The control port is 7999. The stream port is 8085. To turn on or off functions you need to use port 7999.

thanks for reply, ok but how can I choose which camera start recording? if I try: curl "http://192.168.0.10:7999/1/config/set?emulate_motion=1" i receive: curl: (7) Failed to connect to 192.168.0.10 port 7999: Connection refused

starbasessd commented 2 years ago

https://motion-project.github.io/motion_config.html#OptDetail_Webcontrol curl http://IP:7999/camera#/command for your case (assuming camera 5): {IP}:{port}/{camid}/action/eventstart #Trigger a new event. curl "http://192.168.0.10:7999/5/eventstart" to end: curl "http://192.168.0.10:7999/5/eventend"

enry86cami commented 2 years ago

https://motion-project.github.io/motion_config.html#OptDetail_Webcontrol curl http://IP:7999/camera#/command for your case (assuming camera 5): {IP}:{port}/{camid}/action/eventstart #Trigger a new event. curl "http://192.168.0.10:7999/5/eventstart" to end: curl "http://192.168.0.10:7999/5/eventend"

I checked and the control port is:

# the TCP port that motion HTTP control interface listens on
motion_control_port 7999

but for example if I type: curl "http://192.168.0.10:7999/2/action/eventstart"

the reply is: curl: (7) Failed to connect to 192.168.0.10 port 7999: Connection refused

so I suppose that the command didn't been receive

starbasessd commented 2 years ago

Are you running motionEye or motionEyeOS?

enry86cami commented 2 years ago

Are you running motionEye or motionEyeOS?

motioneye

starbasessd commented 2 years ago

Edit /etc/motioneye/motion.conf: set webcontrol_port 7999 setup_mode off webcontrol_parms 2 webcontrol_localhost off webcontrol_interface 1 and save restart motioneye or reboot. Web interface for motion (port 7999) should now be active for computers on local network.

enry86cami commented 2 years ago

Edit /etc/motioneye/motion.conf: set webcontrol_port 7999 setup_mode off webcontrol_parms 2 webcontrol_localhost off webcontrol_interface 1 and save restart motioneye or reboot. Web interface for motion (port 7999) should now be active for computers on local network.

is the same... this is the file: `

starbasessd commented 2 years ago

With it set correctly if I open a browser and point to: http://ip_address:7999 I get: Motion 4.2.2 Running [6] Cameras 1 2 3 4 5 6

enry86cami commented 2 years ago

http://ip_address:7999 I also rebooted raspberry image

starbasessd commented 2 years ago

If you didn't follow the install instructions from here: https://github.com/ccrisan/motioneye/wiki/Installation You may also need to edit /etc/motion/motion.conf

starbasessd commented 2 years ago

Are you running a firewall on the 192.168.0.10? What OS are you running? Maybe Arch, or Gentoo, or something really locked down?

enry86cami commented 2 years ago

Are you running a firewall on the 192.168.0.10? What OS are you running? Maybe Arch, or Gentoo, or something really locked down?

It is instelled on a raspberry 3b with raspbian, no firewall...

starbasessd commented 2 years ago

Desktop or Lite?

enry86cami commented 2 years ago

If you didn't follow the install instructions from here: https://github.com/ccrisan/motioneye/wiki/Installation You may also need to edit /etc/motion/motion.c

Desktop or Lite?

desktop

starbasessd commented 2 years ago

Open the local browser on the Pi, and check http://localhost:7999 and in terminal try running the curl commands above...

starbasessd commented 2 years ago

I am building a Pi3B+ right now, latest Raspbian and updates and instructions from Wiki, with the changes I listed above.

enry86cami commented 2 years ago

Open the local browser on the Pi, and check http://localhost:7999 and in terminal try running the curl commands above...

On the raspberry localhost:7999 works! but not 192.168.0.10:7999.....

starbasessd commented 2 years ago

What does command ip a show in terminal on the Pi?

enry86cami commented 2 years ago

pi@raspberrypi:~ $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether b8:27:eb:ff:88:8b brd ff:ff:ff:ff:ff:ff inet 192.168.0.10/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::63aa:eb2e:6730:c243/64 scope link valid_lft forever preferred_lft forever 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000 link/ether b8:27:eb:aa:dd:de brd ff:ff:ff:ff:ff:ff

starbasessd commented 2 years ago

OK, interesting it can't find itself via IP. Can you ping 192.168.0.10?

enry86cami commented 2 years ago

OK, interesting it can't find itself via IP. Can you ping 192.168.0.10?

yes I can ping from raspberry. I can ping from pc pc also...

in the same raspberry runs a local BLYNK server and I didn't have similar problems

starbasessd commented 2 years ago

what port(s) does BLYNK use?

enry86cami commented 2 years ago

honestly I don't know... If I change the webcontrol_port from 7999 to another? for example 7888?

starbasessd commented 2 years ago

I missed a setting: edit /etc/motioneye/motioneye.conf change # whether motion HTTP control interface listens on # localhost or on all interfaces motion_control_localhost false

# the TCP port that motion HTTP control interface listens on motion_control_port 7999

Sorry, lack of caffeine.

starbasessd commented 2 years ago

restart motioneye or reboot...

starbasessd commented 2 years ago

Built a clean new Desktop image of RaspberryPiOS (2021/05/07 start) with all patches and updates. Installed motionEye from instructions at: https://github.com/ccrisan/motioneye/wiki/Install-On-Raspbian Edited /etc/motioneye/motioneye.conf changed: motion_control_localhost true to motion_control_localhost false and restarted motioneye. Can now send curl commands from both local network PCs and desktop. If I connect from local network PCs or Pi desktop browser I get: Motion 4.3.2 Running [2] Cameras 1 2

enry86cami commented 2 years ago

I missed a setting: edit /etc/motioneye/motioneye.conf change

whether motion HTTP control interface listens on

localhost or on all interfaces

motion_control_localhost false

the TCP port that motion HTTP control interface listens on

motion_control_port 7999

Sorry, lack of caffeine.

I tried to change the port to 7888 also but nothing: `

path to the configuration directory (must be writable by motionEye)

conf_path /etc/motioneye

path to the directory where pid files go (must be writable by motionEye)

run_path /var/run

path to the directory where log files go (must be writable by motionEye)

log_path /var/log

default output path for media files (must be writable by motionEye)

media_path /var/lib/motioneye

the log level (use quiet, error, warning, info or debug)

log_level info

the IP address to listen on

(0.0.0.0 for all interfaces, 127.0.0.1 for localhost)

listen 0.0.0.0

the TCP port to listen on

port 8765

path to the motion binary to use (automatically detected if commented)

motion_binary /usr/bin/motion

whether motion HTTP control interface listens on

localhost or on all interfaces

motion_control_localhost false

the TCP port that motion HTTP control interface listens on

motion_control_port 7888

interval in seconds at which motionEye checks if motion is running

motion_check_interval 10

whether to restart the motion daemon when an error occurs while communicating with it

motion_restart_on_errors false

interval in seconds at which motionEye checks the SMB mounts

mount_check_interval 300

interval in seconds at which the janitor is called

to remove old pictures and movies

cleanup_interval 43200

timeout in seconds to wait for response from a remote motionEye server

remote_request_timeout 10

timeout in seconds to wait for mjpg data from the motion daemon

mjpg_client_timeout 10

timeout in seconds after which an idle mjpg client is removed

(set to 0 to disable)

mjpg_client_idle_timeout 10

enable SMB shares (requires motionEye to run as root)

smb_shares false

the directory where the SMB mount points will be created

smb_mount_root /media

path to the wpa_supplicant.conf file

(enable this to configure wifi settings from the UI)

wpa_supplicant_conf /etc/wpa_supplicant.conf

path to the localtime file

(enable this to configure the system time zone from the UI)

local_time_file /etc/localtime

enables shutdown and rebooting after changing system settings

(such as wifi settings or time zone)

enable_reboot false

timeout in seconds to use when talking to the SMTP server

smtp_timeout 60

timeout in seconds to wait for media files list

list_media_timeout 120

timeout in seconds to wait for media files list, when sending emails

list_media_timeout_email 10

timeout in seconds to wait for zip file creation

zip_timeout 500

timeout in seconds to wait for timelapse creation

timelapse_timeout 500

enable adding and removing cameras from UI

add_remove_cameras true

enables HTTP basic authentication scheme (in addition to, not instead of the signature mechanism)

http_basic_auth false

overrides the hostname (useful if motionEye runs behind a reverse proxy)

server_name motionEye

webcontrol_port 7888 setup_mode off webcontrol_parms 2 webcontrol_localhost off webcontrol_interface 1 `

I don't know why there is this formatting....

starbasessd commented 2 years ago

I don't know. Works on my Production motionEye hub, and several test machines ( motionEye on other OSs, and RaspberryPiOS on various hardware. Can you run command: netstat -apt and report the result?

If not, my suggestion would be to start clean on a different USB or SDCard (save this setup) install RPiOS, update everything, and then just install motionEye ONLY. This would eliminate the BLYNK as being interfering, then re-add BLYNK after confirming motionEye is working.

As to the freaky text formatting, MarkUp (here in Github) thinks '#' as the first character on a line designates

BOLD

enry86cami commented 2 years ago

I don't know. Works on my Production motionEye hub, and several test machines ( motionEye on other OSs, and RaspberryPiOS on various hardware. Can you run command: netstat -apt and report the result?

If not, my suggestion would be to start clean on a different USB or SDCard (save this setup) install RPiOS, update everything, and then just install motionEye ONLY. This would eliminate the BLYNK as being interfering, then re-add BLYNK after confirming motionEye is working.

As to the freaky text formatting, MarkUp (here in Github) thinks '#' as the first character on a line designates

BOLD

here you are: pi@raspberrypi:~ $ netstat -apt (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:netbios-ssn 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:tproxy 0.0.0.0:* LISTEN - tcp 0 0 localhost:8082 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN - tcp 0 0 localhost:5939 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:8085 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN - tcp 0 0 localhost:postgresql 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:smtp 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:8765 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:microsoft-ds 0.0.0.0:* LISTEN - tcp 0 0 localhost:7999 0.0.0.0:* LISTEN - tcp 3493 0 192.168.0.10:34750 192.168.0.19:1025 ESTABLISHED - tcp 0 0 192.168.0.10:8765 192.168.10.1:1028 ESTABLISHED - tcp 0 0 localhost:33186 localhost:8085 ESTABLISHED - tcp 0 0 192.168.0.10:58972 dr-streamer.united:http ESTABLISHED - tcp 0 0 localhost:34412 localhost:5939 ESTABLISHED 962/TeamViewer tcp 37 0 localhost:8085 localhost:33186 ESTABLISHED - tcp 0 0 192.168.0.10:34128 192.168.0.24:http ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35594 ESTABLISHED - tcp 0 0 192.168.0.10:8765 192.168.10.1:1030 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35608 ESTABLISHED - tcp 0 0 192.168.0.10:56218 IE-DUB-ANX-R005.te:5938 ESTABLISHED - tcp 0 0 192.168.0.10:34380 192.168.0.:microsoft-ds ESTABLISHED - tcp 0 0 192.168.0.10:58420 RS-BEG-ANX-R005.te:5938 TIME_WAIT - tcp 0 0 localhost:postgresql localhost:35602 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35586 ESTABLISHED - tcp 0 0 192.168.0.10:51430 192.168.0.19:http ESTABLISHED - tcp 0 0 192.168.0.10:47834 192.168.0.18:rtsp ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35592 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35542 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35588 ESTABLISHED - tcp 0 0 localhost:5939 localhost:36754 TIME_WAIT - tcp 0 0 localhost:5939 localhost:34412 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35600 ESTABLISHED - tcp 0 0 192.168.0.10:ssh 192.168.0.100:9847 ESTABLISHED - tcp 0 0 192.168.0.10:58978 dr-streamer.united:http ESTABLISHED - tcp 0 0 192.168.0.:microsoft-ds 192.168.0.100:1037 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35598 ESTABLISHED - tcp 0 0 localhost:postgresql localhost:35582 ESTABLISHED - tcp 0 0 192.168.0.10:8765 192.168.10.1:1029 ESTABLISHED - tcp6 0 0 [::]:9443 [::]:* LISTEN - tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN - tcp6 0 0 [::]:http-alt [::]:* LISTEN - tcp6 0 0 [::]:ssh [::]:* LISTEN - tcp6 0 0 [::]:8440 [::]:* LISTEN - tcp6 0 0 localhost:postgresql [::]:* LISTEN - tcp6 0 0 [::]:smtp [::]:* LISTEN - tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN - tcp6 0 0 localhost:35608 localhost:postgresql ESTABLISHED - tcp6 0 0 192.168.0.10:http-alt 192.168.10.5:1026 ESTABLISHED - tcp6 0 0 localhost:35542 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35582 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35598 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35594 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35586 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35588 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35600 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35592 localhost:postgresql ESTABLISHED - tcp6 0 0 localhost:35602 localhost:postgresql ESTABLISHED -

starbasessd commented 2 years ago

Yours: tcp 0 0 localhost:7999 0.0.0.0: LISTEN Mine: tcp 0 0 0.0.0.0:7999 0.0.0.0: LISTEN 2242/motion

Something is broken. It should be listening on 0.0.0.0 (any IP address, Eth0, Wlan0, Lo) but only seems to be listening on Lo. At this point I vote for save your current setup, Install RPiOS fresh on a USB Thumb Drive, then motionEye, and see if you can get it working there.

enry86cami commented 2 years ago

Yours:

tcp 0 0 localhost:7999 0.0.0.0: LISTEN Mine: tcp 0 0 0.0.0.0:7999 0.0.0.0: LISTEN 2242/motion Something is broken. It should be listening on 0.0.0.0 (any IP address, Eth0, Wlan0, Lo) but only seems to be listening on Lo. At this point I vote for save your current setup, Install RPiOS fresh on a USB Thumb Drive, then motionEye, and see if you can get it working there.

I'm scared about this... If I try to remove and install again motioneye?

starbasessd commented 2 years ago

Don't use your current SDCard or USB stick. Use a new (different) one. Keep the current one to switch back to. Uninstalling and re-installing on the same SDCard or USB stick has a much worse chance of surviving.

enry86cami commented 2 years ago

Don't use your current SDCard or USB stick. Use a new (different) one. Keep the current one to switch back to. Uninstalling and re-installing on the same SDCard or USB stick has a much worse chance of surviving.

many thanks for your support and patience. I'll schedule this new installation soon...

enry86cami commented 2 years ago

Don't use your current SDCard or USB stick. Use a new (different) one. Keep the current one to switch back to. Uninstalling and re-installing on the same SDCard or USB stick has a much worse chance of surviving.

I checked the configuration and I missed a part.... (motion.conf). So it was only necessary:

edit /etc/motioneye/motioneye.conf and /etc/motioneye/motion.conf: In /etc/motioneye/motion.conf Change webcontrol_localhost on To webcontrol_localhost off In /etc/motioneye/motioneye.conf Change motion_control_localhost true To motion_control_localhost false

Many thanks again!