Relayed servers
The hub can carry other LemmeKnow Servers to your phone through the same address and port your phone already uses for the hub. Each relayed server shows up in LemmeKnow as a server of its own, with its own status dot, log sources and states, and nothing about it mixes with the hub or with other servers.
How it works
The other server's Mosquitto sends its LemmeKnow topics to the hub's broker over a TLS bridge, signed in with a publish key the hub gives you. Those messages land in an inbox only the hub can read. The hub checks each one and passes on what's allowed, under the other server's own server id, to phones that hold a server key for it. The same person's normal access key sees only the hub.
What the hub checks:
- Only what a plain LemmeKnow Server publishes gets through: its heartbeat, its config message, its public and private logs, and the states its scripts send. Pings and hub features such as feeds, states, plugins, and approvals never do, and the hub address in the config message is removed, so a hub can't be reached through another hub.
- A publish key can write only to its own server's inbox and can read nothing. It's accepted only from the addresses you allow, your private networks by default.
- Each relayed server is limited to 600 messages a minute, 200 log sources, 100 states, and 1 MB per message. Anything over a limit is dropped and counted on the task card.
The other server needs no open port, no auth plugin and no users. It keeps publishing to its own broker as it does now, and the bridge carries the messages out.
Add a relayed server
Create the relay. On the Tasks page, add a task and pick Relayed server. Enter the other server's Server id, the 8 characters LemmeKnow Server prints when it starts (server_id=…). Allowed addresses lists the address ranges its bridge may sign in from, separated by spaces; leave it empty for your private networks.
Get the bridge settings. Save, then choose Bridge setup (the key button) on the task's card and Create bridge settings. The hub shows the settings once, with a new publish key in them. Creating them again replaces the key, and the old bridge stops until it gets the new settings.
Add them to the other server's Mosquitto. Paste the settings into that PC's mosquitto.conf, then:
- Replace
HUB_ADDRESS:1884with the address and port phones use for the hub's broker. - Copy the hub broker's certificate (
server.crtfrom its Mosquittocertsfolder) to that PC and put its path inbridge_cafile. The bridge then accepts only that certificate.bridge_insecure trueonly skips matching the certificate's name to the address; it doesn't skip the certificate check.
Restart that Mosquitto. Within a minute the task card shows receiving <server id> and how long ago its last heartbeat arrived.
The settings look like this:
connection lemmesee-a1b2c3d4
address HUB_ADDRESS:1884
bridge_protocol_version mqttv311
remote_clientid lemmeknow-relay-a1b2c3d4
remote_username relay_…
remote_password …
bridge_cafile /path/to/hub_broker.crt
bridge_insecure true
notifications false
try_private false
cleansession true
topic a1b2c3d4/# out 1 lemmeknow/ inbox/
Turning the task off, deleting it, or changing its server id or allowed addresses disconnects the bridge right away.
Give someone access
On the Users page, click Keys on the user's row. Under Relayed servers, pick the server and choose Create. The hub shows the key once, along with what to enter in the app:
- Host and port: the same as that person's hub server.
- Username: their usual hub username.
- Access key: the new server key.
They add it in LemmeKnow like any other server. Each person has one key per server, so the list only offers servers they don't have a key for yet. Revoke a key from the same dialog to cut them off from the server within seconds; the person's hub access is untouched. To give them a new key, for example after a lost phone, revoke the old one and create another; their permissions stay as they were. Deleting the relayed server task revokes all of its keys.
Choose what they see
Choose Permissions next to a person's server key. The hub lists the log sources and states that server has sent, so you tick real names instead of typing them. A log source the server hasn't used for 30 days drops off the list, and comes back, with the same tick, if the server uses it again. A state stays until the server clears it.
- Public logs show to everyone with a key for the server. Untick a source to hide it from this person.
- Private logs and States show only when ticked.
- Everything on this server covers all of its private logs and states, including ones it sends later.
Unticking something always hides it from that person, even when a wider grant such as Everything on this server or an admin's * would otherwise include it: the hub records a revocation, and a revocation wins over every grant. Changes reach the phone within a few seconds. Permissions belong to the person rather than the key, so creating a new key keeps them. Deleting the relayed server task removes them.
The hub's own grants, such as states.* in the Read Only preset, don't reach relayed servers. Each relayed server is permitted on its own. Under the hood the keys are relay.<server id>.logs.public.<source>, relay.<server id>.logs.private.<source> and relay.<server id>.states.<group>.<name>, and they also appear in the person's grants.
States from a relayed server
A script on the relayed server can send states with log_client, and the hub turns them into states on the phone, shown on the relayed server's Status tab and usable in rules. They also appear on the hub's States page, under the relayed server's tab:
import log_client
log_client.SOURCE = "nas"
log_client.state("c_drive", {"value": 72, "max": 100, "label": "72% used"},
label="C: drive", display="progress", interval=300)
log_client.state("uptime", "3d 4h", label="Uptime", interval=300)
| Argument | Default | Meaning |
|---|---|---|
name | (required) | The state's name, unique within its group. |
value | (required) | The value, in the shape its display expects. See States. |
label | name | Name shown next to the value. |
display | "text" | How phones draw the value. |
group | log_client.SOURCE | Groups states on the phone. Letters, digits, -, and _. |
group_label | the group | Display name for the group. |
alarm | False | True while the state is in alarm. |
interval | 0 | How often you send it, in seconds, so phones can mark it stale. |
fields | None | Named values for rules to test. |
sort_order | None | Position within the group. |
log_client.clear_state(name, group=None) removes a state. The Logger class has matching state() and clear_state() methods that use its source as the group.
States are retained, so each one is a single stored value that every update replaces, and a phone that connects later sees the latest value straight away. When the relayed server or its bridge restarts, its latest values are sent again. Turning the relayed server task off clears its states on phones; turning it back on brings back the latest values. A phone connected straight to LemmeKnow Server, without the hub, ignores states.
When things go down
- If the relayed server or its bridge stops, its status dot goes red on the usual heartbeat timeout. The hub's dot stays green.
- If the hub restarts, the bridge and phones stay connected to the broker, and relaying picks up again as soon as the hub is back.
- If the hub is down, phones can't sign in to its broker, so the hub and every relayed server go offline together.