The virtual device service simulates different kinds of devices to generate events and readings to the core data micro service, and users send commands and get responses through the command and control micro service. These features of the virtual device services are useful when executing functional or performance tests without having any real devices.
The virtual device service, built in Go and based on the device service Go SDK, can simulate sensors by generating data of the following data types:
- Bool, BoolArray
- Int8, Int16, Int32, Int64, Int8Array, Int16Array, Int32Array, Int64Array
- Uint8, Uint16, Uint32, Uint64, Uint8Array, Uint16Array, Uint32Array, Uint64Array
- Float32, Float64, Float32Array, Float64Array
By default, the virtual device service is included and configured to run with all EdgeX Docker Compose files. This allows users to have a complete EdgeX system up and running - with simulated data from the virtual device service - in minutes.
Using the Virtual Device Service
The virtual device service contains 4 pre-defined devices as random value generators:
These devices are created by the virtual device service in core metadata when the service first initializes. These devices are defined by device profiles that ship with the virtual device service. Each virtual device causes the generation of one to many values of the type specified by the device name. For example, Random-Integer-Device generates integer values: Int8, Int16, Int32 and Int64. As with all devices, the deviceResources in the associated device profile of the device defind what values are produced by the device service. In the case of Random-Integer-Device, the Int8, Int16, Int32 and Int64 values are defined as deviceResources (see the device profile).
Additionally, there is an accompanying deviceResource for each of the generated value deviceResource. Each deviceResources has an associated EnableRandomization_X deviceResource. In the case of the integer deviceResources above, there are the associated EnableRandomization_IntX deviceResources (see the device profile). The EnableRandomization deviceResources are boolean values, and when set to true, the associated simulated sensor value is generated by the device service. When the EnableRandomization_IntX value is set to false, then the associated simulator sensor value is fixed.
The Enable_Randomization attribute of resource is automatically set to false when you use a
PUT command to set a specified generated value. Furtehr, the minimum and maximum values of generated value deviceResource can be specified in the device profile. Below, Int8 is set to be between -100 and 100.
description: "Generate random int8 value"
For the binary deviceResources, values are generated by the function rand.Read(p byte) in Golang math package. The byte size is fixed to MaxBinaryBytes/1000.
Core Command and the Virtual Device Service
Use the following core command service APIs to execute commands against the virtual device service for the specified devices. Both
PUT commands can be issued with these APIs.
GET command request the next generated value while
PUT commands will allow you to disable randomization (EnableRandomization) and set the fixed values to be returned by the device.
Port 59882 is the default port for the core command service.
Please refer to the general Common Configuration documentation for configuration properties common to all services.
For each device, the virual device service will contain a DeviceList with associated Protocols and AutoEvents as shown by the example below.
|properties used in defining the static provisioning of each of the virtual devices
|name of the virtual device
|device profile that defines the resources and commands of the virtual device
|'Example of Device Virtual'
|description of the virtual device
|labels array used for searching for virtual devices
|address for the virtual device
|properties used to define how often an event/reading is schedule for collection to send to core data from the virtual device
|every 15 seconds
|collect data regardless of change
|deviceResource to collect - in this case the Int8 resource