drogue-iot / drogue-cloud

Cloud Native IoT
https://drogue.io
Apache License 2.0
114 stars 30 forks source link

Provide digital twin capabilities #164

Open ctron opened 2 years ago

ctron commented 2 years ago

Drogue Cloud should provide some digital twin capabilities out of the box. This should be optional on two layers: for the overall infrastructure, but also for the application.

JulianFeinauer commented 2 years ago

I like the feature and the idea. What are you exactly considering? My initial idea would be to have some kind of "last message seen" API for each message (probably with some kind of TTL, ...).

So that if you receive (in whatever order) messages {"a":1}, {"b":2}, {"c":3} one could get the message

{
  "a": 1,
  "b": 2,
  "c": 3
}

and so on ...

ctron commented 2 years ago

Yes, that would be one aspect of the twin I guess. In addition to that, I would like to be able to receive aggregated (full state) updates. From your example, when the next change of {"c": 4} comes in, I want to get the following event:

{
  "a": 1,
  "b": 2,
  "c": 4
}

In order to make it easier for clients to work with the full state of a device.

The come a set of additional features:

I think all of this requires some kind of payload normalization. Like defining "features" of a device, which has "reported properties" and "desired properties". So that the different functionalities of the system can operate on the level of .<device>.<feature>.(reported|desired).<property>.

Like:

{
  "temperature": {
    "properties": {
      "value": 1.23
    }
  },
  {
    "accelerometer": {
      "properties": {
        "x": 123,
        "y": 123,
        "z": 123
      }
    }
  },
  {
    "led_1": {
      "properties": {
        "state": true,
      }
      "desiredProperties": {
        "state": false,
      }
      "reconciliation": {
        "last": "2022-02-23T16:44:12Z"
      }
    }
  }
}

Where each property of a feature is treated atomically, and can be any JSON value.

JulianFeinauer commented 2 years ago

So you would (also) agree that json is the default message format and there is some kind of mapping from keys to "jsonPath" to specify the values, right?