schema.json
What is the purpose of schema.json?
This file is a contract between a specific Unit instance and Pepeunit:
- The Unit guarantees that it will subscribe to all standard topics listed in
input_base_topicand to all UnitNodes listed ininput_topic. - The Unit guarantees that it will publish data to the standard topics from
output_base_topicand to all UnitNodes listed inoutput_topic. - Pepeunit guarantees that it will send correctly formatted data to
input_base_topicand subscribe to all topics inoutput_base_topic. - Pepeunit guarantees that it will authorize publication and subscription for all topics that are addressed to the EMQX instance used by the Backend.
- Pepeunit guarantees that it will subscribe to all topics matching the pattern
unit.example.com/+/+/+/pepeunit. - Pepeunit guarantees that it will subscribe to all topics matching
unit.example.com/+/pepeunitthat have DataPipe enabled.
Structure
{
"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_topicandoutput_base_topic– standard topicsinput_topicandoutput_topic– Unit Developer topics
Standard topics
INFO
- Always consist of 5 main elements.
- Every topic name in schema_example.json maps to exactly one physical topic in EMQX.
Topic structure in EMQX:
instance domain / topic type / Unit.uuid / purpose / pepeunitStandard topics are used to implement standard MQTT commands and standard MQTT state topics.
Developer topics
INFO
- Can consist of 2 or 3 elements (with or without the
/pepeunitsuffix). - For topics without the
/pepeunitsuffix (2 elements), DataPipe cannot be enabled.
Topic structure in EMQX:
instance domain / UnitNode.uuid
instance domain / UnitNode.uuid / pepeunitEach 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_topicfrom 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_topicfrom schema_example.json can correspond to several EMQX topics. - The
Output->Inputlink system allows a Unit to subscribe not only to its ownInputUnitNode but also to receive values fromOutputUnitNodes of other Units within the sameinput_topic.
The diagram below shows an example of a link between two Units:
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.