Virtual Device Service
The Virtual Device Service simulates different kinds of devices to generate events and readings to the Core Data microservice. You can send commands and get responses through the Core Command microservice.
This allows users to process data using the Edge Xpert platform and verify that data flows to other microservices without the need for physical devices. This is especially useful for the following:
- Learning how Edge Xpert works
- Functional and performance testing
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.
Key Features
The Virtual Device Service supports the following key features:
- Reading data
- Writing data
Supported Data Types
The Virtual Device Service supports 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
- Binary
The virtual device services leverages ql(an embedded SQL database engine) to simulate virtual resources.
Note
Currently, the Virtual Device Service does not store binary values in the ql database and the generation of binary values is always randomized
Virtual Device Profiles
The following device profiles are provided for use with the Virtual Device Service:
Profile Name | YAML File |
---|---|
Random-Boolean-Device | device.virtual.bool.yaml |
Random-Integer-Device | device.virtual.int.yaml |
Random-UnsignedInteger-Device | device.virtual.uint.yaml |
Random-Float-Device | device.virtual.float.yaml |
Random-Binary-Device | device.virtual.binary.yaml |
These default device profiles are pre-loaded into the device service. They are defined in /usr/share/edgexpert/examples/device-services/virtual.
Setting Minimum and Maximum Values
The device profiles can be configured with the following device resource attributes:
Resource Attribute | Description |
---|---|
minimum |
Sets the minimum value to be generated |
maximum |
Sets the maximum value to be generated |
An example can be seen below:
deviceResources:
-
name: "Int16"
isHidden: false
description: "Generate random int8 value"
properties:
valueType: "Int16"
readWrite: "RW"
minimum: "-100"
maximum: "100"
defaultValue: "0"
Randomization
Each deviceResources has an associated EnableRandomization_X
deviceResource. The EnableRandomization deviceResources are boolean values. When set to true, the associated simulated sensor value is generated by the device service. When the EnableRandomization value is set to false, then the associated simulator sensor value is fixed.
An example can be seen below:
deviceResources:
-
name: "EnableRandomization_Int8"
isHidden: true
description: "used to decide whether to re-generate a random value"
properties:
valueType: "Bool"
readWrite: "W"
defaultValue: "true"
-
name: "Int8"
isHidden: false
description: "Generate random int8 value"
properties:
valueType: "Int8"
readWrite: "RW"
defaultValue: "0"
The EnableRandomization deviceResource is automatically toggled to false when you issue a PUT
command to set a specified 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
.
Using the Virtual Device Service
For an example of how to set up and use devices with the Edge Xpert Virtual Device Service, see Virtual Example.