-
Notifications
You must be signed in to change notification settings - Fork 5
Device Catalog API
Device Catalog provides a REST(ish) API to publish and discover devices and the resources they expose (e.g., Temperature sensor, Light switch).
The entry point of the Device Catalog API returns devices and their resources in the following format:
{
"id": "/dc",
"type": "DeviceCatalog",
"@context": <string>,
"devices": {},
"resources":[],
"page": <number>,
"per_page": <number>,
"total": <number>,
}The fields id, type, and @context are used to enable LinkedData support and can be ignored by clients using the plain JSON API described in this document.
The resources array holds an array of Resources. The devices object holds a dictionary of Devices with ids as keys. page, per_page and total are used for pagination of the resources array.
Each device is represented in the following format:
{
"id": <string>,
"type": "Device",
"name": <string>,
"description": <string>,
"meta": {},
"resources": [],
"ttl": <number>,
"created": <timestamp>,
"updated": <timestamp>,
"expires": <timestamp>,
"page": <number>,
"per_page": <number>,
"total": <number>,
}The field id needs to uniquely identify the device in the network and the convention is to construct it as the dgw-id/devicename.
The rest of the fields have following meanings:
-
nameis a short string describing a device (e.g., "DummyDevice") -
descriptionis a human-readable description of a device (e.g., "Just a test of DGW") -
metais any hashmap describing meta-information of a device -
resourcesis an array of Resources as described below -
ttlis an integer defining the Time-To-Live of a device registration -
created,updated, andexpiresare generated by the Device Catalog and describe TTL-related timestamps -
page,per_pageandtotalare used for pagination
Each resource exposed by a Device has the following representation:
{
"id": <string>,
"type": "Resource",
"name": <string>,
"meta": {},
"protocols": [
{
"type": <string>,
"endpoint": {},
"methods": [],
"content-types": []
}
],
"representation": {}
"device": <string>
}where:
-
nameis a short string describing a device (e.g., "TemperatureSensor01") -
metais any hashmap describing meta-information of a resource -
protocolsis an array of protocols which can be used to access the resource-
typeis a short string describing the protocol (e.g., "MQTT", "REST") -
endpointis an object describing the protocol endpoint (e.g., URL for a Web API) -
methodsis an array of protocol verbs (e.g., "GET,POST,PUT,DELETE" for REST, "PUB,SUB" for MQTT) -
content-typesis an array of strings representing MIME-types defined inrepresentation
-
-
representationis a dictionary describing the MIME-types supported by the resource -
devicespecifies theidof the device exposing this resource
A registration describing a Device with a Dummy Sensor may look as follows:
{
{
"/dc/my-demo-gateway-1/DummyDevice": {
"id": "/dc/my-demo-gateway-1/DummyDevice",
"type": "Device",
"name": "DummyDevice",
"description": "Just a test of DGW",
"meta": {
"any": "key",
"kind": "dummy"
},
"resources": [
{
"id": "/dc/my-demo-gateway-1/DummyDevice/RandomStream",
"type": "Resource",
"name": "RandomStream",
"meta": {},
"protocols": [
{
"type": "REST",
"endpoint": {
"url": "http://pi.homenetwork:9000/rest/DummyDevice/RandomStream"
},
"methods": [
"GET"
],
"content-types": [
"text/plain"
]
}
],
"representation": {
"text/plain": {
"type": "number"
}
},
"device": "/dc/my-demo-gateway-1/DummyDevice"
}
],
"ttl": -1,
"created": "2014-08-20T12:58:21.29182903+02:00",
"updated": "2014-08-20T12:58:21.29182903+02:00",
"expires": "0001-01-01T00:00:00Z"
}
}
The REST(ish) API of the Device Catalog includes CRUD to create/retrieve/update/delete device registrations, a read-only API for (LinkedData-enabled) Resources they expose, and a simple filtering API to search through the catalog for both of them.
-
/dcreturns all registered devices as DeviceCatalog - methods: GET
-
/dc/<deviceid>returns a specific device registration given itsidas a Device - methods: POST (create), GET (retrieve), PUT (update), DELETE (delete)
-
<id>id of the registration -
/dc/<deviceid>/<resourceid>returns a specific resource of a specific registration given itsidas a Resource
/sc/<type>/<path>/<op>/<value>- methods: GET
-
<type>is either device/resource (returns a random matching entry in the corresponding format) or devices/resources (returns all matching entries as DeviceCatalog) -
<path>is a dot-separated path in the Device or Resource similar to json-path -
<op>is one of (equals, prefix, suffix, contains) string comparison operations -
<value>is the intended value/prefix/suffix/substring of the key identified by<path>
curl http://catalog.example.com/dc/resource/name/equals/RandomStream
will return a collection of all devices in the catalog which have resources with name RandomStream (as the one described in the example above)
The Resources returned in resources array in DeviceCatalog and Registration are paged using the page and per_page parameters.
The results are then include the following additional entries:
-
pageis the current page (if not specified - the first page is returned) -
per_pageis the number of entries per page (if not specified - the maximum allowed is returned) -
totalis the total number of Resources in the catalog
curl http://catalog.example.com/dc?page=1&per_page=2
curl http://catalog.example.com/dc/my-demo-gateway-1/DummyDevice?page=1&per_page=2
curl http://catalog.example.com/dc/devices/name/equals/RandomStream?page=1&per_page=2
API version is included as a parameter to the MIME type of request/response:
application/ld+json;version=0.1
Local device catalogs are exposed by the Device Gateways and contain the devices and resources they expose to the outer world. The same registrations can also be published to remote catalogs (if configured).
Registrations in both local and remote catalogs have same ids, and for applications it is transparent with which catalog to work: both local and remote catalogs implement the same API.
Registrations in the remote catalog have a TTL and need to be updated before they are expired and removed. For devices in the local catalog, TTL = -1 ("never expires").
About Patchwork Toolkit
Configuration
- Configuring Device Gateway
- Configuring Devices
- Configuring Device Catalog
- Configuring Service Catalog
- Configuring Services
Deployment examples
- Singleall-in-on-box
- Multiple Device Gateways with optional central Device Catalog
- Using central Service Catalog
API for Application developers
Integrating devices
- TBD...
Third-party integrations