Skip to main content

Command-line utility designed to facilitate the interconnection between serial devices and an MQTT server. This project is based on the `mqtty` library and allows simple configuration using a TOML file.

Project description

mqtty-cli

mqtty-cli is a command-line utility designed to facilitate the interconnection between serial devices and an MQTT server. This project is based on the mqtty library and allows simple configuration using a TOML file.

Installation

You can install mqtty-cli directly from PyPI:

pip install ki2-mqtty-cli

Usage

Basic Command

Once installed, the mqtty-cli command will be available. You can use it to start the interconnection using a TOML configuration file.

mqtty-cli <path-to-settings.toml>

If no path is provided, the program will attempt to load a configuration file named settings.toml from the current directory. You can also specify the path using the MQTTY_CONFIG environment variable.

Configuration

The configuration file must be written in TOML format. Here is an example settings.toml file:

# MQTT Configuration
[mqtt]
host = "localhost"
port = 1883

[[devices]]
# Device 1 configuration
topic = "device/1"
port = "/dev/ttyACM0"
baudrate = 9600

[[devices]]
# Device 2 configuration
topic = "device/2"
port = "/dev/ttyACM1"
baudrate = 9600

Field Details

MQTT Section ([mqtt])

Field Type Default Description
host string "localhost" Address of the MQTT server
port int 1883 Port of the MQTT server
auth table None Authentication configuration (optional)

If authentication is required, add the following fields:

[mqtt.auth]
username = "my-username"
password = "my-password"

Devices Section ([[devices]])

Each serial device must be defined as a table in a [[devices]] list.

Field Type Default Description
topic string - MQTT topic associated with the device
port string - Serial port of the device (e.g., /dev/ttyACM0)
baudrate int 9600 Serial communication speed
bytesize int 8 Size of serial data
parity string "None" Parity (None, Even, Odd, Mark, Space, or N, E, O, M, S)
stopbits float 1 Number of stop bits
timeout int / null null Timeout in seconds (null to disable)
xonxoff bool False XON/XOFF flow control
rtscts bool False RTS/CTS flow control
write_timeout float / null null Write timeout
dsrdtr bool False DSR/DTR flow control
inter_byte_timeout float / null null Timeout between bytes
exclusive bool / null null Exclusive mode for the serial port
endline_char string (1) "\n" End-of-line character
mqtt_start string (1) "@" Start character for MQTT messages
mqtt_separator string (1) ":" Separator in MQTT messages

Example Execution

  1. Create a settings.toml configuration file with your parameters.
  2. Run the following command:
mqtty-cli settings.toml

You will see a message indicating that the devices have been configured and the interconnection has started:

Path = settings.toml
New device '/dev/ttyACM0' on topic 'device/1'
New device '/dev/ttyACM1' on topic 'device/2'

Programming Example for Serial Devices

For serial devices, all messages received on the associated topic are sent directly to the device without any specific start or end characters.

To publish to a specific topic from the device, messages written to the serial port should follow the format:

@<topic>:<payload>\n
  • <topic> is the target MQTT topic.
  • <payload> is the message to be published.

Arduino Example

void setup() {
  Serial.begin(9600);
  Serial.println("Arduino is ready!");
}

void loop() {
  // Send data to the MQTT broker
  if (Serial.available()) {
    String topic = "other-topic"; // Specify the target topic
    String payload = Serial.readStringUntil('\n');
    Serial.print("@");
    Serial.print(topic);
    Serial.print(":");
    Serial.println(payload);
  }
}

In this example, the Arduino listens on its serial input and formats outgoing messages to publish to the topic other-topic.

License

This project is distributed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ki2_mqtty_cli-1.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ki2_mqtty_cli-1.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file ki2_mqtty_cli-1.0.1.tar.gz.

File metadata

  • Download URL: ki2_mqtty_cli-1.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.0-130-generic

File hashes

Hashes for ki2_mqtty_cli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4329b37d105f7edacbd8b3a1bad8a18680a6fdff0505e3fb082ae5867733c5a3
MD5 43acd57c18db44819c3a0a5a9939b44c
BLAKE2b-256 d5125d10a533edc8b565f04debe41fca76bbddd8b45ecec162c2c2be23906ea0

See more details on using hashes here.

File details

Details for the file ki2_mqtty_cli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ki2_mqtty_cli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/5.15.0-130-generic

File hashes

Hashes for ki2_mqtty_cli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd73aab5a1bc1d60bee522b8f4058c18a72c1dafd28ae5938d30ceaf113b378
MD5 6e962e1442e4774fe6bf34f9d3e0e36f
BLAKE2b-256 b64f9d2f3b69f26677d81f400fe9529ae780390bc51f398be8b9e8bbe0a01a0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page