Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[epic] Distinguish between reported and desired state in twins #696

Open
thjaeckle opened this issue Jun 18, 2020 · 2 comments
Open

[epic] Distinguish between reported and desired state in twins #696

thjaeckle opened this issue Jun 18, 2020 · 2 comments

Comments

@thjaeckle
Copy link
Member

thjaeckle commented Jun 18, 2020

Problem statement

A feature which was long on the roadmap of Eclipse Ditto (see also former GH issue #125 where previous discussions were done) is the ability to distinguish between reported and desired twin state.
reported twin state can be seen as data/state coming from the actual device (the current "truth") whereas the desiredProperties state is something an application in the backend or a mobile app would set as the new requested target state for a property.

Example

For example, take a room thermostat:

  • the actual device reports that the measured-temperature (reported) is 20°
  • the currently configured target-temperature (reported) is also 20°
  • the user feels chilly, so via a mobile app the (desired) target-temperature is set to 22°
  • the actual device receives this desired target-temperature as change notification and sets its reported target-temperature also to 22
  • when this change was done and reported = desired for the target-temperature, the desired target-temperature is removed from the twin
  • the measured-temperature in this moment is still 20, and the device will now start heating up the room until the measured-temperature reaches the (reported) target-temperature
  • now if the device was offline during the desired target-temperature was configured, upon reconnection it can ask its twin "give me a delta for the desired state to apply" and can apply those missed changes

Sequence diagram

The following sequence diagram shall illustrate the interaction pattern:

Untitled (2)

Show sequencediagram.org source of sequence diagram
title Eclipse Ditto reported/desired feature state

participant Mobile App
participant Ditto
participant Device

==Device has connection==

Mobile App->Ditto:set "desired" property\nThermo/desiredProperties/configuration/targetTemp
activate Mobile App
activate Ditto
activate Device
Ditto->Ditto:update twin\nThermo/desiredProperties/configuration/targetTemp
Mobile App<-Ditto:response
deactivate Mobile App

Ditto->Device:send modified event regarding\nThermo/desiredProperties/configuration/targetTemp
deactivate Ditto

Device->Device:apply config change

Device->Ditto:confirm by setting actual property\nin "properties" with same name:\nThermo/properties/configuration/targetTemp
activate Ditto

Ditto->Ditto:update twin\nThermo/properties/configuration/targetTemp
Mobile App<--Ditto:send modified event regarding\nThermo/properties/configuration/targetTemp

Ditto->Ditto:remove twin\nThermo/desiredProperties/configuration/targetTemp
Mobile App<--Ditto:send modified event regarding\nThermo/desiredProperties/configuration/targetTemp

deactivate Ditto
deactivate Device

==Device looses connection==

Mobile App->Ditto:set "desiredProperties" property\nThermo/desiredProperties/configuration/targetTemp
activate Mobile App
activate Ditto
Ditto->Ditto:update twin\nThermo/desiredProperties/configuration/targetTemp
Mobile App<-Ditto:response
deactivate Mobile App

note right of Ditto:ineffective modified event
deactivate Ditto

==on Device re-connect==

Device->Ditto:request outstanding desired changes
activate Ditto
activate Device
Ditto->Device:send back all outstanding (non-deleted) \ndesired properties
deactivate Ditto

Device->Device:apply delta\nchanges to\ndesired
Device->Ditto:confirm by setting adjusted actual property\nin "properties" with same name:\nThermo/properties/configuration/targetTemp
activate Ditto

Ditto->Ditto:update twin\nThermo/properties/configuration/targetTemp
Mobile App<--Ditto:send modified event regarding\nThermo/properties/configuration/targetTemp

Ditto->Ditto:remove twin\nThermo/desiredProperties/configuration/targetTemp
Mobile App<--Ditto:send modified event regarding\nThermo/desiredProperties/configuration/targetTemp

deactivate Ditto
deactivate Device

====
note over Mobile App,Device:Sequence diagram created using the awesome online tool http://sequencediagram.org/

Benefits

Currently, Eclipse Ditto foresees features of a thing (aka the digital twin) to contain data/state from real devices in the properties of the features.
It is however not defined if those properties are reported or desired state. Up to now this had to be defined by the application developer modeling the data
to store in Ditto.

By defining in Ditto what is reported and what desired property state, Ditto can provide several benefits for application developers:

  • at any time (e.g. when a device is not connected) the reported and desired properties are clearly distinguishable in the twin
  • devices which are offline during changing desiredProperties can retrieve all desired state of a digital twin, e.g. on (re-)connection of the device
  • delta changes can be calculated by Ditto in order to get a list of changes to be done for an out-of-sync-device to reach its configured desired state
  • the definition (the information about the contained properties and their types) of a feature applies for both, reported and desired state
  • automatic cleanup/deletion of desiredProperties state by Ditto when reported state eventually reaches the desired state
  • policies may be applied based on reported/desired, so e.g. a device may be prohibited to change the desiredProperties state whereas an end user may be prohibited from changing the reported state
  • search capabilities based on the desired state, e.g. finding all twins where the desired state is not yet met
  • automatic delta calculation and publishing to the device upon device connection
  • maintaining order (modification timestamp) of desired/reported changes in order to not apply a desired change when a change done to the actual device was done at a later point in time

This GitHub issue shall act as the overall "epic" for all issues regarding the "desiredProperties" feature addition.

EPIC issues

Phase 1

Phase 1+x

Please feel free to start discussions about the overall concept in this issue and regarding the more specific topics in the linked issues.

@jufickel-b
Copy link

At least one corner case came to my mind: what happens if a property with a desired state gets deleted or renamed?

Deletion, probably, is no problem because the desired state gets deleted as well.

However when a property is renamed will its desired property renamed, too? If so, how does Ditto maintain the association of the former name to the new name for received state changes?

@thjaeckle
Copy link
Member Author

At least one corner case came to my mind: what happens if a property with a desired state gets deleted or renamed?

I think that this is a cornercase which can only happen during development - once the model/structure of a feature is defined by a fixed "definition", there is no renaming of properties.

When updating the major version of a definition (according to semantic versioning this would be the only way to rename a field), there would have to be a migration done anyways, so that migration must migrate properties as well as desired fields the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants