Skip to content

Commit

Permalink
Merge pull request #11 from MO-RISE/fix/issue-10-sqlite-queue
Browse files Browse the repository at this point in the history
Changing to use a SQLite-based queue
  • Loading branch information
freol35241 authored Oct 9, 2023
2 parents ab60397 + 3fb8a22 commit 2ea7352
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,59 @@ Use cases:
`pip install mqtt-cli`

## Usage
`mqtt --help`
```
$ mqtt --help
usage: mqtt [-h] [--host HOST] [--port PORT] [--transport {tcp,websockets}] [--clientid CLIENTID] [--user USER] [--password PASSWORD] [--protocol {3,4,5}] [--path PATH] [--tls] [--clean-start] [--log-level LOG_LEVEL]
{publish,subscribe} ...
MQTT command-line client application
positional arguments:
{publish,subscribe}
options:
-h, --help show this help message and exit
--host HOST
--port PORT
--transport {tcp,websockets}
--clientid CLIENTID
--user USER
--password PASSWORD
--protocol {3,4,5}
--path PATH
--tls
--clean-start
--log-level LOG_LEVEL
```

```
$ mqtt publish --help
usage: mqtt publish [-h] [--qos {0,1,2}] [-t TOPIC] [-m MESSAGE] [--line LINE] [--retain] [--queue QUEUE]
options:
-h, --help show this help message and exit
--qos {0,1,2}
-t TOPIC, --topic TOPIC
-m MESSAGE, --message MESSAGE
--line LINE
--retain
--queue QUEUE
```

```
$ mqtt subscribe --help
usage: mqtt subscribe [-h] [--qos {0,1,2}] -t TOPIC [--line LINE] [--json]
options:
-h, --help show this help message and exit
--qos {0,1,2}
-t TOPIC, --topic TOPIC
--line LINE
--json
```


TBC
6 changes: 3 additions & 3 deletions mqtt_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from threading import Thread

from parse import compile
from persistqueue import Queue
from persistqueue import SQLiteQueue
from paho.mqtt.client import Client, MQTTv31, MQTTv311, MQTTv5

logger = logging.getLogger("mqtt")
Expand Down Expand Up @@ -59,7 +59,7 @@ def publish(mq: Client, parser: argparse.ArgumentParser, args: argparse.Namespac
parser.error("--queue is only suitable for use together with qos=0")

@mq.connect_callback()
def _(client, userdata, flags, reason_code, properties):
def _(client, userdata, flags, reason_code, *args):
if reason_code != 0:
logger.error(
"Connection failed to %s with reason code: %s", client, reason_code
Expand All @@ -80,7 +80,7 @@ def _(client, userdata, flags, reason_code, properties):
parser = compile(pattern)

if args.queue:
queue = Queue(args.queue)
queue = SQLiteQueue(args.queue, multithreading=True, auto_commit=False)

def _putter():
for line in sys.stdin:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(fname):

setup(
name="mqtt-cli",
version="0.4.0",
version="0.4.1",
license="Apache License 2.0",
description="CLI for Paho MQTT",
long_description=read("README.md"),
Expand Down

0 comments on commit 2ea7352

Please sign in to comment.