EdgeX device service for REST protocol
This device service provides easy way for 3'rd party applications, such as Point of Sale, CV Analytics, etc., to push data into EdgeX via the REST protocol.
The current implementation is meant for one-way communication into EdgeX via async readings. If future use cases determine a need forcommanding
, i.e. two-communication, it can be added then.
This device service creates the additional parametrized REST
endpoint:
/api/v2/resource/{deviceName}/{resourceName}
deviceName
refers to a device
managed by the REST device service.resourceName
refers to the device resource
defined in the device profile
associated with the given deviceName
.The data, text
or binary
, posted to this endpoint is type validated and type casted (text data only) to the type defined by the specified device resource
. The resulting value is then sent into EdgeX via the Device SDK's async values
channel.
Note: When binary data is used the EdgeX event/reading is
CBOR
encoded by theDevice SDK
and the binary value in the reading isNOT
be stored in the database byCore Data
. TheCBOR
encoded event/reading, with the binary value, is published to theMessage Bus
forApplication Services
to consume
Note: All non-binary data is consumed as text. The text is casted to the specific type of the specified
device resource
once it passes type validation.
This device service use the standard configuration defined by the Device SDK.
The DeviceList
configuration is standard except that the DeviceList.Protocols
can be empty. The following is a sample DeviceList
that works with the sample device profiles referenced below.
[[DeviceList]]
Name = "sample-json"
ProfileName = "sample-json"
Description = "RESTful Device that sends in JSON data"
Labels = [ "rest", "json" ]
[DeviceList.Protocols]
[DeviceList.Protocols.other]
[[DeviceList]]
Name = "sample-image"
ProfileName = "sample-image"
Description = "RESTful Device that sends in binary image data"
Labels = [ "rest", "binary", "image" ]
[DeviceList.Protocols]
[DeviceList.Protocols.other]
[[DeviceList]]
Name = "sample-numeric"
ProfileName = "sample-numeric"
Description = "RESTful Device that sends in numeric data"
Labels = [ "rest", "numeric", "float", "int" ]
[DeviceList.Protocols]
[DeviceList.Protocols.other]
As with all device services the device profile
is where the Device Name, Device Resources and Device Commands are define. The parameterized REST endpoint described above references these definitions. Each Device
has it's own device profile. There are three sample device profiles that define the devices referenced in the above sample configuration.
Note: The
isHidden
field is set to true since this device service does not support Commanding.
The best way to test this service with simulated data is to use PostMan to send data to the following endpoints defined for the above device profiles.
http://localhost:59986/api/v2/resource/sample-image/jpeg
BinaryValue
of the Reading
being set to the JPEG image data posted.http://localhost:59986/api/v2/resource/sample-image/png
BinaryValue
of the Reading
being set to the PNG image data posted.http://localhost:59986/api/v2/resource/sample-json/json
POSTing a JSON string value will result in the Value
of the Reading
being set to the JSON string value posted.
Note: Currently there isn't a JSON data type, thus there is no validation that the string value is valid JSON. It is up to the Application Service using the JSON to first validate it.
Example test JSON value to post:
{
"id" : "1234",
"name" : "test data",
"payload" : "test payload"
}
http://localhost:59986/api/v2/resource/sample-numeric/int
POSTing a text integer value will result in the Value
of the Reading
being set to the string representation of the value as an Int64
. The POSTed value is verified to be a valid Int64
value.
A 400 error will be returned if the POSTed value fails the Int64
type verification.
Example test int
value to post:
1001
http://localhost:59986/api/v2/resource/sample-numeric/float
POSTing a text float value will result in the Value
of the Reading
being set to the string representation of the value as an Float64
. The POSTed value is verified to be a valid Float64
value.
A 400 error will be returned if the POSTed value fails the Float64
type verification.
Example test float
value to post:
500.568
Since Commanding
is not implemented, specifying AutoEvents
in the configuration will result in errors. Thus AutoEvents
should not be specified in the configuration.
Clone the device-rest-go repo with the following command:
git clone https://github.com/edgexfoundry/device-rest-go.git
Build a docker image by using the following command:
make docker
Alternatively the device service can be built natively:
make build
EdgeX Device REST is also available as a snap package. Install the snap with the following command:
sudo snap install edgex-device-rest
For more details on the Device REST Snap, including installation, configuration, please refer to EdgeX REST Device Service Snap
For more details on deploying EdgeX with Snaps, viewing logs, security services, please check Getting Started with Snap
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。