Skip to main content
MQTT Gateway is configured through environment variables defined in a .env file. All settings are loaded at startup from the environment.

Configuration file

Create a .env file in the root directory of the project. You can use .env.example as a template:
cp .env.example .env

Database connection

DB_HOST
string
required
Database server hostname or IP address.Example: 192.168.0.137
DB_PORT
integer
default:"3306"
Database server port number.Example: 3306
DB_NAME
string
required
Name of the database to connect to.Example: db
DB_USER
string
required
Database username for authentication.Example: demo
DB_PASSWORD
string
required
Database password for authentication.Example: demo
The gateway uses these credentials to build a SQLAlchemy connection URL in the format: mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}

MQTT settings

MQTT_CLIENT_ID
string
default:"mqtt-gateway"
Unique identifier for the MQTT client connection. This ID is used when connecting to the MQTT broker.Example: mqtt-gateway
MQTT_KEEPALIVE
integer
default:"60"
MQTT keepalive interval in seconds. The client will send ping messages to the broker at this interval to maintain the connection.Example: 60

Operational settings

LOG_DIR
string
default:"./log"
Directory path where log files will be written.Example: ./log
HTTP_TIMEOUT_SECONDS
integer
default:"10"
Timeout in seconds for HTTP requests when forwarding messages to HTTP endpoints.Example: 10
FLOWS_RELOAD_INTERVAL_SECONDS
integer
default:"600"
Interval in seconds between automatic reloads of flow configurations from the database. This allows the gateway to pick up configuration changes without restarting.Minimum value: 1Example: 600 (10 minutes)

Example configuration

# Database connection
DB_HOST=192.168.0.137
DB_PORT=3306
DB_NAME=db
DB_USER=demo
DB_PASSWORD=demo

# Logging
LOG_DIR=./log

# HTTP settings
HTTP_TIMEOUT_SECONDS=10

# MQTT settings
MQTT_CLIENT_ID=mqtt-gateway
MQTT_KEEPALIVE=60

# Flow configuration
FLOWS_RELOAD_INTERVAL_SECONDS=600
Ensure that required environment variables (DB_HOST, DB_NAME, DB_USER, DB_PASSWORD) are set before starting the gateway. Missing required variables will cause the application to fail at startup.

Build docs developers (and LLMs) love