2025-05-21 13:53:46 +00:00
# Quickstart
2015-11-04 13:32:40 +00:00
2025-05-21 13:53:46 +00:00
`aMQTT` is an open source `MQTT` client and broker implementation; these can be integrated into other projects using the appropriate APIs. To get started, three command-line scripts are also installed along with the package:
2015-11-04 21:32:10 +00:00
2025-05-22 01:59:12 +00:00
- `amqtt` - the MQTT broker
- `amqtt_pub` - an MQTT client to publish messages
- `amqtt_sub` - an MQTT client to listen for messages
2015-11-04 21:32:10 +00:00
2025-05-21 13:53:46 +00:00
To install the `aMQTT` package:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```bash
(venv) $ pip install amqtt
```
2015-11-04 21:32:10 +00:00
2025-05-21 13:53:46 +00:00
## Running a broker
2015-11-04 21:32:10 +00:00
2025-05-21 13:53:46 +00:00
`amqtt` is a command-line tool for the MQTT 3.1.1 compliant broker:
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```bash
$ amqtt
[2015-11-06 22:45:16,470] :: INFO - Listener 'default' bind to 0.0.0.0:1883 (max_connections=-1)
```
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
See [amqtt reference documentation ](references/amqtt.md ) for details about available options and settings.
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
## Publishing messages
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
`amqtt_pub` is a command-line tool which can be used for publishing some messages on a topic. It requires a few arguments like broker URL, topic name, QoS and data to send. Additional options allow more complex use case.
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
Publishing `some_data` to as `/test` topic using a TCP connection to `test.mosquitto.org` :
2025-05-20 23:40:56 +00:00
2025-05-21 13:53:46 +00:00
```bash
$ amqtt_pub --url mqtt://test.mosquitto.org -t test -m some_data
[2015-11-06 22:21:55,108] :: INFO - amqtt_pub/5135-myhostname.local Connecting to broker
[2015-11-06 22:21:55,333] :: INFO - amqtt_pub/5135-myhostname.local Publishing to 'test'
[2015-11-06 22:21:55,336] :: INFO - amqtt_pub/5135-myhostname.local Disconnected from broker
```
2015-11-04 21:32:10 +00:00
2025-05-20 23:40:56 +00:00
Websocket connections are also supported:
2015-11-04 21:32:10 +00:00
2025-05-21 13:53:46 +00:00
```bash
$ amqtt_pub --url ws://test.mosquitto.org:8080 -t test -m some_data
[2015-11-06 22:22:42,542] :: INFO - amqtt_pub/5157-myhostname.local Connecting to broker
[2015-11-06 22:22:42,924] :: INFO - amqtt_pub/5157-myhostname.local Publishing to 'test'
[2015-11-06 22:22:52,926] :: INFO - amqtt_pub/5157-myhostname.local Disconnected from broker
```
2025-05-20 23:40:56 +00:00
Additionally, TCP connections can be secured via TLS and websockets via SSL.
2015-11-04 21:32:10 +00:00
2025-05-21 13:53:46 +00:00
`amqtt_pub` can read from file or stdin and use data read as message payload:
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
```bash
$ some_command | amqtt_pub --url mqtt://localhost -t test -l
```
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
See [amqtt_pub reference documentation ](references/amqtt_pub.md ) for details about available options and settings.
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
## Subscribing a topic
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
`amqtt_sub` is a command-line tool which can be used to subscribe to a specific topics or a topic patterns.
2015-11-06 21:47:12 +00:00
2025-05-21 13:53:46 +00:00
Subscribe to the `my/test` topic and the `test/#` topic pattern:
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
```bash
$ amqtt_sub --url mqtt://localhost -t my/test -t test/#
```
2015-11-06 21:47:12 +00:00
2025-05-20 23:40:56 +00:00
This will run and print messages to standard output; it can be stopped by ^C.
2015-11-05 21:46:00 +00:00
2025-05-21 13:53:46 +00:00
See [amqtt_sub reference documentation ](references/amqtt_sub.md ) for details about available options and settings.
2015-11-06 21:47:12 +00:00
2025-05-21 13:53:46 +00:00
## URL Scheme
2015-11-06 21:47:12 +00:00
2025-05-21 13:53:46 +00:00
aMQTT command line tools use the `--url` to establish a network connection with the broker. It follows Python's [urlparse ](https://docs.python.org/3/library/urllib.parse.html ) structure but also adds the [mqtt scheme ](https://github.com/mqtt/mqtt.org/wiki/URI-Scheme ).
2015-11-06 21:47:12 +00:00
2025-05-21 13:53:46 +00:00
```
[mqtt|ws][s]://[username][:password]@host.domain[:port]
```
2015-11-05 21:46:00 +00:00
2025-05-20 23:40:56 +00:00
Here are some examples:
2015-11-04 13:32:40 +00:00
2025-05-21 13:53:46 +00:00
```
mqtt://localhost
mqtt://localhost:1884
mqtt://user:password@localhost
ws://test.mosquitto.org
wss://user:password@localhost
```