System & Component Usecase with MQTT APIs
This guide explains how to:
- Create and manage IoT Systems (devices or device collections) i.e
Energy Management System - Register and manage Components (sub-devices) i.e
Smart Meters - Monitor and control the System and its Components.
- Handle real-time state changes and errors.
- Use JSON for efficient data transfer, you can also use
MsgPack(https://msgpack.org/) format with the corresponding msgpack topics.
Please go through the Introduction and Prerequisite sections before proceeding with the use-case. Here: Introduction Guide For MQTT Setup
Let's create a use-case for system management using MQTT APIs. The following operations will be covered:
A smart building uses an IoT-based energy management system to monitor and control energy consumption in real-time. The system includes devices like smart meters, HVAC systems, lighting controllers, and occupancy sensors.
-
The building's energy management system is registered as a
System. In this case, lets create asystemwith the nameEnergy Management Systemvia DRIVR UI as mentioned in the prerequisite.
-
Once a system is created you can update the fields using this
PUBMQTT topic. The fields likedescription,name,connectionStateandstatusetc. can be updated using the MQTT API.PUB drivr/v1/{slug}/input/system/{systemUuid}/jsonPUB drivr/v1/{slug}/input/system/{systemUuid}/msgpackSample Json Example:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/jsonRequest:
{ "description": "This is an energy management system.", "name": "ESM-system", "status": "ACTIVATED", "connectionState": "CONNECTED" }Response:
Topic: drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/json QoS: 1 { "description": "This is an energy management system.", "name": "ESM-system", "status": "ACTIVATED", "connectionState": "CONNECTED" }
-
After creating the system, you can verify it using the
SUBMQTT topic. The system will publish its initial configuration and status.SUB drivr/v1/{slug}/systems/{systemUuid}Sample Example:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586Response:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586 QoS: 0 Retained { "uuid": "792b6149-1daa-488f-b07a-f684503b0586", "createdAt": "2025-04-15T08:46:14.998945", "updatedAt": "2025-04-15T08:52:12.620248", "code": "energy-management-system", "name": "ESM-system", "description": "This is an energy managment system.", "connectionState": "UNDEFINED", "connectionStateUpdatedAt": "2025-04-15T08:46:14.999275", "domainUuid": "7b6f629d-872b-48a0-9386-7c0ee61ceb0d", "ownerUuid": "3348037a-9f5d-425e-b593-11e6e7437b74", "status": "ACTIVATED", "metadata": {} }
-
If there are any errors for your request, you can monitor them by subscribing to the error MQTT topic for your system. All errors will be published there. Please subscribe to this topic before you make a request to DRIVR as messages are not retained for this topic.
You can get the data in
JSONorMsgPackformat based on the request you have used for publishing your payload. Here,slugis domain unique identifier andsystemUuidis the unique identifier of the system you created in the previous step.SUB drivr/v1/{slug}/input/system/{systemUuid}/json/errorSUB drivr/v1/{slug}/input/system/{systemUuid}/msgpack/errorSample Json Example:
Subscribe to Error topic:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/json/errorError Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/json{ "connectionState" : "ErrorConnectionState" }Response on Error Topic:
Topic: drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/json/error QoS: 0 { "connectionState": [ "Incorrect enum member ErrorConnectionState" ] }
-
With this
SUBMQTT topic, you can monitor thestateof the system. OnlystatuslikeACTIVATED,DEACTIVATED, andARCHIVEDare allowed.SUB drivr/v1/{slug}/systems/{systemUuid}/stateSample Example:
Request:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/stateResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/state QoS: 0 Retained ACTIVATED -
- The system's
connection statecan be updated to one of the following predefined values:CONNECTED,DISCONNECTED, orUNDEFINED. This is anENUMfield, meaning only these specific values are allowed and must be provided inplain textformat. - Use the
PUBMQTT topic below to update the connection state of the system efficiently.
PUB drivr/v1/{slug}/input/system/{systemUuid}/state/connectionSample Example:
Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/state/connectionDISCONNECTEDResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/state/connection QoS: 0 DISCONNECTED - The system's
-
With this
SUBMQTT topic, you can monitor theconnection stateof the system.SUB drivr/v1/{slug}/systems/{systemUuid}/state/connectionSample Example:
Request:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/state/connectionResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/state/connection QoS: 0 Retained DISCONNECTED -
If there are any errors for your request, you can monitor them by subscribing to the error MQTT topic for the connection state of your system. All errors will be published there. Please subscribe to this topic before you make a request to DRIVR as messages are not retained for this topic.
SUB drivr/v1/{slug}/systems/{systemUuid}/state/connection/errorSample Example:
Subscribe to Error topic:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/state/connection/errorError Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/state/connectionUNKNOWNResponse on Error Topic:
Topic: drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/state/connection/error QoS: 0 { "connection_state": [ "Incorrect enum member UNKNOWN" ] }
You need to create a
componentModelbefore registering thecomponentswhich acts as a template for thecomponentsyou are going to register.
Create a blueprint for all the
smart meterscomponentsin DRIVR withComponentModel. In this case, lets create acomponentModelwith nameSmart Meter Modelvia DRIVR UI.Go through the Component Model Creation guide to create a
componentModel.
-
Devices like smart meters, HVAC controllers, and lighting systems are added as
Components. In our example, lets go withSmart Metersas a component. The smart meters will be registered with the system using thePUBMQTT topic. The component will publish its configuration and state to the system.You can send the data in
JSONorMsgPackformat. Here,slugis domain unique identifier andsystemUuidis the unique identifier of the system you created in the previous step.componentModelUuidwill be the unique identifier of thecomponentModelyou created in the previous step.PUB drivr/v1/{slug}/input/system/{systemUuid}/component/jsonPUB drivr/v1/{slug}/input/system/{systemUuid}/component/msgpackSample Json Example:
Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/json{ "componentModelUuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter", "name": "Smart-Meter", "status": "ACTIVATED", "connectionState": "CONNECTED" }Response:
Topic: drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/json QoS: 1 { "componentModelUuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter", "name": "Smart-Meter", "status": "ACTIVATED", "connectionState": "CONNECTED" }
-
-
The component(
smart meters) will publish their configuration and state to the system. The system will subscribe to the component's configuration updates. If you have more than 1 component, this endpoint will help you to subscribe to all the components under the system. You can use the#wildcard in the MQTT topic to subscribe to updates for all components within a system. This allows you to receive real-time notifications about thestatus,connection state, andmetadatachanges for every component under the specified system, making it efficient to monitor and manage multiple components efficiently.SUB drivr/v1/{slug}/systems/{systemUuid}/components/#/jsonSUB drivr/v1/{slug}/systems/{systemUuid}/components/#/msgpackSample Example:
Request:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/#Response:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter QoS: 0 { "uuid": "6204964f-0636-4613-9875-eda244e1a1d9", "createdAt": "2025-04-15T13:01:44.387740", "updatedAt": "2025-04-15T13:01:44.396418", "code": "smart-meter", "name": "Smart-Meter", "systemUuid": "792b6149-1daa-488f-b07a-f684503b0586", "connectionState": "UNDEFINED", "connectionStateUpdatedAt": "2025-04-15T13:01:44.396118", "status": "ACTIVATED", "componentModel": { "uuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter-model", "isConnective": true }, "metadata": {} }Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/state QoS: 0 Retained ACTIVATEDTopic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/state/connection QoS: 0 Retained UNDEFINED
-
For specific details on each component, you can use the componentCode in the topic.
-
- The component
smart meterswill publish their state to the system. The system will subscribe to the component's state updates. - We will use the
componentCodeto subscribe to the specific component which issmart-meterin this case. - Allowed states are
ACTIVATED,DEACTIVATED, andARCHIVED.
SUB drivr/v1/{slug}/systems/{systemUuid}/components/{componentCode}/stateSample Example:
Request:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/stateResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/state QoS: 0 Retained ACTIVATED - The component
-
- The component (
smart meters) will publish their connection status to the system. The system will subscribe to the component's connection updates. - Allowed connection states are
CONNECTED,DISCONNECTED, andUNDEFINED.
SUB drivr/v1/{slug}/systems/{systemUuid}/components/{componentCode}/state/connectionSample Example:
Request:
SUB drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/state/connectionResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/state/connection QoS: 0 Retained UNDEFINED - The component (
-
- If there are any errors for your request, you can monitor them by subscribing to the error MQTT topic for your component. All errors will be published there. Please subscribe to this topic before you make a request to DRIVR as messages are not retained for this topic.
SUB drivr/v1/{slug}/input/system/{systemUuid}/component/json/errorSUB drivr/v1/{slug}/input/system/{systemUuid}/component/msgpack/errorSample Example:
Request:
SUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/json/errorResponse:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter/json/error QoS: 0 { "connectionState": [ "Incorrect enum member ErrorConnectionState" ] }
-
- You can update the values of an existing component using this
PUBMQTT topic. This includes changingname,state,connectionState, andmetadataetc. - You can also do mass creation and update of components using this
PUBMQTT topic.
- You can update the values of an existing component using this
-
PUB drivr/v1/{slug}/input/system/{systemUuid}/component/{componentCode}/jsonPUB drivr/v1/{slug}/input/system/{systemUuid}/component/{componentCode}/msgpackSample Example:
Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/smart-meter/json{ "name": "Smart-Meter-Updated" }Response:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter QoS: 0 Retained { "uuid": "6204964f-0636-4613-9875-eda244e1a1d9", "createdAt": "2025-04-15T13:01:44.387740", "updatedAt": "2025-05-06T14:29:49.445921", "code": "smart-meter", "name": "Smart-Meter-Updated", "systemUuid": "792b6149-1daa-488f-b07a-f684503b0586", "connectionState": "UNDEFINED", "connectionStateUpdatedAt": "2025-04-15T13:01:44.396118", "status": "ACTIVATED", "componentModel": { "uuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter-model", "isConnective": true }, "metadata": {} } -
PUB drivr/v1/{slug}/input/system/{systemUuid}/component/jsonPUB drivr/v1/{slug}/input/system/{systemUuid}/component/msgpackSample Example:
Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/json[ { "code": "smart-meter", "name": "Smart-Meter-Updated" }, { "code": "smart-meter-v2", "name": "Smart-Meter-v2-Updated" } ]Response:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter QoS: 0 { "uuid": "6204964f-0636-4613-9875-eda244e1a1d9", "createdAt": "2025-04-15T13:01:44.387740", "updatedAt": "2025-05-07T08:39:45.034821", "code": "smart-meter", "name": "Smart-Meter-Updated", "systemUuid": "792b6149-1daa-488f-b07a-f684503b0586", "connectionState": "UNDEFINED", "connectionStateUpdatedAt": "2025-04-15T13:01:44.396118", "status": "ACTIVATED", "componentModel": { "uuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter-model", "isConnective": true }, "metadata": {} }Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter-v2 QoS: 0 { "uuid": "6d6eb245-599e-42c6-b1a6-009805655fbd", "createdAt": "2025-05-07T08:32:15.566260", "updatedAt": "2025-05-07T08:39:45.082120", "code": "smart-meter-v2", "name": "Smart-Meter-v2-Updated", "systemUuid": "792b6149-1daa-488f-b07a-f684503b0586", "connectionState": "CONNECTED", "connectionStateUpdatedAt": "2025-05-07T08:32:15.571446", "status": "ACTIVATED", "componentModel": { "uuid": "f2deb868-aec5-4976-91e0-262902f01d1e", "code": "smart-meter-model", "isConnective": true }, "metadata": {} }
-
The smart meters will publish their connection status to the system. The system will subscribe to the component's connection updates.
PUB drivr/v1/{slug}/input/system/{systemUuid}/component/{componentCode}/json/state/connectionSample Example:
Request:
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/smart-meter/json/state/connectionDISCONNECTEDResponse:
Topic: drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/smart-meter/json/state/connection QoS: 0 DISCONNECTED
This guide should serve as a comprehensive resource for those looking to manage IoT systems and components using a real-time, structured approach.
If you have any additional metadata to be added to the component, you can do that using the createMetadataType{DataType} mutation on DRIVR Graphiql APIs, you can create metadata of type STRING, INTEGER, FLOAT, BOOLEAN, DATE and DATETIME etc. This metadata can be used to store additional information about the component or any other supported entity.
This can also be created on system level.
Let's create metadata for Manufacturer and Version for the all the component using the Graphiql API.
Graphql Mutation & Query Sample
Request:
mutation create_metadata_on_component_manufacturer {
createMetadataTypeString(
key: "Manufacturer",
entityType: COMPONENT,
default: "Not Defined"
) {
key
entityType
dataType
uuid
unique
}
}
Response:
{
"data": {
"createMetadataTypeString": {
"key": "Manufacturer",
"entityType": "COMPONENT",
"dataType": "STRING",
"uuid": "effc785a-6c82-46f2-a2d8-637f2c1a41d2",
"unique": false
}
}
}
Request:
mutation create_metadata_on_component_version{
createMetadataTypeString(
key:"Version",
entityType: COMPONENT,
unique:true
){
key
entityType
dataType
uuid
unique
}
}
Response:
{
"data": {
"createMetadataTypeString": {
"key": "Version",
"entityType": "COMPONENT",
"dataType": "STRING",
"uuid": "2bf0d4e7-37f5-471d-a69d-7e003b9f0685",
"unique": true
}
}
}
Verify if the following metadata is created successfully using the GraphQL API.
Request:
query metadata{
metadataTypes{
items{
uuid
key
dataType
entityType
}
}
}
Response:
{
"data": {
"metadataTypes": {
"items": [
{
"uuid": "effc785a-6c82-46f2-a2d8-637f2c1a41d2",
"key": "Manufacturer",
"dataType": "STRING",
"entityType": "COMPONENT"
},
{
"uuid": "2bf0d4e7-37f5-471d-a69d-7e003b9f0685",
"key": "Version",
"dataType": "STRING",
"entityType": "COMPONENT"
}
]
}
}
}
Once the metadata is created, you can use the PUB MQTT topic to use metadata fields in create, update component. Here you see the Version and Manufacturer metadata is used in the component update.
Example with Metadata on Component
PUB drivr/v1/company-example/input/system/792b6149-1daa-488f-b07a-f684503b0586/component/smart-meter/json
{
"name": "Smart-Meter-Updated",
"metadata": {
"Version": "V2",
"Manufacturer": "TM"
}
}
Response:
Topic: drivr/v1/company-example/systems/792b6149-1daa-488f-b07a-f684503b0586/components/smart-meter QoS: 0
{
"uuid": "6204964f-0636-4613-9875-eda244e1a1d9",
"createdAt": "2025-04-15T13:01:44.387740",
"updatedAt": "2025-05-06T14:29:49.445921",
"code": "smart-meter",
"name": "Smart-Meter-Updated",
"systemUuid": "792b6149-1daa-488f-b07a-f684503b0586",
"connectionState": "UNDEFINED",
"connectionStateUpdatedAt": "2025-04-15T13:01:44.396118",
"status": "ACTIVATED",
"componentModel": {
"uuid": "f2deb868-aec5-4976-91e0-262902f01d1e",
"code": "smart-meter-model",
"isConnective": true
},
"metadata": {
"Version": "V2",
"Manufacturer": "TM"
}
}