Skip to content

USB Camera Example

This example demonstrates how to use the USB Camera Device Service to connect to a USB camera and start/stop video streaming. This example uses the HP w200 Webcam.

Start the USB Camera Device Service

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

edgexpert up device-usb-camera

Device Onboarding

Once the USB Camera Device Service has been started, the USB camera HP w200 Webcam should be discovered and added to Edge Xpert. You should expect to observe similar logs as shown below:

level=INFO ts=2022-09-05T12:31:37.519054199Z app=device-usb-camera source=driver.go:498 msg="discovered device: w200_w200-SN0001"
level=INFO ts=2022-09-05T12:31:37.519465008Z app=device-usb-camera source=async.go:105 msg="Adding discovered device w200_w200-SN0001 to Metadata"
level=WARN ts=2022-09-05T12:31:39.033256776Z app=device-usb-camera source=driver.go:554 msg="Protocol property AutoStreaming not found. Use default value: false"

For further information on device discovery, refer to Dynamic Discovery.

Start Video Streaming

In order to use Core Command API, enter the following command to find the IP address of the container running the Core Command Service

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.

edgexpert ip

Start video streaming for the USB camera through the Core Command API:

curl -X PUT -d '{"StartStreaming":{"OutputVideoQuality":"5"}}' http://localhost:59882/api/v2/device/name/w200_w200-SN0001/StartStreaming
Where the request body is a JSON string for passing in video options.

The stream URI can be found through the Core Command API:

curl http://localhost:59882/api/v2/device/name/w200_w200-SN0001/StreamURI

Stop Video Streaming

Stop video streaming for the USB camera through the Core Command API:

curl -X PUT -d '{"StopStreaming":"true"}' http://localhost:59882/api/v2/device/name/w200_w200-SN0001/StopStreaming

CameraStatus Command

Use the following query to determine the status of the camera. URL parameter:

  • DeviceName: The name of the camera
  • InputIndex: indicates the current index of the video input (if a camera only has one source for video, the index needs to be set to '0')

curl -X GET http://localhost:59883/api/v2/device/name/<DeviceName>/CameraStatus?InputIndex=0 | jq -r '"CameraStatus: " + (.event.readings[].value|tostring)'
Example Output:
CameraStatus: 0

Response meanings:

Response Description
0 Ready
1 No Power
2 No Signal
3 No Color