Skip to main content

No project description provided

Project description

django-mqtt

MQTT tools for Django project

PyPI

Usage

  • Add "dmqtt" to your INSTALLED_APPS
  • Add MQTT_HOST, MQTT_USER, MQTT_PASS, MQTT_PORT
  • Run with python manage.py mqtt
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

# 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mqtt-0.4.0.tar.gz (7.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page