Skip to main content

Interface between MQTT broker and ASGI and Channels 2.0 compatible

Project description

# channels-asgi-mqtt
Interface between MQTT and ASGI and Channels 2.0 compatible


## Installation

```bash
pip install chasgimqtt
```


## Configuration

First you would to configure a valid `channel_layer` endpoint to consume and connect between chasgimqtt and channels.

In `your_channel_application/asgi.py`:

```python
import os
import django
from channels.routing import get_default_application
from channels.layers import get_channel_layer

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_channel_application.settings")
django.setup()

# Application
application = get_default_application()

# Layers
channel_layer = get_channel_layer()
```


## Usage

```bash
chasgimqtt -H iot.eclipse.org -p 1883 --topic=some_topic:2 your_channel_application.asgi:channel_layer
```


## Options

```
chasgimqtt -h

usage: chasgimqtt [-h] [-H HOST] [-p PORT] [-v] [-U USERNAME] [-P PASSWORD]
[--topic TOPICS] [-n CHANNEL_NAME] [-s CHANNEL_SUB]
[-x CHANNEL_PUB]
channel_layer

Simple MQTT bridge for ASGI

positional arguments:
channel_layer The ASGI channel layer instance to use as
path.to.module:instance.path

optional arguments:
-h, --help show this help message and exit
-H HOST, --host HOST MQTT broker host
-p PORT, --port PORT MQTT broker port
-v, --verbosity Set verbosity
-U USERNAME, --username USERNAME
MQTT username to authorised connection
-P PASSWORD, --password PASSWORD
MQTT password to authorised connection
--topic TOPICS MQTT topics with qos to subscribe --topic TOPIC:QOS
--topic /office/sensor:0 --topic /home/sensor:1 If
empty (#, 2) is set as default
-n CHANNEL_NAME, --channel-name CHANNEL_NAME
Name of Channels's channel to send and receive
messages
-s CHANNEL_SUB, --channel-sub CHANNEL_SUB
Name of Channels's channel for MQTT Sub messages,
default is mqtt.pub
-x CHANNEL_PUB, --channel-pub CHANNEL_PUB
Name of Channels's channel for MQTT Pub messages,
default is mqtt.sub
```


**HOST**: MQTT broker host

**PORT**: MQTT broker port, default 1883

**USERNAME**: MQTT username to authorised connection

**PASSWORD**: MQTT password to authorised connection

**TOPICS**: MQTT topics with qos to subscribe. This option expect a valid topic name and a QOS value splited by `:`

To subscribe to a list of topics use the same option `--topic`.

```
--topic some_topic:qos --topic another_topic:qos --topic home/kitchen_gas_sensor:2 --topic home/office_air_sensor:0
```

**CHANNEL_NAME** : Name of Channels's channel to send and receive messages, this `channel_name` must to exist in your channel's consumer, default is `mqtt`.

**CHANNEL_SUB** : Name of Channels's channel for MQTT Sub messages, default is `mqtt.sub`.

**CHANNEL_PUB** : Name of Channels's channel for MQTT Pub messages, default is `mqtt.pub`.



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

chasgimqtt-0.3.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distributions

chasgimqtt-0.3.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

chasgimqtt-0.3.0-py2-none-any.whl (6.1 kB view details)

Uploaded Python 2

File details

Details for the file chasgimqtt-0.3.0.tar.gz.

File metadata

  • Download URL: chasgimqtt-0.3.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/2.7.15

File hashes

Hashes for chasgimqtt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 017cb7518a55728172da0c3bb99d760f3702786cf54b5f88bb7c7f05e11d7df5
MD5 6ce1d226ec5c7239d56c4e22f57bdddf
BLAKE2b-256 7d3e7d40d5a3d96b8dd3d5dc9e33189fd8500544b6af74135c848f83437bf40b

See more details on using hashes here.

File details

Details for the file chasgimqtt-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: chasgimqtt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/2.7.15

File hashes

Hashes for chasgimqtt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20c2a8139f9594ef1e6c2168fea4d0a8225258d9c745fe674e2c4d484342b8de
MD5 62c0a63c1b8ece3f0709b9810e738132
BLAKE2b-256 aab9c0dcbdbd67d989cd73febabf47e14866eea8501a9f081b7c9e8405cd407d

See more details on using hashes here.

File details

Details for the file chasgimqtt-0.3.0-py2-none-any.whl.

File metadata

  • Download URL: chasgimqtt-0.3.0-py2-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/2.7.15

File hashes

Hashes for chasgimqtt-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 feda7ffdccf75efdf7564bb2cf33484831697171d256a7bb6a0089012bb349cd
MD5 46c7808e6b653ad2b9597c7c5d090e10
BLAKE2b-256 7aad6060d6d9921fc18d375b0238f04068d2437c5ae44c237422d5ec578af99b

See more details on using hashes here.

Supported by

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