banner



How To Add A Camera To Motioneyeos

PCBWAY

Building our centralized web-controlled habitation video surveillance arrangement. Last episode

In the previous posts, defended to the creation of a video surveillance system based on Raspberry Pi and the MotionEye application, we saw how to install the software necessary for our architecture and how to configure a start video camera connected via USB and a 2d Pi Camera that can exist managed remotely, using a 2d Raspberry Pi, reachable from the local network, with MotionEye installed. We accept seen how to configure the management of alarm notifications confronting the detection of a "suspicious" motion in the expanse controlled by the video camera. In the face of an event, we have described the possibility of sending a message via email and / or executing a command or programme. Still with reference to the compages that we propose in Fig. one, in this episode we see how to expand our compages with a commercial IP camera, all ever controlled by our Raspberry Pi "concentrator". Nosotros state that the information contained in this article is of an "orientation" type to bargain with a project of this type. Those who want to reproduce what is described should take a good knowledge of the GNU / Linux world, of the TCP / IP protocol and of the Lather engineering (Elementary Object Access Protocol – it is the technology adopted for the development of Web Services, category to which ONVIF belongs). Plain, the knowledge of a footling programming in the Python language does non hurt.

Fig. i

The challenge, if we can call it that, was to be able to control a commercial IP camera from the MotionEye application. A wide range of this blazon of video cameras is bachelor, of good quality, with prices continuously falling and equipped with TCP / IP connectivity, PTZ zoom and pan (Pan, Tilt, Zoom). More often than not, for the use of these cameras, proprietary software is offered, albeit free of charge, ordinarily provided as "apps" for smartphones or PC applications. Fortunately, an increasingly widespread trend is the adoption by manufacturers of the GNU / Linux operating system and the ONVIF (Open Network Video Interface Forum) advice protocol and the RTSP (Existent-Time Streaming Protocol) video streaming protocol.

Too many acronyms? Let's proceed with the social club.

The IP camera nosotros take called is the IPC-Z06H model with the code CP728. The primary problem we encountered is the lack of documentation intended for a "maker" user, so nosotros approached the project with a "reverse" applied science approach.

Looking at the IP camera, below we have identified a label with the admission credentials to the IP camera management system, as visible in Fig. two. A first indication, better than nothing.

Fig. ii

Nosotros connected the IP camera to the local network via Ethernet cable. Clearly our local network has a DHCP server, therefore our IP photographic camera will automatically be assigned an IP address belonging to our local subnet. Yeah merely which address? To find out, you have two possibilities: either open the graphic interface of your router and go to find out which devices are currently continued and their respective IP addresses, or use the Nmap command from the GNU / Linux shell, for instance, Raspberry Pi. Nmap is a network mapping tool with numerous features, in our instance we utilize it to detect out the IP address of the IP camera and on which ports network services are bachelor. If Nmap is not installed, install it with the commands:

sudo apt update

sudo apt install nmap

So type the control:

nmap -p ane-10000 <indirizzo-IP-vostra-rete>/<CIDR>

Nmap is able to probe the open up TCP ports on each device to place the type of service offered.

The parameter -p allows to indicate the range of ports to exist scanned. In our instance from i to 10000. Normally there should be no services on the doors above 10000.

For <IP-address-your-internet> enter the "network" IP address of your local subnet, for example 192.168.178.0, for <CIDR> (Classless Inter-Domain Routing) enter the bit length of your subnet mask, for example 24 for the commonly used mask "255.255.255.0".

Among the numerous output lines we take identified the following, visible in Fig. 3:

Nmap scan written report for 192.168.178.135

Host is up (0.0017s latency).

Not shown: 9998 closed ports

PORT     STATE SERVICE VERSION

554/tcp  open  rtsp?

5000/tcp open  upnp?

Our attention on this device was drawn by the presence, on port 554 of a service with RTSP protocol, the video streaming protocol of our IP camera. At this point, suppose that the ONVIF protocol is nowadays on port 5000. In addition, we also take the IP accost of our IP room. Our goal is to be able to intercept the streaming video to be able to view it via MotionEYE and, why not, e'er from MotionEye to be able to manage the pan and tilt of the IP camera. Having no documentation in this regard, we decided to request "enlighten" from the "ONVIF" protocol itself. ONVIF is structured according to the Web service standard, or "web service", whatever you desire. A web service consists of a set of messages that a device makes available to be able to provide and receive data and commands from a 3rd-political party user, usually another device on the network that acts as a user. ONVIF messages are encoded on the basis of Lather (Uncomplicated Object Access Protocol) specifications which is an object-oriented protocol for exchanging messages between devices based on the XML format and which, in turn, more often than not relies on the HTTP protocol for network transmission.

Fig. 3

For our "investigation" we used the SoapUI (Lather User Interface) tool, an application that allows y'all to "manage" the SOAP protocol with a graphical interface that can be used by a "man" user. The specifications of the ONVIF protocol and of the dissimilar message classes are documented in the "ONVIF Core Specification" manual, which can be downloaded at: https://www.onvif.org/specs/cadre/ONVIF-Core-Specification-v250.pdf

We will not dwell on the configuration and preparation of SoapUI to interrogate the PI chamber. This would crave far more than the space of an article. We just illustrate the master steps nosotros have taken.

A few more than notes. There are currently ii versions of the ONVIF protocol, one.0 (ten) and 2.0 (20). ONVIF message classes are developed with the Spider web Services Clarification Language (WSDL) and are bachelor on the ONVIF website.

The start class of messages that we are going to utilise is the "Device Direction" class. The specifications are available at the address: https://world wide web.onvif.org/ver10/device/wsdl/devicemgmt.wsdl

Fig. 4

One time imported into SoapUI we find it as "Device Bindings".

In the "Device Bindings" class nosotros select the "GetServices" message (method). In the elevation window you can see the destination URL of the message:

http://192.168.178.135:5000

Every bit you lot tin run into, it is an HTTP asking to the IP accost of the IP camera on port 5000, which nosotros identified with the "nmap" control.

We modify the text of the request by inserting "true" in the IncludeCapability tag.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsdl="http://www.onvif.org/ver10/device/wsdl">     <lather:Header/>     <lather:Body>        <wsdl:GetServices>           <wsdl:IncludeCapability>true</wsdl:IncludeCapability>        </wsdl:GetServices>     </soap:Body>  </soap:Envelope>  After pressing the "Submit" push (greenish triangle at the summit left) nosotros get the respond:        <Lather-ENV:Header/>     <Soap-ENV:Body>        <tds:GetServicesResponse>           <tds:Service>              <tds:Namespace>http://www.onvif.org/ver10/events/wsdl</tds:Namespace>              <tds:XAddr>http://192.168.178.135:5000/onvif/device_service</tds:XAddr>              <tds:Version>                 <tt:Major>0</tt:Major>                 <tt:Minor>iii</tt:Minor>              </tds:Version>           </tds:Service>        </tds:GetServicesResponse>     </Soap-ENV:Body>  </SOAP-ENV:Envelope>

Unfortunately, the answer just partially helps us. In fact, information technology confirms that in that location is an ONVIF service on port 5000 corresponding to the address of our IP room, simply it does not tell us much about the other supported classes. We would accept liked to notice the pointer to the "middle" course among the Namespaces. Or rather to its version. From the specifications of the IP photographic camera we know that it supports the 2.0 version of ONVIF and therefore nosotros create our pointer to the "middle" form independently:

https://www.onvif.org/ver20/media/wsdl/media.wsdl

Nosotros are interested in the messages of the "middle" course because we have to identify the proper name of the configuration "Profile" defined by the manufacturers of the IP camera to personalize the ONVIF messages. We volition need to correctly make full in the letters for the pan / tilt management of the IP photographic camera. Nosotros import the "middle" class into SoapUI and configure the "GetProfiles" message. We execute the request and obtain the partially visible response in Fig. 5.

  <trt:GetProfilesResponse>           <trt:Profiles token="IPCProfilesToken0">              <tt:Name>MainStream</tt:Proper noun>                 <tt:VideoEncoderConfiguration token="VideoEncoderConfigToken0">                 <tt:Proper noun>VideoEncoderConfig0</tt:Proper name>                 <tt:UseCount>ane</tt:UseCount>                 <tt:Encoding>H264</tt:Encoding>                 <tt:Resolution>                    <tt:Width>1280</tt:Width>                    <tt:Height>720</tt:Height>                 </tt:Resolution>                 <tt:Quality>x</tt:Quality>                 <tt:RateControl>                    <tt:FrameRateLimit>30</tt:FrameRateLimit>                    <tt:EncodingInterval>i</tt:EncodingInterval>                    <tt:BitrateLimit>1200</tt:BitrateLimit>                 </tt:RateControl>

We take reported in the text the nearly important sections contained in the reply message. The first is the proper noun of the famous "configuration profile so sought after, in our case" IPCProfilesToken0 ".

Fig. 5

In the 2d section nosotros can come across the information of camera configuration, resolution, quality, frame charge per unit, etc.

In the same form the message "GetStreamURI" is also available. The response to this message tells us which URIs to utilize to intercept the IP photographic camera's video streaming stream. It volition exist useful to configure the IP photographic camera inside MotionEye. So, let's go and scan. In Fig. 6 we tin can see the answer of the message "GetStreamURI".

PCBWAY

Fig. six

Nosotros merely report the URI address that interests us:

rtsp://192.168.178.135:554/onvif1

Let's make a final check on the message that allows you to manage the pan and tilt of the IP camera. For simplicity nosotros volition employ the message "ContinuosMove" that we find in the PTZ class of ONVIF. We import it into SoapUI from the address: https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl

Allow's see the message in Fig. seven.

Fig. 7

To address it correctly we must communicate the Profile, which we have constitute previously.

<wsdl:ContinuousMove>           <wsdl:ProfileToken>IPCProfilesToken0</wsdl:ProfileToken>           <wsdl:Velocity>              <!--Optional:-->              <sch:PanTilt 10="0" y="0" space="?"/>              <!--Optional:-->              <sch:Zoom x="-1" space="?"/>           </wsdl:Velocity>           <!--Optional:-->           <wsdl:Timeout>1</wsdl:Timeout>        </wsdl:ContinuousMove>

The parameters that interest us are the "ProfileToken" that we found previously, the "PanTilt" parameter and the Timeout parameter.

The PanTilt parameter, in the "Velocity" section, is a vector that allows you to set the speed and management of move of the pan and tilt. The "x" parameter sets the horizontal pan and tilt. The values range from "-ane", maximum speed to the left to "+ane", maximum speed to the right. The value "0" means no movement. Similarly, the parameter "y" sets the vertical pan and tilt. The values also in this instance range from "-1", maximum speed upwards, to "+1", maximum speed downwards. The value "0" means no motion. The "Timeout" parameter allows y'all to configure the duration of the movement. With these parameters, nosotros will be able to configure a client programme written in Python that will allow us to "swing" the IP photographic camera from the MotionEye interface.

MotionEYE configuration for IP camera

As we take already described in the previous articles, the MotionEye web server responds to the IP address of Raspberry Pi on port 8765. Therefore, to admission your MotionEye you must open a browser, for example, Firefox, and type in the URL: http://<indirizzo-IP>:8765

where the IP accost is that of your Raspberry Pi "concentrator".

Yous will run across the usual login page visible in Fig. viii. Recall that the default MotionEye administrator is "admin", without password, so leave the password field empty.

Y'all volition meet the main page of MotionEye, (Fig. 9). Every bit known, the buttons at the tiptop left allow you to configure the cameras connected to MotionEye and to change the user. The button at the top correct is used to get out the application.

To add together the IP camera, click with the right mouse button on the field at the meridian left (see blood-red arrow) and select "Add Camera".

Fig. viii

You volition be presented with a pop-up window with the characteristics of the camera you want to configure.

Fig. 9

Several possibilities are available. For each, a specialized configuration mode opens, where y'all can specify paths and credentials to access the photographic camera itself. In our instance, since information technology is an IP Camera connected via a network, select "Network Camera" and as the URL, enter the one found past the message "GetStreamURI". As Username and Countersign, enter those indicated on the characterization applied to the IP camera or that indicated by the manufacturer. If everything went in the correct management, the camera will be recognized as RTSP / TCP Camera (Fig. 10). In our case, in the "Camera" field we had to select the "RTSP / UDP Photographic camera" selection.

Ostend and you lot will be presented with the bill of fare with all the available configuration sections. In the meantime, you tin see the images taken past the IP camera, together with the other configured cameras, on the main page of MotionEye.

In the "Video Device" section, give a proper name to the IP camera, in our case we have called it "CameraIP". Accept note of the number that appears in the "Camera ID" field. Nosotros volition need information technology later to configure the pan and tilt functionality. Go out the other configuration sections disabled, except for the "Text Overlay" department. It does not make much sense to set up the interception of movement for a room that is itself to move. How well-nigh?

Fig. 10

Python-onvif installation

It is time to deal with the pan and tilt of the PI bedchamber. MotionEye provides a series of "actions" that can be used to perform boosted operations. Each action, if activated, materializes with the presence of a push in the window relating to the video camera to which you want to acquaintance the specific action.

  • lock
  • unlock
  • light_on
  • light_off
  • alarm_on
  • alarm_off
  • up
  • right
  • down
  • left
  • zoom_in
  • zoom_out
  • preset1 to preset9

To activate an action information technology is necessary to insert a file in the configuration binder of MotionEye (/ etc / motioneye), the name of which is equanimous of the name of the activeness followed by the underscore character and the "Camera ID" of the camera to which y'all wants to acquaintance the activeness itself.

The crush (bash) commands relating to the functions to be associated with the action must exist inserted within the file. For the pan and tilt of the IP camera we will use the deportment:

  • upward
  • right
  • down
  • left

For this we volition insert the Bash scripting files in the / etc / motioneye folder: up_3, right_3, down_3 and left_3. At the startup MotionEye, given the presence of these files in its configuration folder, it will insert the relative activation buttons, at the bottom right, in the IP camera window. In order to manage the pan and tilt of the IP photographic camera it is necessary to create a client that allows you to talk with the web services of the IP photographic camera itself. The "python-onvif" project is bachelor in the GitHub repository, which is an implementation in Python of an ONVIF client. The project is fabricated available, with MIT license, by Quatanium Engineering science Co. Ltd., which we mention and thank for the piece of work done. To install python-onvif type the commands:

sudo apt update

sudo apt dist-upgrade

Install "suds", a python client to manage SOAP messaging:

pip install 'suds>=0.four'

pip install suds-passworddigest

Install python-onvif

pip install onvif

At the get-go, we experienced the directly call to the "ContinuousMove" grade, each time a button was clicked the response times were incomparably also long, largely due to the creation of the ONVIFCamera object (see List 1).

Listing 1

#!/usr/bin/python from onvif import ONVIFCamera import sys from socket import * myHost = '192.168.178.119' # IP RPI myPort = 5555 # Camera object with connection parameters mycam = ONVIFCamera('192.168.178.135', 5000, '15986051', '123') # Direction and speed of movements XMAX = one # right XMIN = -1 # left YMAX = 1 # hight YMIN = -1 # low tmov = 0 # default motion duration # Create ptz servic objecte ptz = mycam.create_ptz_service() request = ptz.create_type('ContinuousMove') # instanza messaggio ONVIF request.ProfileToken = "IPCProfilesToken0" # Profile camera IP south = socket(AF_INET, SOCK_STREAM) # creates a TCP socket s.bind((myHost, myPort)) # demark IP and port s.listen(5) # accepts 5 simultaneous connections  while one: # expect for next client to connect connection, address = s.accept() # accept connexion from client while one: comando = connexion.recv(1) # receives a character if (comando == 'd'): # destra print 'motility right...' request.Velocity.PanTilt._x = XMAX request.Velocity.PanTilt._y = 0 request.Timeout = tmov if (comando == 's'): #left impress 'move left...' asking.Velocity.PanTilt._x = XMIN request.Velocity.PanTilt._y = 0 request.Timeout = tmov if (comando == '1000'): # depression print 'move down...' request.Velocity.PanTilt._x = 0 asking.Velocity.PanTilt._y = YMAX request.Timeout = tmov if (comando == 'u'): # hight impress 'motility up...' request.Velocity.PanTilt._x = 0 request.Velocity.PanTilt._y = YMIN request.Timeout = tmov # Send a messagge ContinuousMove at camera IP ptz.ContinuousMove(request) comando = '' break connectedness.shut() # shut socket

Consequently, we decided to create a "server" program that initializes the ONVIFCamera grade only once and waits for requests from an intermediate program on TCP / IP socket, port 5555, which is in turn called by the activated scripts. from the buttons. Fig. 12 shows the architecture of the software objects used to manage the pan and tilt of the IP Photographic camera. When a pan and tilt button is pressed in the IP Camera screen, the "Bash" script respective to the required activity is executed. For case, in case of move to the right, the "right_3" script will be activated, which in turn calls the "onvif_cli.py" program by passing it the "right" parameter. Same for the other movements. In Listings 3, four, 5 and half dozen y'all tin run into the very simple content of each script or the invocation of the onvif_cli.py program with the parameter that requires the execution of the respective move of the IP camera.

Fig. 12

The "onvif_cli.py" programme is visible in Listing ii. When called by one of the scripts associated with the buttons, information technology analyzes the content of the parameter passed by each script, packages a request for the server "onvif_server.py", creates a client session via socket, always towards the server and sends the relative swivel request. At this point, the "onvif_server.py" server composes the ONVIF message corresponding to the requested action and delivers it to the "python-onvif" and "python-suds" component concatenation which provide the effective transmission to the IP Camera. The upshot is the movement of the Camera in or in the required directions and the consequent modify of angle of the displayed epitome.

Listing two

#!/usr/bin/python import sys from socket import * serverHost = '192.168.178.119' # IP address server serverPort = 5555 # port server comando = sys.argv[1] print comando # only for debug muovi = 'ten' if (comando == 'destra'): print 'move correct...' muovi = 'd' if (comando == 'sinistra'): print 'move left...' muovi = 's' if (comando == 'giu'): muovi = 'g' if (comando == 'su'): print 'move up...' muovi = 'u' s = socket(AF_INET, SOCK_STREAM) # create a TCP socket s.connect((serverHost, serverPort)) # connect to server on the port southward.transport(muovi) # send request to server

The request message is of a single grapheme, the pregnant of which is easy to understand by analyzing Listing ii.

In Fig. thirteen you tin see what the contents of the / etc / motioneye folder should look similar.

Fig. 13

To launch the onvif_server.py program automatically at the get-go of Raspbian, insert the server execution directive in the configuration file of the Cron scheduler.

Open the Cron scheduler configuration file with the control:

crontab -due east

At the end of the text insert the declaration:

@reboot nohup python /home/pi/onvif_server.py  > /dev/nada &

Shut with <CTRL-ten> and confirm. Reboot and reopen the MotionEye page. In our case, information technology is possible to encounter the images taken past the three cameras.

Listings iii, 4, v and half-dozen

List 3 - right_3 #!/bin/bash nohup python /dwelling house/pi/onvif_cli.py destra > /dev/goose egg & Listing four - up_3 #!/bin/fustigate nohup python /home/pi/onvif_cli.py su > /dev/nada & Listing 5- left_3 #!/bin/bash nohup python /habitation/pi/onvif_cli.py sinistra > /dev/null & Listing six- down_3 #!/bin/bash nohup python /home/pi/onvif_cli.py giu > /dev/zero &

To arrange them as in Fig. xiv, use the "Layout Rows" cursor in the "Preferences" configuration department. By clicking on whatever image, yous tin can see all the buttons associated with each room. The ones to be used for the pan and tilt are the iv at the lesser correct of the CameraIP image.

Fig. 14

Deepening the available features even more than and using a hard disk equally mass memory for Raspberry Pi and, why non, a UPS to guarantee continuity of ability, we can create an integrated video surveillance arrangement with practically professional person features.

From openstore

Raspberry Pi 3 Model B+

Camera module viii Megapixel for Raspberry Pi

Raspberry Pi NoIR Infrared Photographic camera Lath v2.1 (8MP, 1080p)

OpenStore

Virtually Boris Landoni

Boris Landoni is the technical manager of Open up-Electronics.org. Skilled in the GSM field, embraces the Open up Source philosophy and its projects are available to the community.

Source: https://www.open-electronics.org/cctv-with-raspberry-pi-and-motioneye-2/

Posted by: moorechavir49.blogspot.com

0 Response to "How To Add A Camera To Motioneyeos"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel