Skip to content

ONVIF PTZ Camera with Position Tour Example

Overview

The following example is the usage of the property positionTour, see positionTour usage for more information.

Prerequisites

  • Prepare the local storage for camera On your Edge Node, prepare a storage for storing the camera data.For example, create a local storage as below.
mkdir -p /home/edge-node/camera
# since device service and app service will access this storage, so change the storage permission
chmod 777 /home/edge-node/camera
  • To configure the ONVIF Camera Device Service to connect to the PTZ camera using the correct "username" and "password", you must first create a local docker-compose.yml file. This can be achieved by copying the following content and saving it to your working directory.
version: '3.7'
services:
  device-onvif-camera:
    environment:
      WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_MODE: usernametoken
      WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_USERNAME: <your_camera_username>
      WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_PASSWORD: <your_camera_password>
    volumes:
      - /home/$your_node_name/camera:/camera/data:rw

Start the ONVIF Camera Device Service

To start the ONVIF Camera Device Service, enter the following command:

edgexpert up device-onvif-camera

Note

The ONVIF Camera Device Service will create a default profile onvif-camera for general usage.

Device Onboarding

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \
  -d '[
        {
        "apiVersion":"v2",
        "device":{
            "name":"Camera001",
            "profileName":"onvif-camera",
            "serviceName":"device-onvif-camera",
            "protocolName":"onvif",
            "description":"onvif conformant camera",
            "adminState":"UNLOCKED",
            "operatingState":"UP",
            "protocols":{
                "onvif":{
                    "Address":"<your_camera_address>",
                    "Port":"<your_camera_port>"
                }
            },
            "properties":{
                "positionTour":{
                    "interval":"1m",
                    "positions":[
                    {
                        "duration":"5s",
                        "cameraAction":{
                            "action":"takeSnapshot",
                            "storagePath":"/camera/data/snapshot"
                        },
                        "position":{
                            "x":10,
                            "y":0,
                            "z":0
                        }
                    },
                    {
                        "duration":"5s",
                        "cameraAction":{
                            "action":"takeSnapshot",
                            "storagePath":"/camera/data/snapshot"
                        },
                        "position":{
                            "x":30,
                            "y":0,
                            "z":0
                        }
                    },
                    {
                        "duration":"5s",
                        "cameraAction":{
                            "action":"recordVideo",
                            "duration":"10s",
                            "storagePath":"/camera/data/video"
                        },
                        "position":{
                            "x":-30,
                            "y":0,
                            "z":0
                        }
                    }
                    ]
                }
            }
        }
        }
      ]'

Monitor the Remote Storage

After onboarding the device, you can access to your edge node and check if there're photos and videos on /home/$your_node_name/camera as shown below:

  • Go to the directory snapshot and there will be photos taken by your camera:
cd snapshot
Camera001_1704713397.jpg  Camera001_1704760677.jpg  Camera001_1704807957.jpg
Camera001_1704713406.jpg  Camera001_1704760685.jpg  Camera001_1704807965.jpg
  • Go to the directory video and there will be videos taken by your camera:
cd snapshot
Camera001_1704713356.mp4  Camera001_1704750316.mp4  Camera001_1704787276.mp4
Camera001_1704713418.mp4  Camera001_1704750375.mp4  Camera001_1704787336.mp4