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.
- core-data
- Redis DB
- core-metadata
Currently, the NATS Messaging capability (NATS MessageBus) is opt-in at build time. This means that the published Docker image and Snaps do not include the NATS messaging capability.
The following make commands will build the local binary or local Docker image with NATS messaging capability included.
make build-nats
make docker-nats
The locally built Docker image can then be used in place of the published Docker image in your compose file.
See Compose Builder nat-bus
option to generate compose file for NATS and local dev images.
This device service creates the additional parametrized REST
endpoint:
/api/v2/resource/{deviceName}/{resourceName}
deviceName
refers to adevice
managed by the REST device service.resourceName
refers to thedevice resource
defined in thedevice profile
associated with the givendeviceName
.
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
- POSTing a JPEG binary image file will result in the
BinaryValue
of theReading
being set to the JPEG image data posted. - Example test JPEG to post:
- Select any JPEG file from your computer or the internet
- POSTing a JPEG binary image file will result in the
-
http://localhost:59986/api/v2/resource/sample-image/png
- POSTing a PNG binary image file will result in the
BinaryValue
of theReading
being set to the PNG image data posted. - Example test PNG to post:
- Select any PNG file from your computer or the internet
- POSTing a PNG binary image file will result in the
-
http://localhost:59986/api/v2/resource/sample-json/json
-
POSTing a JSON string value will result in the
Value
of theReading
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 theReading
being set to the string representation of the value as anInt64
. The POSTed value is verified to be a validInt64
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 theReading
being set to the string representation of the value as anFloat64
. The POSTed value is verified to be a validFloat64
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
This component is packaged as docker image and snap.
For docker, please refer to the Dockerfile and Docker Compose Builder scripts.
For the snap, refer to the snap directory.