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
integer
required
Primary key, auto-incremented
string(255)
required
MQTT broker hostname or IP address
integer
default:"1883"
MQTT broker port number
string(255)
Authentication username (optional)
string(255)
Authentication password (optional)
boolean
default:"true"
Whether this server is active. Only enabled servers are considered for connection
boolean
default:"true"
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
integer
required
Primary key, auto-incremented
string(100)
required
Unique identifier for the flow (e.g.,
AHT10_SENSOR)string(255)
required
Human-readable description of the flow’s purpose
string(255)
required
MQTT topic pattern to subscribe to. Supports MQTT wildcards (
+, #)string(30)
required
Processing action to perform. Valid values:
STORE_DB: Save payload attributes to thedatatablePOST_ENDPOINT: Forward payload to an HTTP endpoint
JSON
required
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"}string(500)
HTTP endpoint URL (required when
action is POST_ENDPOINT)integer
default:"0"
Message counter, incremented with each processed message
boolean
default:"true"
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
integer
required
Primary key, auto-incremented
datetime
required
UTC timestamp when the message was processed (default:
datetime.utcnow())string(100)
required
Reference to the flow that processed this message (matches
Flow.code)string(255)
required
Payload field name (e.g.,
temperature, humidity)text
required
Serialized value. Primitive types are converted to strings, objects/arrays are JSON-encoded
integer
required
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