Skip to content

schema.json

What is the purpose of schema.json?

This file is a contract between a specific Unit instance and Pepeunit:

  1. The Unit guarantees that it will subscribe to all standard topics listed in input_base_topic and to all UnitNodes listed in input_topic.
  2. The Unit guarantees that it will publish data to the standard topics from output_base_topic and to all UnitNodes listed in output_topic.
  3. Pepeunit guarantees that it will send correctly formatted data to input_base_topic and subscribe to all topics in output_base_topic.
  4. Pepeunit guarantees that it will authorize publication and subscription for all topics that are addressed to the EMQX instance used by the Backend.
  5. Pepeunit guarantees that it will subscribe to all topics matching the pattern unit.example.com/+/+/+/pepeunit.
  6. Pepeunit guarantees that it will subscribe to all topics matching unit.example.com/+/pepeunit that have DataPipe enabled.

Structure

json
{
    "input_base_topic": {
        "update/pepeunit": [
            "example.com/input_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/update/pepeunit"
        ],
        "env_update/pepeunit": [
            "example.com/input_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/env_update/pepeunit"
        ],
        "schema_update/pepeunit": [
            "example.com/input_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/schema_update/pepeunit"
        ],
        "log_sync/pepeunit": [
            "example.com/input_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/log_sync/pepeunit"
        ]
    },
    "output_base_topic": {
        "state/pepeunit": [
            "example.com/output_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/state/pepeunit"
        ],
        "log/pepeunit": [
            "example.com/output_base_topic/9d0c2f4d-108e-488a-85e5-6040ef3d842a/log/pepeunit"
        ]
    },
    "input_topic": {
        "set_fan_state/pepeunit": [
            "example.com/2d98b4ba-c935-4379-8e1a-520e76018c17/pepeunit",
            "example.com/c0b107a7-9ae0-44ed-bc76-db5ff2af8887"
        ]
    },
    "output_topic": {
        "current_fan_speed_percentage/pepeunit": [
            "example.com/d76b4234-3997-4a4a-a113-6d1c21d6b84a/pepeunit"
        ],
        "current_temp/pepeunit": [
            "example.com/7279d28d-53b6-4866-99da-0b81bc1cc025/pepeunit"
        ]
    }
}

Topics can be divided into two categories: standard topics and developer topics:

  • input_base_topic and output_base_topic – standard topics
  • input_topic and output_topicUnit Developer topics

Standard topics

INFO

  1. Always consist of 5 main elements.
  2. Every topic name in schema_example.json maps to exactly one physical topic in EMQX.

Topic structure in EMQX:

txt
instance domain / topic type / Unit.uuid / purpose / pepeunit

Standard topics are used to implement standard MQTT commands and standard MQTT state topics.

Developer topics

INFO

  1. Can consist of 2 or 3 elements (with or without the /pepeunit suffix).
  2. For topics without the /pepeunit suffix (2 elements), DataPipe cannot be enabled.

Topic structure in EMQX:

txt
instance domain / UnitNode.uuid
instance domain / UnitNode.uuid / pepeunit

Each topic with this structure corresponds to a single UnitNode.

More about output_topic:

  • Used so that a Unit can send data to EMQX.
  • Each output_topic from schema_example.json maps to exactly one EMQX topic.
  • The Unit has exclusive rights to publish to these topics—no other Unit can publish to them.

More about input_topic:

  • Used so that a Unit can receive messages from multiple other Units.
  • Each input_topic from schema_example.json can correspond to several EMQX topics.
  • The Output->Input link system allows a Unit to subscribe not only to its own Input UnitNode but also to receive values from Output UnitNodes of other Units within the same input_topic.

The diagram below shows an example of a link between two Units:

img

Why are there only Output->Input links?

In the MQTT protocol paradigm, publishers send data to topics and subscribers receive it from those topics. If we apply this logic to Pepeunit, we get:

  • Output – a topic where the Unit can send data (the Unit is the publisher).
  • Input – a set of topics from which the Unit can receive data (the Unit is the subscriber).

Thus, when we create an Output->Input link, we instruct the Unit that owns the Input to additionally subscribe that Input to the Output of another Unit. The Unit can then receive data in its Input from multiple Outputs of other Units.

If there were Input->Output links, they would imply that the Input of one Unit initiates or affects the Output of another Unit, which does not match the MQTT communication model.