Dash with MQTT
dash_mqtt is a Dash component library for adding MQTT messaging functionality to your Dash apps.
It is essentially a wrapper around MQTT.js.
Usage
Simple echo example using emqx.io test MQTT broker.
import dash_mqtt
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
TEST_SERVER = 'broker.emqx.io'
TEST_SERVER_PORT = 8083
TEST_SERVER_PATH = 'mqtt'
MESSAGE_OUT_TOPIC = 'testtopic'
MESSAGE_IN_TOPIC = 'testtopic'
app = dash.Dash(__name__)
app.layout = html.Div([
dash_mqtt.DashMqtt(
id='mqtt',
broker_url=TEST_SERVER,
broker_port = TEST_SERVER_PORT,
broker_path = TEST_SERVER_PATH,
topics=[MESSAGE_IN_TOPIC]
),
html.H1('MQTT echo'),
html.P('MQTT echo server to ' + TEST_SERVER + ' on port ' + str(TEST_SERVER_PORT)),
dcc.Input(
id='message_to_send',
placeholder='message to send',
debounce = True),
html.Button('Send',id='send'),
html.Div(id='return_message')
])
@app.callback(
Output('mqtt', 'message'),
Input('send', 'n_clicks'),
State('message_to_send', 'value')
)
def display_output(n_clicks, message_payload):
if n_clicks:
return {
'topic': MESSAGE_OUT_TOPIC,
'payload' : message_payload
}
return dash.no_update
NOTE
MQTT.js is running as an MQTT client in the browser in this implementation (As a React component as per typical Dash components). Subsequently, from here:
- There is no way for JavaScript running in browsers to open TCP sockets so "normal" MQTT is impossible in browser apps.
- To get around this limitation, MQTT.js uses MQTT over WebSockets instead when it detects it's running in a browser.
This means that you need to set the broker_port up to point at the MQTT-over-WebSockets port of the MQTT broker you are using, or if you are setting up your own broker server, turn on MQTT-over-WebSockets and expose a port.
Help with developing the component
If you are want to adapt or help develop the component, refer README_DEV.md
Currently written to suit author's needs - MQTT broker running in a DOcker Container on a local network for home IOT scenarion using IOTStack, so have not put any effort into encrypted messaging.
Metadata
Release files for dash-mqtt 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dash_mqtt-0.0.2.tar.gz | 299.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dash_mqtt-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 602.2 kB
Release files / dash_mqtt-0.0.2.tar.gz
| Download URL | dash_mqtt-0.0.2.tar.gz |
|---|---|
| Size | 299.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66b3934e876ae5f9c3e2c73dc8262fe265bd0167946ed1ce6be5011d849826c5
|
|
BLAKE2b-256 checksum How to use checksums |
db1d73f27fded711f033a5f25b29f762cc71a49b8c2cd1f3aa587984f09c3306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.2
|
Release files / dash_mqtt-0.0.2-py3-none-any.whl
| Download URL | dash_mqtt-0.0.2-py3-none-any.whl |
|---|---|
| Size | 302.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
05b8e6e62a15257d71820f420941c734022b19329ee99ddb2d2bf353b61a3e9c
|
|
BLAKE2b-256 checksum How to use checksums |
452fce53bf704b67fcd640337035d0bdc5467f0e066e4bc0a8ad791b39ce8595
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.2
|
Security for dash-mqtt 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.