Skip to main content
Get MQTT Gateway up and running quickly with this streamlined guide. For detailed installation instructions, see the installation guide.

Prerequisites

Before you begin, ensure you have:
  • Python 3.12 or higher
  • MariaDB or MySQL server (accessible on your network)
  • MQTT broker (e.g., Mosquitto, HiveMQ)
Don’t have an MQTT broker? You can use test.mosquitto.org or install Mosquitto locally with sudo apt install mosquitto mosquitto-clients

Installation

1

Clone and setup

Clone the repository and create a virtual environment:
2

Install dependencies

Install the required Python packages:
This installs SQLAlchemy, PyMySQL, paho-mqtt, requests, and python-dotenv.
3

Configure environment

Create a .env file with your database and MQTT broker settings:
Edit .env with your database credentials:
Update DB_HOST, DB_NAME, DB_USER, and DB_PASSWORD to match your MariaDB server configuration.
4

Start the gateway

Run the gateway:
On first run, the gateway will:
  • Create database tables (mqtt_servers, flows, data)
  • Insert a default MQTT broker configuration
  • Connect to your MQTT broker

Create your first flow

Now let’s create a flow to receive and store sensor data from MQTT.
1

Connect to your database

Connect to your MariaDB database using your preferred client:
2

Insert a flow

Create a flow that listens to the sensors/aht10 topic and stores data in the database:
This flow:
  • Subscribes to the sensors/aht10 MQTT topic
  • Validates incoming messages against the schema (requires temperature and humidity as floats)
  • Stores valid messages in the data table
3

Wait for flow reload

The gateway reloads flows every 10 minutes by default. To see your flow immediately, restart the gateway:
In production, you can adjust FLOWS_RELOAD_INTERVAL_SECONDS to reload flows more frequently.
4

Publish a test message

Publish a test message to the MQTT broker using mosquitto_pub:
Or using Python:

Verify the data

Query the data table to see your stored message:
Expected output: Each attribute from the JSON payload is stored as a separate row, linked by the last_msg_id counter.

Try an HTTP endpoint flow

You can also forward messages to HTTP endpoints instead of storing them in the database. Create a flow with the POST_ENDPOINT action:
When a message arrives on sensors/aht10/http, the gateway will POST it to the configured endpoint URL.

Next steps

Installation guide

Detailed installation and Docker deployment instructions

Configuration

Learn about all environment variables and database settings

Flows

Understand how flows work and how to configure them

Flow examples

Explore real-world flow examples and use cases