> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Uptime heartbeat and component health

> How a MaihueGO machine reports that it is alive and the health of each of its components

Every device of a MaihueGO machine sends a heartbeat to Horizon about every
30 seconds. Horizon turns the heartbeats into the machine's connectivity and,
when the Raspberry includes them, into the live health of each component, its
history, its alerts and the clinical record.

The body is validated per device: each device has its own strict shape, and
only the Raspberry may report components. The schema is published as
`machineUptimeReportSchema` in `@bbrandslab/maihue-street-protocol`, and the
component catalogue as `MACHINE_COMPONENT_CATALOG`.

## Endpoint

```http theme={null}
POST /api/v3/maihue-street/machine/{document_id}/uptime
Authorization: Bearer <machine JWT>
Content-Type: application/json
```

The machine key only reports for its own machine (`404` otherwise). The
permission is `maihue-street-machine:uptime`.

## Component catalogue

The catalogue is closed: Horizon only knows the components below. Three
critical layers and their parts, each reported by its `internal`.

| `internal` | Layer | Critical |
| - | - | - |
| `controller` | — | yes |
| `controller_brand_experience_player` | `controller` | no |
| `controller_kiosk_browser` | `controller` | no |
| `interface` | — | yes |
| `interface_pusher` | `interface` | no |
| `interface_controller_socket` | `interface` | no |
| `mcu` | — | yes |
| `mcu_hat_board` | `mcu` | no |
| `mcu_can_bus` | `mcu` | no |
| `mcu_pressure_board` | `mcu` | no |
| `mcu_bottle_dispenser_board` | `mcu` | no |

A layer is the program (controller, interface, MCU firmware); its parts are
what that program drives. Report every layer and every part in every
heartbeat, even when a layer is down.

## Bodies per device

```json Raspberry with components theme={null}
{
  "device": "raspberry",
  "observed_at": "2026-10-23T13:05:00-03:00",
  "software": { "version": "1.8.2" },
  "components": [
    { "internal": "controller", "status": "ok" },
    {
      "internal": "controller_brand_experience_player",
      "status": "ok",
      "message": "Playing spring-campaign.mp4"
    },
    {
      "internal": "controller_kiosk_browser",
      "status": "ok",
      "message": "https://touch.maihuego.com/machine"
    },
    { "internal": "interface", "status": "ok" },
    { "internal": "interface_pusher", "status": "ok", "message": "connected" },
    { "internal": "interface_controller_socket", "status": "ok" },
    { "internal": "mcu", "status": "ok" },
    {
      "internal": "mcu_hat_board",
      "status": "ok",
      "message": "Last ping 2026-10-23T16:04:58Z"
    },
    {
      "internal": "mcu_can_bus",
      "status": "failed",
      "code": "connection_lost",
      "message": "Bus off since 16:03"
    },
    { "internal": "mcu_pressure_board", "status": "ok" }
  ]
}
```

```json Touch theme={null}
{ "device": "touch", "app_version": "3.4.0" }
```

```json Brand experience / advertising theme={null}
{ "device": "advertising" }
```

A bare `{ "device": "<device>" }` is valid for every device. For the
Raspberry it means "alive, no component report": nothing about the
components changes.

### Component fields

| Field | Type | Rules |
| - | - | - |
| `internal` | string | Required. A catalogue code: lowercase snake\_case (`a-z`, `0-9`, `_`), 2 to 50 characters. Never a `document_id`: it is the same in every environment. |
| `status` | `ok` \| `degraded` \| `failed` | Required. The device decides it; Horizon does not evaluate readings. A component that is running reports `ok`, one that is not reports `failed`; `degraded` is for "running with problems". |
| `code` | string | Optional error code, up to 64 characters (see below). |
| `message` | string | Optional free status, up to 500 characters: the video playing, the page open (without its query string), the last ping. Longer values are rejected, so trim on the device. |
| `metrics` | object | Optional readings (number, string or boolean), up to 32 keys. |
| `details` | object | Optional `serial_number` and `firmware`. |

A heartbeat carries at most 64 components, never the same `internal` twice,
and no other field: unknown fields are rejected (`400`) and the whole
heartbeat with them.

### Error codes

`code` is free text in lowercase snake\_case. Use these when they fit:

| `code` | Meaning |
| - | - |
| `process_stopped` | The program or service is not running. |
| `connection_lost` | A connection (socket, bus, network) dropped. |
| `device_not_responding` | The board or device does not answer. |
| `not_reported` | Set by Horizon, never by the device: the component was left out of the heartbeat. |

## The snapshot is complete

`components` is the full state of the machine in every heartbeat:

* **A component that is not installed is simply not sent.** Optional parts
  (for example the pressure or bottle dispenser sub-boards) only exist on the
  totems that have them; Horizon never expects them elsewhere.
* **A component Horizon already knows on this machine and that is left out
  turns off**: Horizon marks it `failed` with code `not_reported`, records the
  event and opens its alert. To stop showing a part a totem no longer has,
  an operator deactivates it on the machine (Horizon → machine → Componentes).
* **`"components": []`** is a full snapshot with nothing in it: every known
  component turns off. Leaving `components` out is not the same: it reports
  nothing about them.

## Response

```json theme={null}
{
  "data": {
    "device": "raspberry",
    "document_id": "194667ad-8cc6-4335-a806-6dafacc9dffc",
    "seen_at": "2026-10-23T16:05:01.120Z",
    "components": { "accepted": 10, "changed": 1 },
    "unknown_components": ["co2_sensor"]
  }
}
```

* `accepted`: components applied (catalogued and linked to an active link).
* `changed`: components whose status changed with this heartbeat, including
  the ones that turned off for being left out.
* `unknown_components`: internals missing from the catalogue. They are
  ignored, never rejected.

## What Horizon does with it

* **Links:** a catalogued component the machine reports for the first time is
  linked to it automatically ("Detected"). Deactivating a layer on a machine
  deactivates its parts there too; reactivating the layer leaves them as
  they are.
* **History:** one event is stored only when a component's status changes.
* **Alerts:** a component that turns `failed` opens one alert (high severity
  for a layer, medium for a part); reporting `ok` again resolves it. While a
  layer has an open alert its parts record their failures without opening
  alerts of their own; when the layer recovers, each part still failing opens
  its own.
* **Verdict:** the machine reads *Con problemas* when a layer failed,
  *Degradado* when any part is degraded or failed, *Operativo* when every
  component is ok, and *Sin reportes* when the machine has not reported its
  components within the offline window (10 minutes by default).
* **Realtime:** each status change is published as `component:status` on the
  machine's totem channel.
* **Touch version:** a Touch heartbeat with `app_version` stores it in the
  machine's `touch_app_version`, and the time of that heartbeat in
  `touch_app_version_at`, in the same update as `uptime_at_touch`. A heartbeat
  without `app_version` keeps the last one. The machine list and detail
  (`GET /api/v3/maihue-street/machine[/{document_id}]`) return both fields; the
  value is client-reported and only displayed.

## Errors

| Status | When |
| - | - |
| `400` | Unknown device, a field not allowed for the device (for example `components` on `touch`), invalid status, an `internal` that is not lowercase snake\_case, repeated `internal`, a `message` over 500 characters, too many components or readings. |
| `401` / `403` | Missing token or permission. |
| `404` | The machine does not exist or belongs to another key. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.