Skip to content

ONVIF Camera Example with simulator

ONVIF simulator

The ONVIF Camera Device Service example demonstrates onboarding the ONVIF simulator.

Before running this example, ensure that simulator is configured and running as described in the ONVIF Simulator section.

Preconfiguration

To configure the ONVIF Camera Device Service to use the correct username and password for connecting the ONVIF simulator, 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_USERNAME: admin
      WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_PASSWORD: admin
  • WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_USERNAME used to set up default username
  • WRITABLE_INSECURESECRETS_CREDENTIALS001_SECRETS_PASSWORD used to set up default password

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

Once the Device Service has been started, devices can be onboarded to Edge Xpert using either the Edge Xpert Manager UI or through Edge Xpert REST API commands. Instructions on how to use both methods are described below.

Device Onboarding with the Edge Xpert Manager UI

Note

Please refer to the Edge Xpert Manager UI Device Management capability for full details.

  1. Ensure the Edge Xpert Manager UI is started, for example:

    edgexpert up xpert-manager
    
  2. Open a browser and go to localhost:9090. The default username and password is admin

  3. Onboard the device using the device onboarding capability. The following values can be used to provision the example device:

Field Example Value Description Required
Name onvif-sim The unique name used to identify the device Required
Description Simulation of a ONVIF camera Any additional information about the device Optional
Label ONVIF Any additional information about the device Optional
Address 172.17.0.1 The IP address of the ONVIF camera Required
Port 10000 The port number of the ONVIF camera Required
MACAddress It will be set to empty string if no value is provided, or it will be set with the MAC address value of the camera if valid credentials are provided.
The user can pre-define this field in the ProtocolProperties
Optional
FriendlyName It is initialized to be empty or "Manufacturer+Model" if credentials are provided on discovery.
The user can also pre-define this field in the ProtocolProperties
Optional
Device Profile onvif-camera The name of the device profile Required
Device Service device-onvif-camera The name of the appropriate device service Required
Auto Events Interval: 5s

OnChange: false

ResourceName: Snapshot
Automated events to retrieve the data at specific frequencies

Note: If OnChange is set to true, values will only be pushed if a change in value has occurred during the specified interval. If set to false, values will be sent on the specified interval regardless of if there has been a change
Optional

Device Onboarding with the Edge Xpert REST API

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.

Onboard the device using similar values as explained in the above table:

curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \
  -d '[
        {
          "apiVersion": "v2",
          "device": {
            "name": "onvif-sim",
            "description":"Simulation of a ONVIF camera",
            "labels":[
              "ONVIF"
            ],
            "adminState": "UNLOCKED",
            "operatingState": "UP",
            "protocols": {
              "onvif": {
                "Address": "172.17.0.1",
                "Port": "10000"
              }
            },
            "serviceName": "device-onvif-camera",
            "protocolName":"onvif",
            "profileName": "onvif-camera",
            "autoEvents": [
              {
                "interval": "5s",
                "onChange": false,
                "sourceName": "Snapshot"
              }
            ]
          }
        }
      ]'

Device Data Flow

Once the device is onboarded to Edge Xpert, data flow between the Device Service and the connected device can be verified in a number of ways.

The Edge Xpert Manager UI supports Read and Write functionality for each device. Readings can also be viewed and queried within the Edge Xpert Manager UI Data Center.

Alternatively, you can read and write data with cURL commands or through REST API applications, such as Postman.

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.

Both the GET and PUT requests can be made to the following address:

http://localhost:59882/api/v2/device/name/{deviceName}/{commandName}

Using the example above, this could be:

http://localhost:59882/api/v2/device/name/onvif-sim/Hostname

For more information on this, see the Core Command Microservice. A list of available API commands can be found under EdgeXpert API.

Any data collected by the Device Service can then be processed like all other Edge Xpert sensor data. The data readings can be exported for data processing in a number of other applications and services. See the Supporting Services and Application Services documentation for more details.