MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Motion Detection with RaspiCam, Non-Module version

    Scheduled Pinned Locked Moved Tutorials
    47 Posts 13 Posters 51.4k Views 17 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AnduriI
      last edited by

      is it possible to use Motion to activate the screen and MMM-Facial-Recignition simultaneously? Maybe also use the on_event_start to activate some lights in the front of the MM to increase image quality…

      bheplerB 1 Reply Last reply Reply Quote 0
      • bheplerB Offline
        bhepler Module Developer @AnduriI
        last edited by

        @AnduriI It should be. The motion system will operate independently of the mirror and only controls the signal running down the HDMI cable to the monitor. The Pi camera and the Magic Mirror process are still running.

        If you create a simple python script to control the pinouts on the Pi, you should be able to switch on some simple LED lights to illuminate the front of the mirror.

        1 Reply Last reply Reply Quote 0
        • D Offline
          dam4
          last edited by yawns

          @bhepler
          Hello, I am a true n00b and I am having issues with your process for getting the Pi camera to work. I copied and pasted your first line exactly and I get the following.

          pi@raspberrypi:~ $ sudo apt-get install -y libjpeg-dev libavformat56 libavformat-dev libavcodec56 libavcodec-dev libavutil54 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
          Reading package lists... Done
          Building dependency tree
          Reading state information... Done
          Package libmysqlclient-dev is not available, but is referred to by another package.
          This may mean that the package is missing, has been obsoleted, or
          is only available from another source
          
          Package libmysqlclient18 is not available, but is referred to by another package.
          This may mean that the package is missing, has been obsoleted, or
          is only available from another source
          
          E: Unable to locate package libavformat56
          E: Unable to locate package libavcodec56
          E: Unable to locate package libavutil54
          E: Package 'libmysqlclient18' has no installation candidate
          E: Package 'libmysqlclient-dev' has no installation candidate
          pi@raspberrypi:~ $
          

          What did I do wrong? Please help and thank you in advance.

          yawnsY 1 Reply Last reply Reply Quote 0
          • yawnsY Offline
            yawns Moderator @dam4
            last edited by

            @dam4
            Are you running raspbian Jessie or Stretch?

            Looks like the names where changed
            Jessie: https://packages.debian.org/jessie/libmysqlclient-dev
            Stretch: https://packages.debian.org/stretch/default-libmysqlclient-dev

            D 1 Reply Last reply Reply Quote 1
            • D Offline
              dam4 @yawns
              last edited by

              @yawns I am pretty sure I am running Jessie. How do I know for sure?

              yawnsY 1 Reply Last reply Reply Quote 0
              • yawnsY Offline
                yawns Moderator @dam4
                last edited by

                @dam4
                In the terminal run cat /etc/os-release

                Maybe you need to run sudo cat /etc/os-release

                D 1 Reply Last reply Reply Quote 0
                • D Offline
                  dam4 @yawns
                  last edited by yawns

                  @yawns
                  It looks like I am running stretch. This is what I get;

                  pi@raspberrypi:~ $ cat /etc/os-release
                  PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
                  NAME="Raspbian GNU/Linux"
                  VERSION_ID="9"
                  VERSION="9 (stretch)"
                  ID=raspbian
                  ID_LIKE=debian
                  HOME_URL="http://www.raspbian.org/"
                  SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
                  BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
                  pi@raspberrypi:~ $
                  
                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    jasonarends @dam4
                    last edited by jasonarends

                    @dam4 I had the same problem and couldn’t get the correct dependencies resolved, but I just got it to work on stretch by following the Abbreviated Building Guide instructions here: http://htmlpreview.github.io/?https://github.com/Motion-Project/motion/blob/master/motion_guide.html

                    I had already tried the way you did so I had the motion.conf from the other build which I had modified, and it worked with that version.

                    edit:

                    sudo apt-get install autoconf automake build-essential pkgconf libtool libzip-dev libjpeg-dev git libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libavdevice-dev
                    cd ~ 
                    git clone https://github.com/Motion-Project/motion.git 
                    cd motion 
                    autoreconf -fiv 
                    ./configure 
                    make 
                    make install
                    
                    D 1 Reply Last reply Reply Quote 0
                    • D Offline
                      dam4 @jasonarends
                      last edited by dam4

                      @jasonarends
                      I just tried git clone https://github.com/Motion-Project/motion.git and it tells me this;

                      fatal: destination path ‘motion’ already exists and is not an empty directory.

                      I did a ls -al and it doesn’t show up as a directory. Should I remove the ‘motion’ that is in green from the home directory and try again?

                      I have to go to work so I will have to work on this tomorrow. Thank you for your help.

                      J 1 Reply Last reply Reply Quote 0
                      • J Offline
                        jasonarends @dam4
                        last edited by

                        @dam4

                        yep, you have the original motion binary in your home directory still, you can just remove that.

                        D 2 Replies Last reply Reply Quote 0
                        • D Offline
                          dam4 @jasonarends
                          last edited by

                          @jasonarends
                          Thank you for your help. I have tried this and it seemed to install. The only thing I had an issue with was when I entered make install it would not create a directory and it failed. I then ran it as sudo make install and it seemed to install. I am running my MagicMirror now to see if it works. How long does it take to turn the monitor off? Again thank you for your help.

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            dam4 @jasonarends
                            last edited by

                            @jasonarends
                            How long does it take for the screen to blank out? So far the screen has stayed on and hasn’t even flickered. I have something in front of the Pi camera so it doesn’t pick up any movement and it has been over an hour now. Please help.

                            J 1 Reply Last reply Reply Quote 0
                            • J Offline
                              jasonarends @dam4
                              last edited by jasonarends

                              @dam4
                              Hi, make sure that you’ve edited your motion.conf file that it is using according to the instructions in the original post:

                              framerate 4 - run the detection video at 4 frames per second
                              threshold 2500 - increase the # of pixels to trigger the screen. We want them to get close to the mirror
                              minimum_motion_frames 2 - Motion must be detected in 2 consecutive frames (at 4 FPS)
                              event_gap 60 - This is important. This is how long in seconds after no motion the screen will turn off.
                              output_pictures off - Do not save images
                              ffmpeg_output_movies off - Do not record video
                              stream_port 0 - Turn off remote viewing
                              webcontrol_port 0 - Turn off HTTP control of camera
                              on_event_start vcgencmd display_power 1 - Important! This is the command to turn on the screen
                              on_event_end vcgencmd display_power 0 - Important! This is the command to turn off the screen
                              

                              I’ve copied my config here: https://pastebin.com/61hiygKX (edit: updated conf)
                              If you put motion.conf in /etc/motion it should pick it up by default without having to specify anything.

                              Make sure you’ve set the event_gap, on_event_start, and on_event_end at the very least for testing.

                              You can also just try running the command

                              vcgencmd display_power 0
                              

                              by itself to make sure the command works to turn off the monitor.

                              D 1 Reply Last reply Reply Quote 0
                              • D Offline
                                dam4 @jasonarends
                                last edited by dam4

                                @jasonarends
                                My motion.conf is located in my home directory. I looked for /etc/motion and I don’t have a directory called motion in /etc. So I made one and put motion.conf in there. My screen still doesn’t shut off. I did look over my motion.conf file and all my settings were exactly like yours. I did follow all the steps at the beginning of this post. I can also type in vcgencmd display_power 0 and it turns off the monitor and vcgencmd display_power 1 turns it back on. This is really getting frustrating. Thank you for your help.

                                I also copied your updated_motion.conf.sh and double checked it and they match with the exception yours has a .sh at the end where mine does not. Is it supposed to have the .sh on the end of the file name or did it get added due to it being uploaded?

                                J 1 Reply Last reply Reply Quote 0
                                • J Offline
                                  jasonarends @dam4
                                  last edited by

                                  @dam4
                                  Does your camera work outside of motion? Can you do

                                  raspistill -o cam.jpg
                                  

                                  and get a picture?

                                  If so, try launching motion with:

                                  /usr/local/bin/motion -c /etc/motion/motion.conf
                                  

                                  just to be sure that it’s reading the correct file, and then if you can watch the output and paste it here (or pastebin if it’s large) it might help us troubleshoot.

                                  Here’s what the first part of mine looks like with some of the config stuff cut out:

                                  [27690520:motion] [NTC] [ALL] motion_startup: Motion 4.0.1+gitb103dc0 Started
                                  [27690520:motion] [NTC] [ALL] motion_startup: Logging to syslog
                                  [27690520:motion] [NTC] [ALL] motion_startup: Using log type (ALL) log level (INF)
                                  [27690520:motion] [INF] [ALL] conf_output_parms: Writing configuration parameters from all files (1):
                                  [27690520:motion] [INF] [ALL] Thread 0 - Config file: /etc/motion/motion.conf
                                  ---snip---
                                  [0:motion] [NTC] [ALL] main: Camera ID: 0 is from /etc/motion/motion.conf
                                  [0:motion] [NTC] [ALL] main: Camera ID: 0 Camera Name: (null) Device: /dev/video0
                                  [0:motion] [NTC] [ALL] main: Waiting for threads to finish, pid: 30877
                                  [1:ml1] [NTC] [ALL] motion_init: Camera 0 started: motion detection Enabled
                                  [1:ml1] [NTC] [VID] vid_start: Opening MMAL cam
                                  [1:ml1] [NTC] [VID] mmalcam_start: MMAL Camera thread starting... for camera (vc.ril.camera) of 640 x 480 at 4 fps
                                  [1:ml1] [NTC] [VID] create_camera_component: MMAL camera component created
                                  [1:ml1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
                                  [1:ml1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 2 items
                                  [1:ml1] [INF] [ALL] mlp_detection: Lightswitch detected
                                  [1:ml1] [INF] [EVT] event_new_video: Source FPS 4
                                  [1:ml1] [NTC] [ALL] motion_detected: Motion detected - starting event 1
                                  
                                  
                                  D 1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    dam4 @jasonarends
                                    last edited by dam4

                                    @jasonarends
                                    I did get a picture when I typed that in so I know my camera is working.

                                    Here is the link to my config stuff.

                                    config stuff

                                    it sits there and my screen never blanked out, but I did notice that when I moved the block in front of the camera it did do something and when I put it back it did shut off the monitor.

                                    J 1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      jasonarends @dam4
                                      last edited by

                                      @dam4 sounds like it might be working - especially based on these lines:

                                      [1:ml1] [NTC] [ALL] motion_detected: Motion detected - starting event 1
                                      display_power=1
                                      ...
                                      [1:ml1] [NTC] [ALL] mlp_actions: End of event 1
                                      display_power=0
                                      

                                      I found a couple other config options and I think I was able to disable all the “event_newfile: File of type 2 saved to: /run/shm/lastsnap.jpg” stuff. I wonder if that’s what was causing memory leaks for @bhepler I set the pre_capture and post_capture to 0

                                      You might need to play with some of the settings for threshold and event_gap to get it to behave like you want but it sounds like you’re almost there. I set mine up in pm2 like mentioned earlier in the thread and it’s been working fine for the last day for me.

                                      D 2 Replies Last reply Reply Quote 1
                                      • D Offline
                                        dam4 @jasonarends
                                        last edited by

                                        @jasonarends
                                        How would I set it up in pm2? I’d like to try it.

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          dam4 @jasonarends
                                          last edited by yawns

                                          @jasonarends
                                          I feel I am so close I followed the instructions exactly and I have motion started in pm2. it still doesn’t work. As I checked the motion-error-2.log I am seeing the following;

                                          Error: Cannot find module '/home/pi/motion'
                                              at Function.Module._resolveFilename (module.js:469:15)
                                              at Function.Module._load (module.js:417:25)
                                              at Object. (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:73:21)
                                              at Module._compile (module.js:570:32)
                                              at Object.Module._extensions..js (module.js:579:10)
                                              at Module.load (module.js:487:32)
                                              at tryModuleLoad (module.js:446:12)
                                              at Function.Module._load (module.js:438:3)
                                              at Module.runMain (module.js:604:10)
                                              at run (bootstrap_node.js:383:7)
                                          

                                          This is displayed over and over. I have checked for the directory /home/pi/motion and it is there. What am I missing?

                                          bheplerB 2 Replies Last reply Reply Quote 0
                                          • bheplerB Offline
                                            bhepler Module Developer @dam4
                                            last edited by

                                            This post is deleted!
                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy