# MQTT

## Station Signals

Real-time data from stations is collected over [MQTT](https://mqtt.org/), an open-source, lightweight messaging protocol designed for IoT.

The specific types of data accepted by Busroot are called 'Signals'. The following signals are currently supported:

| Signal Key/Field                                                            | Description                                                                                                                                        |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>production\_complete\_good</p><p>production\_complete (alias)</p><p></p> | The number of new (good) production units created.                                                                                                 |
| <p>production\_count\_good</p><p>production\_count (alias)</p>              | The **running count** of new (good) production units created. (i.e. the number of new units is this count minus the previously received count)     |
| production\_complete\_bad                                                   | The number of new bad/reject production units created.                                                                                             |
| production\_count\_bad                                                      | The **running count** of new bad/reject production units created. (i.e. the number of new units is this count minus the previously received count) |
| productive                                                                  | A binary value indicating if the station is currently engaged in production.                                                                       |
| electrical\_kwh                                                             | The total cumulative amount of kWh consumed. This is typically from a meter reading.                                                               |
| electrical\_kwh\_interval                                                   | The amount of kWh consumed since the last data point.                                                                                              |
| rssi                                                                        | The signal strength of the IoT device.                                                                                                             |

These signals are accepted as a JSON string published to an MQTT topic for the station. e.g.

```
MQTT Topic: busroot/v2/[Account ID]/signals/[Station Code]

Payload:
{
  "production_count_good": 12.4,
  "electrical_kwh": 15774.45
}
```

## MQTT Access

In order for IoT device to communicate with the Busroot MQTT broker, they must use valid credentials consisting of a `Device ID` and `Access Token`.

The `Device ID` is made up of the account ID followed by a `/` and a unique value for that device.

When using these credentials with the MQTT broker, a username, password and client ID must be provided as follows:

| MQTT Field | Value                                   |
| ---------- | --------------------------------------- |
| Username   | `Device ID`                             |
| Password   | `Access Token`                          |
| Client ID  | `Device ID` + `/` + `[optional string]` |

After MQTT authentication, the device is connected but can only publish and subscribe to specific topics:

Busroot Signals Topic: `busroot/v1/` + `Device ID`\
Raw Data Topic: `busroot/v1/dau/` + `Device ID`

Data published to the Busroot Signals topic will be processed directly by Busroot according to the signals mentioned at the top of this page.

Data published to the topic starting with `busroot/v1/dau/` will not be processed by Busroot. The purpose of this topic is to allow raw data to be sent from the device and processed in a second stage (e.g. using Node-RED) which will then re-publish that data to the Busroot Signals topic.

## Registering Devices

<figure><img src="/files/hEQcJU49RdsVLFjBWs6j" alt=""><figcaption></figcaption></figure>

### New Device

The 'Add New' button will create a new device with a unique `Device ID` and `Access Token`.

### Removing Access for a Device

When it is required that a device no longer be able to send data to Busroot, the device ID should be deleted from Busroot. This will cause that device to be immediately disconnected from the MQTT broker.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.output.industries/technical-onboarding/integration/mqtt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
