src/models.py.
MqttServer
Stores MQTT broker connection information. The gateway connects to the first enabled server, prioritizing those marked as default. Table name:mqtt_servers
Primary key, auto-incremented
MQTT broker hostname or IP address
MQTT broker port number
Authentication username (optional)
Authentication password (optional)
Whether this server is active. Only enabled servers are considered for connection
Priority flag. The gateway selects enabled servers ordered by
is_default DESC, id ASCsrc/models.py:10-20
Flow
Defines message routing rules. Each flow specifies a topic to subscribe to, validation schema, and destination action. Table name:flows
Primary key, auto-incremented
Unique identifier for the flow (e.g.,
AHT10_SENSOR)Human-readable description of the flow’s purpose
MQTT topic pattern to subscribe to. Supports MQTT wildcards (
+, #)Processing action to perform. Valid values:
STORE_DB: Save payload attributes to thedatatablePOST_ENDPOINT: Forward payload to an HTTP endpoint
Expected payload structure for validation. Format:
{"field_name": "type"}Supported types: string, str, number, float, int, integer, bool, boolean, object, arrayExample: {"temperature": "float", "humidity": "float"}HTTP endpoint URL (required when
action is POST_ENDPOINT)Message counter, incremented with each processed message
Whether this flow is active. Disabled flows are not processed
src/models.py:22-34
DataRecord
Stores individual attribute values from MQTT messages processed bySTORE_DB flows. Each payload field creates a separate record.
Table name: data
Primary key, auto-incremented
UTC timestamp when the message was processed (default:
datetime.utcnow())Reference to the flow that processed this message (matches
Flow.code)Payload field name (e.g.,
temperature, humidity)Serialized value. Primitive types are converted to strings, objects/arrays are JSON-encoded
Message ID from the flow’s counter at time of processing
src/models.py:36-47
Schema relationships
MqttServerhas no direct foreign keys but is loaded byGatewayMqttClient.load_mqtt_server()(src/mqtt_client.py:25-35)Flowis referenced byDataRecordviaflow_code(not enforced as foreign key)- Message IDs in
DataRecord.last_msg_idcorrespond toFlow.last_msg_id