somestuff-mqttwebstuff 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. somestuff_mqttwebstuff-0.1.4/.gitignore +180 -0
  2. somestuff_mqttwebstuff-0.1.4/LICENSE.md +163 -0
  3. somestuff_mqttwebstuff-0.1.4/PKG-INFO +230 -0
  4. somestuff_mqttwebstuff-0.1.4/README.md +198 -0
  5. somestuff_mqttwebstuff-0.1.4/pyproject.toml +55 -0
  6. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/README.md +198 -0
  7. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/__init__.py +123 -0
  8. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/hub.py +343 -0
  9. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/mqttweb.env.example +58 -0
  10. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugin_api.py +292 -0
  11. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/oepnv_view.py +138 -0
  12. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/extra_head.html.j2 +32 -0
  13. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/oepnv_alert.html.j2 +5 -0
  14. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/oepnv_departures.html.j2 +21 -0
  15. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/oepnv_line.html.j2 +14 -0
  16. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/oepnv_stale.html.j2 +7 -0
  17. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/plugins/templates/oepnv_status.html.j2 +18 -0
  18. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/py.typed +0 -0
  19. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/serve.py +258 -0
  20. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/somestuff-mqttweb-secret.example.yaml +19 -0
  21. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/somestuff_mqttweb_deployment.yml +165 -0
  22. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/static/htmx-ext-sse.js +290 -0
  23. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/static/htmx.min.js +1 -0
  24. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/static/pico.min.css +4 -0
  25. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/templates/base.html.j2 +134 -0
  26. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/templates/generic_item.html.j2 +9 -0
  27. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/templates/generic_tree_item.html.j2 +20 -0
  28. somestuff_mqttwebstuff-0.1.4/somestuff/mqttwebstuff/webapp.py +167 -0
@@ -0,0 +1,180 @@
1
+ /**/.gtfs_cache
2
+ /*.local
3
+ .claude
4
+
5
+ /*gguf*
6
+
7
+ /docker-config
8
+ /docker_build_local.log
9
+
10
+ /ms?hit
11
+ *mstest*py
12
+ *_test.py
13
+ /umqtt
14
+ .idea/
15
+ /upydev_.config
16
+ *.local.*
17
+ /scripts/logdir/
18
+
19
+
20
+ # Byte-compiled / optimized / DLL files
21
+ __pycache__/
22
+ *.py[cod]
23
+ *$py.class
24
+
25
+ # C extensions
26
+ *.so
27
+
28
+ # Distribution / packaging
29
+ .Python
30
+ build/
31
+ develop-eggs/
32
+ dist/
33
+ downloads/
34
+ eggs/
35
+ .eggs/
36
+ lib/
37
+ lib64/
38
+ parts/
39
+ sdist/
40
+ var/
41
+ wheels/
42
+ share/python-wheels/
43
+ *.egg-info/
44
+ .installed.cfg
45
+ *.egg
46
+ MANIFEST
47
+
48
+ # PyInstaller
49
+ # Usually these files are written by a python script from a template
50
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
51
+ *.manifest
52
+ *.spec
53
+
54
+ # Installer logs
55
+ pip-log.txt
56
+ pip-delete-this-directory.txt
57
+
58
+ # Unit test / coverage reports
59
+ htmlcov/
60
+ .tox/
61
+ .nox/
62
+ .coverage
63
+ .coverage.*
64
+ .cache
65
+ nosetests.xml
66
+ coverage.xml
67
+ *.cover
68
+ *.py,cover
69
+ .hypothesis/
70
+ .pytest_cache/
71
+ cover/
72
+
73
+ # Translations
74
+ *.mo
75
+ *.pot
76
+
77
+ # Django stuff:
78
+ *.log
79
+ local_settings.py
80
+ db.sqlite3
81
+ db.sqlite3-journal
82
+
83
+ # Flask stuff:
84
+ instance/
85
+ .webassets-cache
86
+
87
+ # Scrapy stuff:
88
+ .scrapy
89
+
90
+ # Sphinx documentation
91
+ docs/_build/
92
+
93
+ # PyBuilder
94
+ .pybuilder/
95
+ target/
96
+
97
+ # Jupyter Notebook
98
+ .ipynb_checkpoints
99
+
100
+ # IPython
101
+ profile_default/
102
+ ipython_config.py
103
+
104
+ # pyenv
105
+ # For a library or package, you might want to ignore these files since the code is
106
+ # intended to run in multiple environments; otherwise, check them in:
107
+ # .python-version
108
+
109
+ # pipenv
110
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
111
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
112
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
113
+ # install all needed dependencies.
114
+ #Pipfile.lock
115
+
116
+ # poetry
117
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
119
+ # commonly ignored for libraries.
120
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121
+ #poetry.lock
122
+
123
+ # pdm
124
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
125
+ #pdm.lock
126
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
127
+ # in version control.
128
+ # https://pdm.fming.dev/#use-with-ide
129
+ .pdm.toml
130
+
131
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
132
+ __pypackages__/
133
+
134
+ # Celery stuff
135
+ celerybeat-schedule
136
+ celerybeat.pid
137
+
138
+ # SageMath parsed files
139
+ *.sage.py
140
+
141
+ # Environments
142
+ .env
143
+ .venv
144
+ env/
145
+ venv/
146
+ ENV/
147
+ env.bak/
148
+ venv.bak/
149
+
150
+ # Spyder project settings
151
+ .spyderproject
152
+ .spyproject
153
+
154
+ # Rope project settings
155
+ .ropeproject
156
+
157
+ # mkdocs documentation
158
+ /site
159
+
160
+ # mypy
161
+ .mypy_cache/
162
+ .dmypy.json
163
+ dmypy.json
164
+
165
+ # Pyre type checker
166
+ .pyre/
167
+
168
+ # pytype static type analyzer
169
+ .pytype/
170
+
171
+ # Cython debug symbols
172
+ cython_debug/
173
+
174
+ # PyCharm
175
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
178
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
179
+ #.idea/
180
+
@@ -0,0 +1,163 @@
1
+ GNU Lesser General Public License
2
+ =================================
3
+
4
+ _Version 3, 29 June 2007_
5
+ _Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_
6
+
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+
11
+ This version of the GNU Lesser General Public License incorporates
12
+ the terms and conditions of version 3 of the GNU General Public
13
+ License, supplemented by the additional permissions listed below.
14
+
15
+ ### 0. Additional Definitions
16
+
17
+ As used herein, “this License” refers to version 3 of the GNU Lesser
18
+ General Public License, and the “GNU GPL” refers to version 3 of the GNU
19
+ General Public License.
20
+
21
+ “The Library” refers to a covered work governed by this License,
22
+ other than an Application or a Combined Work as defined below.
23
+
24
+ An “Application” is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A “Combined Work” is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the “Linked
32
+ Version”.
33
+
34
+ The “Minimal Corresponding Source” for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The “Corresponding Application Code” for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ ### 1. Exception to Section 3 of the GNU GPL
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ ### 2. Conveying Modified Versions
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ * **a)** under this License, provided that you make a good faith effort to
58
+ ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+
62
+ * **b)** under the GNU GPL, with none of the additional permissions of
63
+ this License applicable to that copy.
64
+
65
+ ### 3. Object Code Incorporating Material from Library Header Files
66
+
67
+ The object code form of an Application may incorporate material from
68
+ a header file that is part of the Library. You may convey such object
69
+ code under terms of your choice, provided that, if the incorporated
70
+ material is not limited to numerical parameters, data structure
71
+ layouts and accessors, or small macros, inline functions and templates
72
+ (ten or fewer lines in length), you do both of the following:
73
+
74
+ * **a)** Give prominent notice with each copy of the object code that the
75
+ Library is used in it and that the Library and its use are
76
+ covered by this License.
77
+ * **b)** Accompany the object code with a copy of the GNU GPL and this license
78
+ document.
79
+
80
+ ### 4. Combined Works
81
+
82
+ You may convey a Combined Work under terms of your choice that,
83
+ taken together, effectively do not restrict modification of the
84
+ portions of the Library contained in the Combined Work and reverse
85
+ engineering for debugging such modifications, if you also do each of
86
+ the following:
87
+
88
+ * **a)** Give prominent notice with each copy of the Combined Work that
89
+ the Library is used in it and that the Library and its use are
90
+ covered by this License.
91
+
92
+ * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
93
+ document.
94
+
95
+ * **c)** For a Combined Work that displays copyright notices during
96
+ execution, include the copyright notice for the Library among
97
+ these notices, as well as a reference directing the user to the
98
+ copies of the GNU GPL and this license document.
99
+
100
+ * **d)** Do one of the following:
101
+ - **0)** Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+ - **1)** Use a suitable shared library mechanism for linking with the
109
+ Library. A suitable mechanism is one that **(a)** uses at run time
110
+ a copy of the Library already present on the user's computer
111
+ system, and **(b)** will operate properly with a modified version
112
+ of the Library that is interface-compatible with the Linked
113
+ Version.
114
+
115
+ * **e)** Provide Installation Information, but only if you would otherwise
116
+ be required to provide such information under section 6 of the
117
+ GNU GPL, and only to the extent that such information is
118
+ necessary to install and execute a modified version of the
119
+ Combined Work produced by recombining or relinking the
120
+ Application with a modified version of the Linked Version. (If
121
+ you use option **4d0**, the Installation Information must accompany
122
+ the Minimal Corresponding Source and Corresponding Application
123
+ Code. If you use option **4d1**, you must provide the Installation
124
+ Information in the manner specified by section 6 of the GNU GPL
125
+ for conveying Corresponding Source.)
126
+
127
+ ### 5. Combined Libraries
128
+
129
+ You may place library facilities that are a work based on the
130
+ Library side by side in a single library together with other library
131
+ facilities that are not Applications and are not covered by this
132
+ License, and convey such a combined library under terms of your
133
+ choice, if you do both of the following:
134
+
135
+ * **a)** Accompany the combined library with a copy of the same work based
136
+ on the Library, uncombined with any other library facilities,
137
+ conveyed under the terms of this License.
138
+ * **b)** Give prominent notice with the combined library that part of it
139
+ is a work based on the Library, and explaining where to find the
140
+ accompanying uncombined form of the same work.
141
+
142
+ ### 6. Revised Versions of the GNU Lesser General Public License
143
+
144
+ The Free Software Foundation may publish revised and/or new versions
145
+ of the GNU Lesser General Public License from time to time. Such new
146
+ versions will be similar in spirit to the present version, but may
147
+ differ in detail to address new problems or concerns.
148
+
149
+ Each version is given a distinguishing version number. If the
150
+ Library as you received it specifies that a certain numbered version
151
+ of the GNU Lesser General Public License “or any later version”
152
+ applies to it, you have the option of following the terms and
153
+ conditions either of that published version or of any later version
154
+ published by the Free Software Foundation. If the Library as you
155
+ received it does not specify a version number of the GNU Lesser
156
+ General Public License, you may choose any version of the GNU Lesser
157
+ General Public License ever published by the Free Software Foundation.
158
+
159
+ If the Library as you received it specifies that a proxy can decide
160
+ whether future versions of the GNU Lesser General Public License shall
161
+ apply, that proxy's public statement of acceptance of any version is
162
+ permanent authorization for you to choose that version for the
163
+ Library.
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.5
2
+ Name: somestuff-mqttwebstuff
3
+ Version: 0.1.4
4
+ Summary: Live web view onto MQTT streams: FastAPI + mountable mapper plugins, Server-Sent Events, htmx/PicoCSS frontend
5
+ Project-URL: Homepage, https://github.com/vroomfondel/somestuff
6
+ Project-URL: Repository, https://github.com/vroomfondel/somestuff
7
+ Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
8
+ Author-email: Henning Thieß <ht@xomox.cc>
9
+ License-File: LICENSE.md
10
+ Keywords: dashboard,fastapi,htmx,iot,mqtt,server-sent-events,sse
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: FastAPI
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Home Automation
20
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.13
23
+ Requires-Dist: fastapi>=0.143
24
+ Requires-Dist: jinja2>=3.1
25
+ Requires-Dist: loguru>=0.7.3
26
+ Requires-Dist: mqttstuff>=0.0.7
27
+ Requires-Dist: python-dotenv>=1.2
28
+ Requires-Dist: tabulate>=0.10
29
+ Requires-Dist: typer>=0.27
30
+ Requires-Dist: uvicorn>=0.54
31
+ Description-Content-Type: text/markdown
32
+
33
+ # mqttwebstuff
34
+
35
+ A tiny live web view onto arbitrary MQTT streams: FastAPI subscribes to the
36
+ broker, a **mapper plugin** (a plain, mountable Python file or module)
37
+ filters/maps every message, and the browser receives rendered HTML fragments via
38
+ **Server-Sent Events**, displayed with **htmx** (+ SSE extension) on **PicoCSS**.
39
+ No frontend build, no framework; the only hand-written JavaScript is a dozen
40
+ lines in `base.html.j2` preserving open `<details>` states across SSE swaps.
41
+
42
+ ## Modules
43
+
44
+ - **`serve.py`**: Typer CLI (`mqttweb-serve`). Loads the mapper plugin (or the
45
+ generic fallback), connects to the broker and runs the web app with uvicorn.
46
+ The MQTT connection tolerates an unreachable broker at startup: paho keeps
47
+ retrying in the background while the web app is already up (empty board,
48
+ `/healthz` showing `mqtt_connected: false`).
49
+ - **`hub.py`**: `ViewHub`, the last-value cache between MQTT and the browsers.
50
+ It keeps the last rendered item per `(panel, key)` and fans updates out to all
51
+ SSE clients. Messages are submitted thread-safely from paho's network thread.
52
+ - **`plugin_api.py`**: the contract between core and plugin. `ViewEvent`
53
+ describes one mapped message (panel, key, data, template, sort, group, title,
54
+ ttl); `load_plugin` validates a mapper given as a file path or dotted module.
55
+ - **`webapp.py`**: the FastAPI app and the Jinja2 environment (including the
56
+ `hhmm` filter).
57
+ - **`plugins/oepnv_view.py`**: reference mapper rendering the `oepnvstuff`
58
+ GTFS-realtime stream as a departure board (departures, feed status,
59
+ per-line coverage, service alerts). It follows the publisher's topic base via
60
+ `OEPNV_MQTT_BASE_TOPIC` (default `oepnv`; multi-level bases like `home/oepnv`
61
+ work).
62
+ - **`templates/`, `static/`**: built-in Jinja2 templates (generic JSON card,
63
+ indented topic tree) and vendored htmx, htmx-ext-sse and PicoCSS, so the
64
+ server serves everything itself (no CDN egress).
65
+
66
+ Logging (loguru, with an intercept for stdlib `logging` from `paho` and
67
+ `uvicorn`) and the startup banner are shared via `somestuff.mqttwebstuff`.
68
+
69
+ ```
70
+ MQTT broker ──> paho thread ──> ViewHub (last-value cache) ──> SSE ──> htmx swaps panels
71
+ │
72
+ mapper plugin
73
+ filter / panel / key / template / ttl
74
+ ```
75
+
76
+ ### Why a cache in the middle?
77
+
78
+ Streams such as the oepnv one publish with `retain=False`. The hub keeps the
79
+ last rendered item per `(panel, key)`, so a freshly opened tab gets the full
80
+ current board server-rendered on `GET /`, then only deltas over `GET /stream`.
81
+ Items carry a TTL, so topics that stop being published disappear from the
82
+ board, mirroring the non-retained semantics.
83
+
84
+ ### Endpoints
85
+
86
+ | Route | Purpose |
87
+ |------------|-----------------------------------------------------------------|
88
+ | `/` | Full board, server-rendered from the cache |
89
+ | `/stream` | SSE: `panel:<name>` repaints, `board` on new panels, keepalives |
90
+ | `/healthz` | `{"ok": true, "mqtt_connected": ...}` |
91
+
92
+ ### Deep links
93
+
94
+ Group boxes (e.g. one stop on the oepnv board) and tree rows carry stable,
95
+ ASCII-slugged anchor ids: `/#g-<panel>-<label>` and `/#t-<topic>`, e.g.
96
+ `/#g-departures-ellerbek-moordamm` or `/#t-nodered-hydrostatics-hydrostatic1`.
97
+ Hovering a label reveals its self-link (`#`); the jump target is highlighted.
98
+ Since ids survive repaints and restarts, the links are bookmarkable.
99
+
100
+ ## Installation
101
+
102
+ ```bash
103
+ pip install somestuff-mqttwebstuff
104
+ ```
105
+
106
+ `somestuff` is a PEP 420 namespace; the package is imported as
107
+ `somestuff.mqttwebstuff` and shares the namespace with the other `somestuff-*`
108
+ distributions.
109
+
110
+ ## Usage
111
+
112
+ The console script and module invocation are equivalent:
113
+
114
+ ```bash
115
+ mqttweb-serve --mapper somestuff.mqttwebstuff.plugins.oepnv_view --mqtt-host broker.example.org
116
+ python3 -m somestuff.mqttwebstuff.serve --mapper somestuff.mqttwebstuff.plugins.oepnv_view --mqtt-host broker.example.org
117
+ ```
118
+
119
+ `--mapper` accepts a dotted module name on the import path (as above) or the
120
+ path of a `.py` file, e.g. `--mapper /config/my_view.py`. In a repository
121
+ checkout, `--mapper somestuff/mqttwebstuff/plugins/oepnv_view.py` works as well.
122
+
123
+ Without a mapper, a generic view shows every message of the `--topics` patterns:
124
+
125
+ ```bash
126
+ # default layout: indented hierarchical topic tree (branch rows per level,
127
+ # scalars inline, JSON collapsible)
128
+ mqttweb-serve --topics 'ecowitt/#,oepnv/status' --mqtt-host broker.example.org
129
+
130
+ # ad-hoc: peek into a whole topic tree and keep items forever
131
+ mqttweb-serve --mapper "" --topics 'nodered/#' --item-ttl 0 --title "Node-RED Live"
132
+
133
+ # one JSON card per topic instead of the tree
134
+ mqttweb-serve --mapper "" --topics 'nodered/#' --view flat
135
+ ```
136
+
137
+ `--mapper ""` explicitly overrides a mapper configured via environment or env
138
+ file; a configured mapper otherwise wins over `--topics`. `--item-ttl` defaults
139
+ to 900 seconds (an item without a new message disappears), `0` keeps items
140
+ forever. `mqttweb-serve --help` lists all options.
141
+
142
+ ## Configuration
143
+
144
+ Every option is also an environment variable (CLI wins over environment). The
145
+ tool additionally loads `mqttweb.local.env` from the current working directory
146
+ and from the package directory; precedence is real environment, then the CWD
147
+ file, then the package-directory file, with CLI options over all.
148
+
149
+ | Variable | CLI option | Default | Meaning |
150
+ |-----------------------------|-----------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
151
+ | `MQTTWEB_MAPPER` | `--mapper` | empty (generic view) | Mapper plugin: `.py` file path or dotted module name |
152
+ | `MQTTWEB_TOPICS` | `--topics` | `#` | Comma-separated subscribe patterns, generic view only |
153
+ | `MQTTWEB_ITEM_TTL` | `--item-ttl` | `900` | Generic view: seconds until an unrefreshed card disappears, `0` = forever |
154
+ | `MQTTWEB_VIEW` | `--view` | `hierarchical` | Generic view layout: `hierarchical` or `flat` |
155
+ | `MQTTWEB_TITLE` | `--title` | empty (plugin's `TITLE`) | Page title override |
156
+ | `MQTTWEB_LISTEN_HOST` | `--listen-host` | `0.0.0.0` | Bind address |
157
+ | `MQTTWEB_LISTEN_PORT` | `--listen-port` | `8080` | Bind port |
158
+ | `MQTTWEB_LIMIT_CONCURRENCY` | `--limit-concurrency` | `0` (unlimited) | Reject new connections with 503 above N concurrent ones. Every open tab holds one SSE stream and a page load briefly needs several slots, so size generously (100+), not per user |
159
+ | `MQTTWEB_MQTT_HOST` | `--mqtt-host` | `mosquitto.mosquitto.svc.cluster.local` | MQTT broker host |
160
+ | `MQTTWEB_MQTT_PORT` | `--mqtt-port` | `1883` | MQTT broker port |
161
+ | `MQTTWEB_MQTT_USER` | `--mqtt-user` | empty (anonymous) | MQTT username |
162
+ | `MQTTWEB_MQTT_PASSWORD` | `--mqtt-password` | empty | MQTT password |
163
+ | `MQTTWEB_MQTT_TLS` | `--mqtt-tls` | `false` | Encrypt the MQTT connection; the port is not switched automatically, set `--mqtt-port` (usually 8883) |
164
+ | `MQTTWEB_MQTT_TLS_CA` | `--mqtt-tls-ca` | empty (system CA store) | CA certificate path |
165
+ | `MQTTWEB_MQTT_TLS_CERT` | `--mqtt-tls-cert` | empty | Client certificate path (mutual TLS) |
166
+ | `MQTTWEB_MQTT_TLS_KEY` | `--mqtt-tls-key` | empty | Client key path (mutual TLS) |
167
+ | `MQTTWEB_MQTT_TLS_INSECURE` | `--mqtt-tls-insecure` | `false` | Skip TLS hostname verification (self-signed certs); encrypted but MITM-able |
168
+ | `MQTTWEB_VERBOSE` | `--verbose`, `-v` | `false` | DEBUG logging, including the uvicorn access log |
169
+
170
+ `--topics`, `--item-ttl` and `--view` are ignored when a mapper is set.
171
+ Plugin-specific settings are plain environment variables the plugin reads
172
+ itself; the oepnv plugin reads `OEPNV_MQTT_BASE_TOPIC` at load time.
173
+
174
+ The repository additionally contains an annotated `mqttweb.env.example`, a
175
+ Kubernetes deployment example and a secret example (not part of the installed
176
+ package): https://github.com/vroomfondel/somestuff/tree/main/somestuff/mqttwebstuff/
177
+
178
+ ## Writing a mapper plugin
179
+
180
+ A plugin is one Python file (or an importable module), no packaging needed.
181
+ Required attributes: `SUBSCRIPTIONS` and `map_message`. Optional: `TITLE`,
182
+ `PANELS` (panel name to heading, fixes the board order; an empty heading means a
183
+ plain panel without chrome) and `TEMPLATE_DIR`. `payload` is already decoded: a
184
+ `dict`/`list` when the raw payload parses as JSON, otherwise the raw string.
185
+
186
+ ### Library
187
+
188
+ ```python
189
+ from somestuff.mqttwebstuff.plugin_api import ViewEvent
190
+
191
+ TITLE = "My Stream"
192
+ SUBSCRIPTIONS = ["mystream/#"]
193
+ PANELS = {"main": "Main"} # optional: fixes panel order + headings
194
+
195
+ # May also return a list of ViewEvents (one message -> several board items,
196
+ # e.g. a leaf plus synthesized ancestor rows, as the generic hierarchical view
197
+ # does) or None to drop the message.
198
+ def map_message(topic: str, payload) -> ViewEvent | None:
199
+ if not isinstance(payload, dict):
200
+ return None # filter
201
+ return ViewEvent(
202
+ panel="main", # board section
203
+ key=topic, # stable identity -> idempotent replace
204
+ data=payload, # template context
205
+ template=None, # None = built-in generic JSON card
206
+ sort="", # ordering within the panel/group ("" = by key)
207
+ group="", # optional sub-heading label (e.g. stop name);
208
+ # items cluster under it, "" = ungrouped
209
+ ttl=300.0, # vanish after 5 min without re-publish
210
+ )
211
+ ```
212
+
213
+ Save it as `my_view.py` and run `mqttweb-serve --mapper my_view.py --mqtt-host broker.example.org`.
214
+
215
+ Templates: put Jinja2 files (`*.html.j2`) into a `templates/` directory next to
216
+ the plugin file (or set `TEMPLATE_DIR`, relative to the plugin's directory). The
217
+ plugin's directory is searched first, the built-ins second, so a plugin can also
218
+ override `base.html.j2` or add styles via an `extra_head.html.j2` include. The
219
+ `hhmm` filter formats ISO timestamps as `HH:MM`.
220
+
221
+ In Kubernetes, mount the plugin (+ templates) from a ConfigMap and point
222
+ `MQTTWEB_MAPPER` at it; see the deployment example in the repository (link
223
+ above). The oepnv reference plugin is part of the package, so the oepnv board
224
+ needs no mount at all.
225
+
226
+ ## Notes
227
+
228
+ - Requires: `loguru`, `typer`, `fastapi`, `uvicorn`, `jinja2`, `python-dotenv`,
229
+ `tabulate`, `mqttstuff`.
230
+ - Licensed under the LGPL, see `LICENSE.md` in the repository root.