element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog PiIoT - DomPi 15: IPCam Integration
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mg.sergio
  • Date Created: 28 Aug 2016 12:48 AM Date Created
  • Views 1050 views
  • Likes 1 like
  • Comments 4 comments
  • piiot
  • piiot challenge
Related
Recommended

PiIoT - DomPi 15: IPCam Integration

mg.sergio
mg.sergio
28 Aug 2016

During these last 2 days and before the official end of the Challenge, I have managed to integrate my Foscam IPCam into the DomPi project. This will probably be the last post with some solid progress. Let´s go into the details!

 

Previous Posts

PiIoT - DomPi: ApplicationPiIoT - DomPi: IntroPiIoT - DomPi 02: Project Dashboard and first steps in the Living room
PiIoT - DomPi 03: Living room, light control via TV remotePiIoT - DomPi 04: Movement detection and RF2.4Ghz commsPiIoT - DomPi 05: Ready for use Living Room and parents and kids´ bedrooms
PiIoT - DomPi 06: Setting up the Command Center - RPI3PiIoT - DomPi 07: Setting up the Command Center (2)PiIoT - DomPi 08: Setting up the Command Center (3) openHAB, mosquitto, RF24
PiIoT - DomPi 09: Presence EmulatorPiIoT - DomPi 10: Garage node (slave)PiIoT - DomPi 11: Ready to use. Garage node (master & slave)
PiIoT - DomPi 12: Ready to use. Control Panel and Garden NodePiIoT - DomPi 13: Ready to use. DomPi Phase 1PiIoT - DomPi 14: Presence Identification, Welcome Home and Temperature Alarm

 

Project Status

image

Foscam IPCam integration

At home I have an IPCam like the one in the picture below. The reason for leveraging this ipcam instead of the PiCam is based on two points:image

  • Redundancy. This ipcam is in itself a standalone alarm system, meaning, you can configure it to detect motion, raise an alarm and send you an email - among many other features. By using the alarm feature of DomPi together with the alarm system of the IPCam I have two different devices, if one fails (crashes, looses connectivity, it is hacked, it dies, etc) I still have the second system to monitor my home
  • Range. The IPCam includes a motor and it can rotate to cover a wider range. I am leveraging this function to cover two zones with a single camera: the living room and the corridor. By monitoring these two rooms, I am covering the "hot places" at home and those where it is more probably that someone would break in: the main entrance and the garden. Below you can see a diagram which shows the current position of the IPCam and both monitored zones. In green the living room and by asking the IPCam to move to the second position, the corridor with the main entrance in purple

image

IPCam configuration

The first step to integrate the camera is to configure it using the web interface that Foscam includes. I will skip the basic configuration steps like the user and password, or IP configuration. Specially relevant for the DomPi project is to set up the preset points. A preset point is a position of the camera indicated on the X and Y axis so that it points to the desired place. In my case, I am setting up two preset positions: the preset to point at the living room and the preset to point at the corridor (and main entrance). I have placed the ipcam on top of my fridge where I can cover these two places with the same camera.

 

The web interface of IPCam is quite intuitive and adding a preset point is  easy, you just need to move the camera with the web buttons to the desired positions and save them. It is important to remember the names you save them with, as they will be the key part of the openHAB integration. There are some other interesting features to configure: sensitivity level (to trigger the alarm if motion is detected), trigger interval (how many seconds to wait before raising a new alarm), etc. I will touch these later on during the openHAB integration.

 

imageimage

Before leaving the IPCam configuration, I have configured the email account where the Foscam camera has to send the pictures to. I have also configured my router to always assign the same IP to this camera since it will be required for the openHAB.

 

Foscam IPCamera CGI

My camera supports CGI string requests and the manufacturer has provided the CGI manual (here). This enables the control of the IPCam via http requests sent out from the openHAB. An example of these strings can be:

http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&linkage=7&snapInterval=2&sensitivi…

 

With this line, the IPCam will enable the Motion detection (see the &isEnable=1 part). If the motion is detected, it will inform the user via an email, it will also take a picture of the image and attache it to the email and finally it will also ring the ipcam´s buzzer (see the &linkage=7), etc, etc. To make it easier to follow, please find a snapshot of the above CGI manual that explains the setMotionDetectConfig parameter.

 

imageimage

 

In the openHAB I am using the setMotionDetectConfig function, as well as two other more: getDevState (to check if there is motion detected) and the ptzGotoPresetPoint (to point the ipcam at the living room or the corridor).

 

openHAB Integration

There is as such no openHAB binding, however, there is a nice webpage with key information to help you move faster on understanding how to integrate the camera (here). For DomPi, I just need the three functions below, so I have decided to implement it in a maybe not very sexy way, but... it works. I have created four items:

  • One switch: to enable or disable the Foscam IPcam alarm. When the switch is turned on, it sends to the camera the below cgi string that instructs the ipcam to start detecting motion. If turned off, it sends the "OFF:GET:..." string to the camera which stops the detection
  • One switch: to move the camera to the preset position of the living room or the corridor. If the switched is moved to the "On" position, DomPi points the camera at the living room. If it is moved to "off", the camera will point at the corridor
  • One string: that captures the motion alarm status: not enabled, no motion detected, detected motion
  • One string: to capture the sound alarm status: not enabled, no sound heard, heard sound

Here is the code at the .items file:

/* Foscam IPCam */
String Foscam_Motion     "Movimiento IPCam [MAP(ipcam.map):%s]"    <camera> (gStatus, gFoscam)     { http="<[http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USER&pwd=PASSWORD:4000:REGEX(.*?<motionDetectAlarm>(.*?)</motionDetectAlarm>.*)]" }
String Foscam_Sound     "Sonido IPCam [MAP(ipcam.map):%s]"         <camera> (gStatus, gFoscam)     { http="<[http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USER&pwd=PASSWORD:4000:REGEX(.*?<soundAlarm>(.*?)</soundAlarm>.*)]" }
Switch Foscam_Move        "Apuntar IPCam"                            <camera> (gStatus, gFoscam)     { http=">[ON:GET:http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=salon&usr=USER&pwd=PASSWORD] >[OFF:GET:http://foscam_IPaddress/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=pasillo&usr=USER&pwd=PASSWORD]"}
Switch Foscam_AlarmSwitch    "Habilitar Alarma IPCam"            <shieldalarm>    (gStatus, gFoscam)    { http=">[ON:GET:http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&linkage=7&snapInterval=2&sensitivity=1&triggerInterval=5&usr=USER&pwd=PASSWORD] >[OFF:GET:http://foscam_IPaddress:88/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=USER&pwd=PASSWORD]"}

 

I have added something new in the items description, it is the MAP, which transforms a string (0, 1 or 2 in this case) into something more user friendly: not enabled, no motion detected, detected motion. This is done via the ipcam.map file which needs to be copied into the /configurations/transform folder. The ipcam.map file looks like this:

# Map file for DomPi - IPcam Foscam
0=Disabled
1=No Alarm
2=IPCam Alarm
undefined=unknown

 

To manage the IPCam I have coded two rules. You can read the comments below. As a summary, DomPi points the camera to the living room or the corridor depending on where DomPi detects movement via the PIR sensors. The system starts by pointing the camera at the living room, with this view, the camera monitors any movement happening in the living room and covers the two doors to the garden. If any of the PIR sensors of the kids´ room or the parents´ room detects movement, then DomPi points the camera at the corridor and the main entrance.

 

Once the camera has reached any of the two preset positions (living room or corridor), it starts monitoring movement by itself. If the IPcam confirms the movement detected by the PIR, it will take a picture of the motion and email it to me. If the camera is pointing at the corridor and there is no movement after 30s, it is probably a false a larm and DomPi instructs the camera to point back at the living room.

 

All this only happens, of course, if I have turned on the Alarm switch, meaning, if I armed the alarm and want to protect my home while I am out.

 

The second rule is quite simple and just enables or disables the Foscam IPcam standalone alarm. When I activate the Alarm switch in DomPi, it automatically turns on the alarm in the ipcam. This is good as I want to avoid the camera emailing me when I am at home image

 

/*
 * Rules for IPCam movement
 * 
 */
//This rule moves the IPCam from the default position Living room to Corridor
//This happens when the alarm is active and there is some motion detected in the kids or parents rooms
//It waits 30s and confirms if ipcam has detected motion as well
//After 30s since last movement, move cam to living room
rule "Move IPCam when motion detected"
when
    Item Nodo01Movimiento changed from 0 to 1 or    //Kids room
    Item Nodo02Movimiento changed from 0 to 1    //Parents room
then
    if (Nodo09AlarmSwitch.state==ON) {
        //If alarm switch is off, this means we are not interested in monitoring presence at home
        if (Foscam_Move.state==ON) {
            //If the cam is pointing to the living room (Foscam_Move.state==ON) we move it to the corridor
            postUpdate(Foscam_Move, OFF)
            Thread::sleep(5000)        //Allow some time for the ipcam to move to its new position
        }
        ipcam_secs2go = 30        //resets timer to 30 secs
        while (ipcam_secs2go>0 && Nodo09AlarmSwitch.state==ON) {
            Thread::sleep(1000)                
            if ((Nodo01Movimiento.state==1) || (Nodo02Movimiento.state==1)) {
                //if there is still movement, reset timer to 30 secs
                ipcam_secs2go = 30
            } else ipcam_secs2go = ipcam_secs2go -1 
        }
        postUpdate(Foscam_Move, ON)    //After 30 secs with no motion, move the ipcam to the living room
    } 
end

rule "Mimic AlarmSwitch in IPCam Alarm Switch"
//Mimics any change in status of the Alarm Switch to the IPCam: 
//   If I activate the home alarm, let´s also activate the IPCam one
//   If I deactivate home alarm, let´s deactivate the IPCam one
when
    Item Nodo09AlarmSwitch changed
then
    postUpdate(Foscam_AlarmSwitch, Nodo09AlarmSwitch.state)
end

 

With this code, I am able to integrate the Foscam ipcam into DomPi. The camera includes many more features, which are not relevant to this project. One improvement if I need any of those features in the future, would be to leverage the general API from Foscam and the REST API from openHAB.

 

Additional improvements

These two days I have made one additional improvement to a previous rule. I added some fine tunning to the alarm, so that when the Alarm Switch is activated, it resets the Alarm Status by turning it off.

 

OpenHAB - Final View

These are some snapshots of the final view of the openHAB web interface for DomPi.

imageimage
imageimage
imageimage

 

Nodes´ Dashboard

This is the final dashboard of the nodes, I am conscious that not all of the cells are green, but hope that you have enjoyed the journey since May till now with the DomPi project image

image

 

Attached you can find the latest version of the openHAB files and the final part for the project!! I hope you have enjoyed the DomPi posts as much as I have done it image Many thanks to all of you that have read the posts and have shared your comments with me on the things done well and also on what could be improved. I have learned a lot! And it´s been a great pleasure. A great pleasure that I shared also with my friends and family image

Attachments:
openHAB.zip
  • Sign in to reply

Top Comments

  • rhe123
    rhe123 over 9 years ago +3
    Looks like you gave your house a great upgrade mg.sergio !
  • mg.sergio
    mg.sergio over 9 years ago in reply to rhe123 +2
    Thanks rhe123 ! Definitely yes and the touch screen is making it more attractive. I´m trying now to improve the look&feel of the control panel (with the screen). I have looked around and probably will…
  • jkutzsch
    jkutzsch over 9 years ago +1
    Curious mg.sergio , when you are creating your posts do you use the default blog editor by Element 14's website or something other? I really like how you begin each blog entry with a table of previous…
  • mg.sergio
    mg.sergio over 9 years ago in reply to jkutzsch

    Hi jkutzsch! Happy you like it image

     

    It was mcb1 back in June who gave me the idea of adding the previous post. I just created a table with the Jive actions (you know, when typing a post you have some icons, one to create tables) and removed the first line that comes by default - it is the header line which I don't need for presenting the links to the previous posts. I did it the first time for the post 6, and then I just copy-pasted it in the following posts. I thought of improving it by adding, not only the links, but also a pic with the most relevant info per post but... I was worried about the time plus I was not sure if I could easily copy/past also the images or it´d imply uploading every image...

     

    Re the project status, I had in mind sharing the nodes´ dashboard and it was DAB who suggested to add also something to display the capabilities and features I was developing. This template is just an excel file that I´m color coding, I upload just a snapshot of the relevant data.

     

    Thank you image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jkutzsch
    jkutzsch over 9 years ago

    Curious mg.sergio, when you are creating your posts do you use the default blog editor by Element 14's website or something other?  I really like how you begin each blog entry with a table of previous blog entries as well as the updated project status!  I will have to remember how well that looks for sharing information over to readers! 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mg.sergio
    mg.sergio over 9 years ago in reply to rhe123

    Thanks rhe123! Definitely yes image and the touch screen is making it more attractive. I´m trying now to improve the look&feel of the control panel (with the screen). I have looked around and probably will move away from the classical UI of the openHAB and use its REST API together with dashing. There are cool dashboards like this one.

     

    In any case also your UI looks quite cool as well image

     

    Thanks again and nice Thuis!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rhe123
    rhe123 over 9 years ago

    Looks like you gave your house a great upgrade mg.sergio!

    • Cancel
    • Vote Up +3 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