eclipse-hono / hono-extras

Hono Extras
Eclipse Public License 2.0
6 stars 12 forks source link

Support REST Api for sending configs and commands to devices (Device Communication API) #19

Open gdimitropoulos-sotec opened 1 year ago

gdimitropoulos-sotec commented 1 year ago

As we describe here This is an issue in order to qualify Hono as a replacement for Google IoT Core customers. In Google Iot Core clients can send commands and configs to a device through a REST API. Therefore we would like to add another REST API component to Hono as a replacement, named “Hono Device Communication API”. The new component will cover only communication via the MQTT adapter and will not communicate directly with the devices, but only with the command router.

Workflow

Client sends HTTP command/config requests to the Hono Device Communication API, api sends commands/configs to the command router which forwards them to the device.

Config Data

Config data does not need a specific schema and could be any binary data that a device understands. Configuration data will be stored with config version history. Config Request To update device configurations, the client should send a post request to the API and define fields versionToUpdate and binaryData in the request body.

POST https://API_URL/api/v1/config/{tenant-id}/{device-id}

Request body

Schema fields:

{
  "versionToUpdate":  string (int64 format),
  "binaryData": string (bytes format)
}

versionToUpdate field

Every device config has a version id (greater than 0). By updating device configs clients can update a specific config version or if the versionToUpdate field is set to 0, then the current version of configs will be always updated. Config update will fail if requested version does not exist.

binaryData

Any binary data that a specific device can understand.

Response body

If successful, api will return an DeviceConfig.



For more information see Google's IoT API documentation.


DeviceConfig DB

DeviceConfig objects will be saved in a Database so that a client can request them via the API. Database will be also used by MQTT adapter to make sure that all the desired configs have been delivered to the devices and also that all the devices have acknowledged their configs.

Keeping DeviceConfig sync

MQTT adapter after a configuration version was successfully updated, will publish the updated config version with retain set to true and so every device after a new start will always receive the updated current configurations to use.

Hono device communication API

Screenshot 2023-02-17 124422

julian-sotec commented 1 year ago

@calohmn Hi there! May I ask you to assign someone for a review of this issue? If needed we can also do a quick walkthru in virtual meet to have a quick onboarding session

calohmn commented 1 year ago

@julian-sotec Sorry for the delay. I'm having a look at this issue here and the PR.

julian-sotec commented 1 year ago

@julian-sotec Sorry for the delay. I'm having a look at this issue here and the PR.

Great! Thank you very much. If you need a quick demo / walkthru let us know