Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kfdm/django-mqtt
https://github.com/kfdm/django-mqtt
django mqtt mqtt-client
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kfdm/django-mqtt
- Owner: kfdm
- License: mit
- Created: 2020-09-01T11:14:09.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-19T12:28:02.000Z (9 months ago)
- Last Synced: 2024-09-26T11:48:15.651Z (about 1 month ago)
- Topics: django, mqtt, mqtt-client
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# django-mqtt
MQTT tools for Django project
[![PyPI](https://img.shields.io/pypi/v/django-mqtt)](https://pypi.org/project/django-mqtt/)
# Usage
- Add `"dmqtt"` to your `INSTALLED_APPS`
- Add `MQTT_HOST`, `MQTT_USER`, `MQTT_PASS`, `MQTT_PORT`
- Run with `python manage.py mqtt````python
from dmqtt.signals import connect, regex, topic
from django.dispatch import receiver@receiver(connect)
def on_connect(sender, **kwargs):
sender.subscribe("#")@topic("some/mqtt/topic")
def simple_topic(sender, topic, data, **kwargs):
print(topic)
print(data)@regex("^some/(?P[^/]+)/(?P[^/]+)$")
def regex_topic(match, data, **kwargs):
device = match.groupdict()
print(device['username'], device['device])
print(data)
```# Authentication
## mosquitto-go-auth
Used with
```python
# From example project urls
from django.contrib import admin
from django.urls import include, pathurlpatterns = [
path("mosquitto/", include("dmqtt.mosquitto")),
path("account/", include(("django.contrib.auth.urls", "auth"), namespace="auth")),
path("admin/", admin.site.urls),
]
``````
# mosquitto configuration
# https://github.com/iegomez/mosquitto-go-auth#http
auth_plugin /mosquitto/go-auth.so
auth_opt_backends http
auth_opt_check_prefix falseauth_opt_http_host example.com
auth_opt_http_getuser_uri /mosquitto/getuser
auth_opt_http_aclcheck_uri /mosquitto/aclcheck# If using https
auth_opt_http_port 443
auth_opt_http_with_tls true
```