Skip to content

Pub Sub messages

Dominik Schlösser edited this page Aug 2, 2017 · 10 revisions

Pub/Sub messages

Patterns

If an entity has a sub-state (substate), the following subscriptions can be available:

  • (entity)/(substate)/get
  • (entity)/(substate)/set (if appropriate)
  • (substate)/get (useful to enumerate different entities that all support a given (substate) If (substate) changes, the entity publishes:
  • (entity)/(substate) with all information that concerns this substate.

Examples

  • (substate): temperature - For sensors, this would only implement the get subscriptions, but possibly for a heating system, that could also provide set subscriptions.
  • (substate): led - A led can be a compound substate: on/off state, blink frequency, brightness, r-g-b colors. Possibly, a led could export (ledname)\state\get, answering with a state that contains (onoffstate, mode(blinking?), brightness, color), and possibly sub-states like (ledname)\brightness. A (ledname)/state/set could contain one or several of the sub-states within the message. Also abbreviations (on/off etc.) should be discussed.

Published sub-states

Timestamps

Each published substate should contain within it's json message:

  • "timer": millis();
  • "time": util::msgtime::ISOnowMillis(); (only, if a valid system-time is available)

Both time and timer reference the moment, the current state was assumed. (e.g. the moment a switch was pressed, or the moment, the sensor data was actually measured.)

Entity general subscriptions

Each entity subscribes to (entity)/info/get and info/get

  • (entity)/info/get publishing to this enumerates all substates of an entity, publishing (entity)/info
  • info/get publishing to this enumerates all entities and causes all of them to publish (entity)/info

Message flow examples

Time handling (mastertime)

  • Mastertime subscribes to */time

  • Time-providers entities subscribe to (entity)/time/get, time/get, and, if they can change their clock/time: (entity)/time/set and time/set.

  • Mastertime publishes time/get

  • All time-entites publish (entity)/time, both on receive of time/get and periodically.

  • On each receive of a (entity)/time, Master-time selects the time-source with the hightest precision, and periodically uses that information to publish time/set.

  • Time-entities that have subscribed to a time/set, change their internal clocks accordingly.