Skip to main content
A flow defines how MQTT Gateway processes messages from a specific MQTT topic. Each flow specifies the topic to listen to, how to validate incoming payloads, and where to route the data.

Flow structure

Flows are stored in the flows database table and contain the following properties:
The code field must be unique across all flows and is used to identify records in the database.

How flows work

When an MQTT message arrives, the gateway performs these steps:
  1. Topic matching: Compares the message topic against all enabled flows using MQTT topic pattern matching (src/mqtt_client.py:84-86)
  2. Payload validation: Validates the JSON payload against the flow’s payload_schema (src/processor.py:92)
  3. Message ID increment: Increments the last_msg_id counter atomically (src/processor.py:94-95)
  4. Action execution: Routes the message based on the flow’s action type
Multiple flows can match the same topic. Each matching flow processes the message independently.

Example flows

Here are real examples from the sample data:

Temperature and humidity to database

This flow listens to sensors/aht10, validates that messages contain temperature and humidity fields as floats, and stores them in the database.

Sensor data to HTTP endpoint

This flow forwards validated messages to an HTTP endpoint via POST request.

Flow reloading

The gateway automatically reloads flows from the database at regular intervals without restarting:
When flows are reloaded, the gateway automatically subscribes to new topics and unsubscribes from removed ones. Changes to existing flows take effect on the next message.

Enabling and disabling flows

Set enabled = 0 to disable a flow without deleting it:
Disabled flows are excluded from the next reload cycle (src/mqtt_client.py:38-40):