The functions of Virtual Device Service GO just like the java version device-virtual, but supports more data types of random values:
- Bool
- Int8, Int16, Int32, Int64
- Uint8, Uint16, Uint32, Uint64
- Float32, Float64
- Binary
This version of Virtual Device Service is implemented based on Device SDK GO, and leveraged ql (an embedded SQL database engine) to simulate virtual resources.
Adding service:
device-virtual:
image: edgexfoundry/docker-device-virtual-go:1.0.0
ports:
- "49990:49990"
container_name: device-virtual
hostname: device-virtual
networks:
- edgex-network
volumes:
- db-data:/data/db
- log-data:/edgex/logs
- consul-config:/consul/config
- consul-data:/consul/data
- db-devicevirtual:/db # Mount ql database directory is optional
depends_on:
- data
- command
For now, Virtual Device Service contains 4 pre-defined devices as random value generators:
- Random-Boolean-Device
- Random-Integer-Device
- Random-UnsignedInteger-Device
- Random-Float-Device
- Random-Binary-Device Restricted:
- To control the randomization of device resource values, it has to add additional device resources with the prefix "EnableRandomization_" for each device resource. (Need to do the same for device commands and core commands) Please find the above default device profiles for example.
- According to the implementation of REST controller in Device SDK, binary device resource is only applicable to GET command for now.
Use Core-Command Service APIs to find executable commands information:
- http://[host]:48082/api/v1/device/name/Random-Boolean-Device
- http://[host]:48082/api/v1/device/name/Random-Integer-Device
- http://[host]:48082/api/v1/device/name/Random-UnsignedInteger-Device
- http://[host]:48082/api/v1/device/name/Random-Float-Device
- http://[host]:48082/api/v1/device/name/Random-Binary-Device
NOTE:
- The Enable_Randomization attribute of resource is automatically disabled when you use put command to set a specified value.
- The minimum and maximum values of resource can be specified in the device profile. Example:
deviceResources: - name: "Int8" description: "Generate random int8 value" properties: value: { type: "Int8", readWrite: "R", minimum: "-100", maximum: "100", defaultValue: "0" } units: { type: "String", readWrite: "R", defaultValue: "random int8 value" }
- Binary value is generated by function rand.Read(p []byte) in Golang math package. The []byte size is fixed to half MaxBinaryBytes limitation that defined in device-sdk-go.
- Install command ql
- Enter ql database directory:
- If the Virtual Device Service runs in Docker container, use the following command to find the path of ql database directory:
$ docker volume inspect edgex_temp_db-devicevirtual
- If the Virtual Device Service runs in dev mode, the ql database directory is under the driver directory.
Command examples:
- Query all data:
$ ql -db deviceVirtual.db -fld "select * from VIRTUAL_RESOURCE"
- Update Enable_Randomization:
$ ql -db deviceVirtual.db "update VIRTUAL_RESOURCE set ENABLE_RANDOMIZATION=false where DEVICE_NAME=\"Random-Integer-Device\" and DEVICE_RESOURCE_NAME=\"Int8\" "
- Update Value:
$ ql -db deviceVirtual.db "update VIRTUAL_RESOURCE set VALUE=\"26\" where DEVICE_NAME=\"Random-Integer-Device\" and DEVICE_RESOURCE_NAME=\"Int8\" "