# Configuring the MQTT server

This script allows you to subscribe to an MQTT topic, receive messages and store them in a SQLite database. The steps to configure and execute it correctly are described below.

##### **1. Configuration of the configuration file**

Before running the script, a configuration file in **.ini** format must be created. This file contains the necessary parameters for the connection to the MQTT broker, the database and the log configuration. An example of a configuration file is as follows:

```
[DEFAULT]

;;topic
topic = testtopic/#

;; connection
host = test.mosquitto.org
port = 1883
;; protocol supports:  tcp, websockets, unix
; protocol = websockets 
; user = ro
; password = readonly
; ssl = 0
; trust_ssl = 1

;; Database
dblocation = /opt/pandora/pandora_iot_server/db
dbname = pandora_iot.db
; data_cleaning_interval = 300  
; data_cleaning_period = 86400  

;; Logs
log_name = pandora_iot.log   
log_location = /var/log/pandora/
; log_level = debug              
; max_log_bytes = 50_000_000         
; log_rotation_count = 3
```

##### **Key parameters:**

- **topic:** Defines the MQTT topic to which the script will subscribe (e.g. testtopic/#).
- **host :** Specify the address of the MQTT broker.
- **port:** Specify the port of the MQTT broker.
- **protocol:** The protocol to use for the MQTT connection (e.g. tcp or websockets).
- **ssl:** Enables or disables the SSL connection (0 for disable, 1 for enable).
- **trust\_ssl:** Controls whether to trust the broker's SSL certificates.
- **dblocation:** Directory where the SQLite database will be stored.
- **dbname:** Name of the SQLite database.
- **data\_cleaning\_interval:** Time interval (in seconds) between each execution of the data cleaning process.
- **data\_cleaning\_period:** Time (in seconds) to remove old data from the database.
- **log\_name:** Name of the file where the logs will be stored.
- **log\_location:** Directory where the log files will be stored.
- **log\_level:** Log detail level (e.g. debug).
- **max\_log\_bytes:** Maximum size (in bytes) that a log file can reach before being rotated.
- **log\_rotation\_count:** Maximum number of log files that will be kept before deleting the oldest ones.

##### **2. Start the service.**

The service can be launched with the following command :

```
systemctl start pandora_iot_server
```

To stop receiving and storing messages, you can pause the service with :

```
systemctl stop pandora_iot_server
```

<p class="callout warning">The service must be restarted with each configuration change for it to take effect:</p>

```bash
systemctl restart pandora_iot_server
```

##### **3. Start server from console**

In version 783, the following token was introduced to enable the IOT server.

To get there, we need to go to the *Management &gt; Settings &gt; System Settings &gt; General Setup*

Then enable the Enable IOT server field and finally press Update.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-07/scaled-1680-/vqCimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-07/vqCimage.png)