Iris is a C++ application that integrates MQTT messaging with a PostgreSQL database. It listens to specified MQTT topics, processes messages, decrypts them if necessary, and stores them in a PostgreSQL database.
- MQTT Integration: Uses the Mosquitto library to subscribe to and receive MQTT messages.
- PostgreSQL Storage: Saves incoming messages in a PostgreSQL database.
- AES Encryption Handling: Supports AES-CBC encrypted messages and decrypts them using OpenSSL.
- Configurable Topics: Reads topics and encryption keys from a JSON configuration file.
- JSON-Based Configuration: Uses
jsoncppto load database and MQTT settings dynamically.
- C++ Compiler (e.g.,
g++with C++17+ support) - Mosquitto (MQTT client library)
- libpqxx (PostgreSQL C++ client library)
- OpenSSL (For AES decryption)
- jsoncpp (For JSON parsing)
- PostgreSQL Database Server
sudo apt update && sudo apt install -y libmosquitto-dev libpqxx-dev libssl-dev libjsoncpp-devbrew install mosquitto libpqxx openssl jsoncppvcpkg install mosquitto libpqxx openssl jsoncppmkdir build && cd build
cmake ..
make -j$(nproc)Create a config.json file in the root directory with the following structure:
{
"mqtthost": "localhost",
"mqttport": 1883,
"mqtttimeout": 60,
"postgresqlhost": "127.0.0.1",
"postgresqlport": 5432,
"postgresqldbname": "mydatabase",
"postgresqluser": "myuser",
"postgresqlpassword": "mypassword",
"topics": [
{ "name": "sports/football", "aeskey": "your_aes_key_here" },
{ "name": "news/weather" }
]
}./irisConnected to database: mydatabase
Subscribed to: sports/football
Subscribed to: news/weather
Receiving messages.
iris.cpp- Loads configuration from
config.json. - Connects to PostgreSQL.
- Initializes
IrisMQTTClientand subscribes to topics.
- Loads configuration from
irismqttclient.h / irismqttclient.cpp- Handles MQTT message reception.
- Decrypts AES-CBC messages (if encrypted).
- Stores messages in PostgreSQL.
topic.h- Represents an MQTT topic with an optional AES key.
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
topic VARCHAR(255) NOT NULL,
message_payload TEXT NOT NULL,
received_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Feel free to submit pull requests or report issues if you find bugs or improvements.
This project is licensed under the MIT License.
Author: Matthew Grigajtis
Project: Iris