MQTT and Mosquitto
The hub doesn't deliver messages to phones itself. It publishes log entries, states, feed updates, and approval requests to a Mosquitto MQTT broker, and each phone subscribes to that broker. The broker is required for the hub.
Two listeners
The usual setup gives Mosquitto two listeners:
- A local listener on
127.0.0.1that allows anonymous access. The hub and your scripts publish here. The hub connects without a username or password, and so does thelog_client.pyhelper. - A listener for phones that requires sign-in and TLS. Phones sign in with their hub username and access key, and the LemmeKnow auth plugin for Mosquitto checks them against the hub.
per_listener_settings true
listener 1883 127.0.0.1
allow_anonymous true
listener 1884
allow_anonymous false
certfile /path/to/server.crt
keyfile /path/to/server.key
plugin /path/to/mosquitto_lk_auth
plugin_opt_auth_host 127.0.0.1
plugin_opt_auth_port 8765
plugin_opt_snapshot_path /path/to/broker_snapshot.txt
The auth plugin is a separate download for Windows and Linux; see Downloads. Install Mosquitto itself as described in Setting up Mosquitto, then use this configuration in place of that page's options.
Plugin options
| Option | Default | Meaning |
|---|---|---|
plugin_opt_auth_host | 127.0.0.1 | Address of the hub the plugin asks to check sign-ins. |
plugin_opt_auth_port | 8765 | The hub's port. |
plugin_opt_snapshot_path | none | The permission file the hub writes. Must match broker_snapshot_path in the hub's config.json. |
plugin_opt_server_id | asked from the hub | Pins the server id. Normally the plugin asks the hub for it and picks up a change without a broker restart, so you can leave this out. |
Settings on the hub side
Two config.json settings must be in place for phone sign-ins to work. See Configuration.
| Setting | What to set |
|---|---|
internal_allow_cidrs | Must include the broker's address, ["127.0.0.1/32"] for a broker on the same PC. Left empty, the hub refuses every sign-in check and no phone can connect. |
broker_snapshot_path | The file the plugin reads each user's permissions from. Use the same path as plugin_opt_snapshot_path. |
Windows
Keep the permission file in C:\ProgramData\mosquitto\, for example C:\ProgramData\mosquitto\lk_snapshot.txt, rather than in C:\Program Files\mosquitto. The hub runs as your own account and can't write inside Program Files, and Mosquitto's service account can read files in ProgramData. Create the folder and give your account write access to it from an administrator Command Prompt:
mkdir C:\ProgramData\mosquitto
icacls C:\ProgramData\mosquitto /grant %USERNAME%:(OI)(CI)MLinux
Keep the permission file outside your home folder, for example /var/lib/lemmesee/lk_snapshot.txt. Mosquitto runs as its own mosquitto user, which can't look inside home folders on most distributions. Create the folder and make it yours, replacing you with the account that runs the hub:
sudo mkdir -p /var/lib/lemmesee
sudo chown you: /var/lib/lemmeseeIf the hub can't write the file, the broker keeps using the last permissions it read, so grants, revocations, and key changes stop reaching phones.
The plugin rereads the permission file every couple of seconds, so grants and revocations you change on the Users page reach the broker without a restart. See Permissions and grants.
A username with 10 failed sign-ins within a minute is locked out for five minutes.
What phones may read
Phones can't publish anything except their answers to approval requests. What they may read depends on the user's grants: public log sources and ping codes are visible unless revoked, while private ones, states, and private feeds need a grant. Per-user topics, such as pings for one user, are only readable by that user. See Logs and pings and Permissions and grants.
Topics the hub publishes
Every topic carries the hub's server id, shown as {sid}. You'll find it on the Dashboard as the hub id.
| Topic | Retained | What it is |
|---|---|---|
lemmesee/{sid}/status | yes | Hub presence: active, webhooks (count), started_ts, ts. |
lemmesee/{sid}/hub-active | yes | "1" while the hub is connected. The broker clears it automatically when the hub disconnects. |
lemmesee/{sid}/states/{plugin}/{name} | yes | One topic per plugin state. See States. |
lemmesee/{sid}/manifests/dirty | no | Tells phones a list (feeds, plugins, pings, log sources, webhooks, filters, streams) changed, so they fetch it again. |
lemmesee/{sid}/feed/{tier}/{feedId}/nudge | no | A feed has items to fetch. {tier} is public or private. |
lemmesee/{sid}/feed/{tier}/{feedId}/items | no | Feed items pushed directly. See Server feeds. |
lemmeknow/{sid}/logs/{tier}/{source} | no | Log entries, including the hub's own and those from tasks and webhooks. |
lemmeknow/{sid}/ping/{tier}/{code} | no | Pings. See Pings. |
lemmeknow/{sid}/actions/{tier} | no | Approval requests for everyone on that tier. See Approvals. |
lemmeknow/{sid}/actions/{topicId} | no | An approval request for one user. The phone answers on the same topic with /response added. |
The log and ping topics are the same ones scripts publish to with LemmeKnow Server's log_client.py helper. The action topics are the hub's own. The heartbeat and config topics phones also need come from LemmeKnow Server, not the hub. See MQTT topics.
When the hub reconnects to the broker, for example after the broker restarts, it publishes its status and hub-active topics again and tells phones to refresh their lists.