element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Modern security - motion tracking
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tekmeister
  • Date Created: 31 Aug 2014 12:07 PM Date Created
  • Views 460 views
  • Likes 1 like
  • Comments 2 comments
  • forget_me_not
  • iot_modern_security
  • raspberry-pi
Related
Recommended

Modern security - motion tracking

tekmeister
tekmeister
31 Aug 2014

I am attempting to get my challenge back on track after a few hiccups. My car is now fixed but insurance has yet to replace my laptop so my progress will still be slow. I'm also yet to receive the EnOcean Pi and sensor kit, so can't make any headway on that front.

 

This means my tasks have to shuffle around a bit, and I will work on some aspects of my project that were "time-permitting" rather than "mission-critical".

 

I currently have OpenHAB running on my RaspberryPi B+ but it was just running the demo project, ie. nothing useful.

 

Since I have a Logitech USB webcam to hand, I thought I'd look at getting basic motion detection going. I'm learning this as I go, and hopefully the info below is also useful to someone else.

 

 

Installing motion

 

Motion is a free software package designed to monitor video cameras and detect when the image is changing. Perfect for my needs.

 

Installing it on the RaspberryPi is simple:

 

sudo apt-get install motion

 

After installation, I made sure motion would run on start-up, by changing /etc/default/motion to read:

 

start_motion_daemon=yes

 

 

You may want to experiment with the resolution and framerate (also defined in motion.conf). Higher values will place a load on the CPU.

By default, motion will run at 320x240 @ 2fps - this was using about 3% of the CPU normally. I tried it at 640x480 @ 30fps, and motion was using ~45% of the CPU. For now, I'm running with 640x480 @ 2fps (~13% load), but may have to adjust this later.

 

You can check what formats your camera natively supports with the command:

 

v4l2-ctl --list-formats-ext

 

So after all that, I rebooted and checked that motion was indeed running.

 

 

Viewing the webcam stream from openHAB

This was easy thanks to a previous post from fvan. Details shamelessly copied from [CaTS] ForgetMeNot - Week 2: Elro CoCo and Pi Cam with OpenHAB. Just add the following to your sitemap:

 

Frame label="Camera" {
     Text item=Camera {
          Frame {
               Video url="http://localhost:8081" encoding="mjpeg"
          }
     }
}

 

 

Better integration with openHAB

The next step was to figure out how to get openHAB to read the motion status - ie. is there movement or not

 

Motion provides a number of events which can trigger actions. The two that I am interested in today are on_event_start, and on_event_end. These commands are specified in motion.conf and occur at the start and end of motion detection.

 

First I added a new "motionDetected" item in openHAB:

Switch  motionDetectState       "Motion Detected"

 

and added that switch to my sitemap.

 

Then I modified my motion.conf as follows:

 

on_event_start curl --max-time 2 --connect-timeout 2 --header "Content-Type: text/plain" --request PUT --data "ON" http://localhost:8080/rest/items/motionDetectState/state

on_event_end curl --max-time 2 --connect-timeout 2 --header "Content-Type: text/plain" --request PUT --data "OFF" http://localhost:8080/rest/items/motionDetectState/state

 

Essentially this gets motion to tell openHAB to set the motionDetectState when motion is detected, and then clear it when motion is no longer detected.

 

Restart motion:

sudo /etc/init.d/motion restart

 

And run openHAB. Now when motion is detected, my switch is set to ON:

image

and I can see in my logfile:

 

23:32:25.595 INFO  runtime.busevents[:26] - motionDetectState state updated to ON

 

After a minute of no activity (the default gap setting is 60 seconds), I see the following:

 

23:33:28.528 INFO  runtime.busevents[:26] - motionDetectState state updated to OFF

 

and the switch returns to the off state:

image

  • Sign in to reply
Parents
  • electronichamsters
    electronichamsters over 11 years ago

    Very nice!  I've been using a PIR motion detector to detect motion, but I've also been running Motion on a Linux box for a while now.  That's a brilliant way of getting Motion to change an indicator on OpenHAB!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • electronichamsters
    electronichamsters over 11 years ago

    Very nice!  I've been using a PIR motion detector to detect motion, but I've also been running Motion on a Linux box for a while now.  That's a brilliant way of getting Motion to change an indicator on OpenHAB!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • ravi_butani
    ravi_butani over 11 years ago in reply to electronichamsters

    I am also using motion with raspberry pi camera... and to detect motion in day as well as night I will be use Pi NoIR camera

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube