# 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<username>[^/]+)/(?P<device>[^/]+)$")
def regex_topic(match, data, **kwargs):
device = match.groupdict()
print(device['username'], device['device])
print(data)
```
# Authentication
## mosquitto-go-auth
Used with <https://github.com/iegomez/mosquitto-go-auth>
```python
# From example project urls
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
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 false
auth_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
```
Raw data
{
"_id": null,
"home_page": "",
"name": "django-mqtt",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "django mqtt",
"author": "Paul Traylor",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/5f/9b/85eb1ad77776d315f44a554555ee1b582ceb2e0acbc368b65902ee737945/django-mqtt-0.4.3.tar.gz",
"platform": null,
"description": "# django-mqtt\n\nMQTT tools for Django project\n\n[![PyPI](https://img.shields.io/pypi/v/django-mqtt)](https://pypi.org/project/django-mqtt/)\n\n# Usage\n\n- Add `\"dmqtt\"` to your `INSTALLED_APPS`\n- Add `MQTT_HOST`, `MQTT_USER`, `MQTT_PASS`, `MQTT_PORT`\n- Run with `python manage.py mqtt`\n\n```python\nfrom dmqtt.signals import connect, regex, topic\nfrom django.dispatch import receiver\n\n@receiver(connect)\ndef on_connect(sender, **kwargs):\n sender.subscribe(\"#\")\n\n@topic(\"some/mqtt/topic\")\ndef simple_topic(sender, topic, data, **kwargs):\n print(topic)\n print(data)\n\n@regex(\"^some/(?P<username>[^/]+)/(?P<device>[^/]+)$\")\ndef regex_topic(match, data, **kwargs):\n device = match.groupdict()\n print(device['username'], device['device])\n print(data)\n```\n\n# Authentication\n\n## mosquitto-go-auth\n\nUsed with <https://github.com/iegomez/mosquitto-go-auth>\n\n```python\n# From example project urls\nfrom django.contrib import admin\nfrom django.urls import include, path\n\nurlpatterns = [\n path(\"mosquitto/\", include(\"dmqtt.mosquitto\")),\n path(\"account/\", include((\"django.contrib.auth.urls\", \"auth\"), namespace=\"auth\")),\n path(\"admin/\", admin.site.urls),\n]\n```\n\n```\n# mosquitto configuration\n# https://github.com/iegomez/mosquitto-go-auth#http\nauth_plugin /mosquitto/go-auth.so\nauth_opt_backends http\nauth_opt_check_prefix false\n\nauth_opt_http_host example.com\nauth_opt_http_getuser_uri /mosquitto/getuser\nauth_opt_http_aclcheck_uri /mosquitto/aclcheck\n\n# If using https\nauth_opt_http_port 443\nauth_opt_http_with_tls true\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "",
"version": "0.4.3",
"project_urls": {
"Issues": "http://github.com/kfdm/django-mqtt/issues",
"Source Code": "http://github.com/kfdm/django-mqtt"
},
"split_keywords": [
"django",
"mqtt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7243253b8cb94c1582c29c3363216cea02ad6f9003d2a40377dcfe683dd2f93",
"md5": "3facb7aabbfafa0955082469b4960bcf",
"sha256": "7d6aa0f5c9b837d80eed7035c6f6d0258afd70560a847def0e822f51350eae4a"
},
"downloads": -1,
"filename": "django_mqtt-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3facb7aabbfafa0955082469b4960bcf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 11942,
"upload_time": "2024-02-19T12:26:56",
"upload_time_iso_8601": "2024-02-19T12:26:56.898865Z",
"url": "https://files.pythonhosted.org/packages/c7/24/3253b8cb94c1582c29c3363216cea02ad6f9003d2a40377dcfe683dd2f93/django_mqtt-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5f9b85eb1ad77776d315f44a554555ee1b582ceb2e0acbc368b65902ee737945",
"md5": "86905686ef09b733af35adac1ec1c295",
"sha256": "78e6cdbb12a310aae090de352753a189b2ead6a3227ca1ae557b1deaf62846b9"
},
"downloads": -1,
"filename": "django-mqtt-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "86905686ef09b733af35adac1ec1c295",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9149,
"upload_time": "2024-02-19T12:26:58",
"upload_time_iso_8601": "2024-02-19T12:26:58.476429Z",
"url": "https://files.pythonhosted.org/packages/5f/9b/85eb1ad77776d315f44a554555ee1b582ceb2e0acbc368b65902ee737945/django-mqtt-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-19 12:26:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kfdm",
"github_project": "django-mqtt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-mqtt"
}