MQTT Finder and MQTT Finder data are available starting with LoxBerry V3.0.
LoxBerry's MQTT Finder is a permanent MQTT "sniffer" that collects all mqtt data from your broker.
For users, a simple user interface allows to explore and inspect mqtt data.
For developers, it allows permanent access to all mqtt data without creating a listening service/daemon and subscriptions.
MQTT Finder is available on every LoxBerry using the url http://loxberry/admin/system/mqtt-finder.cgi (inside the MQTT widget).
From within a plugin, MQTT Finder is thought to be opened in a new browser tab/window without leaving your plugin, therefore it also supports opening it without panels (see below).
Entries shown in green color got updated in the last 60 seconds.
Enabling this checkbox, your search need to correspond to the mqtt subscription syntax with exact match. The mqtt jokers + and # are possible.
This allows to test your subscriptions and see, what data would arrive with your subscription.
http://loxberry/admin/system/mqtt-finder.cgi
?nopanels=1
This can be combined with pro-allocated search query and subscription filter (see next).
As plugin developer, you have the possibility to pre-define the search field by a query parameter
http://loxberry/admin/system/mqtt-finder.cgi
?q=mytext
To enable the subscription exact matching, add parameter e (no value needed):
http://loxberry/admin/system/mqtt-finder.cgi?q=mytext
&e
Don't forget to uri-escape your search string.
MQTT Finder is a service (process name is mqttfinder.pl) that is executed on every boot-time, and subscribes the # topic.
All incoming data - published or retained - are collected and stored every second to the ramdisk file /dev/shm/mqttfinder.json.
Example data structure:
{ "incoming" : { "awattar/advise/Geschirrspüler/device" : { "p" : "Geschirrspüler", "t" : 1636282811.93135 }, "awattar/advise/Geschirrspüler/deviceuid" : { "p" : "5d1c26de-50f5-493c-bbef-1b0f9e259ee1", "t" : 1636282811.93228 } } }
The file contains an object list called incoming
, that contains one object per received topic.
Each topic object contains the properties p
(=payload) and t
(=last received epoch timestamp). Payloads are "as-is", therefore it may contain a json payload (that is correctly escaped to be parsed by a json library).
Accordingly to the timestamp, topics are removed from the file if nothing was received for the last 7 days. Data cleanup takes place every 60 minutes.
When accessing the file /dev/shm/mqttfinder.json, you should consider to implement a shared file lock, and error handling, as the file might get currently written during your try to access. You might implement a retry after some milliseconds if first try fails.
Please consider: