Running at startup
LemmeKnow Server is an ordinary program that keeps running until you stop it. To have your phone see the PC whenever it's on, start the server automatically. Mosquitto should start automatically too: on Windows its installer sets it up as a service you can start with net start mosquitto, and on Linux the package's service starts at boot.
The server needs the broker to be reachable, but the order doesn't matter much: if the broker isn't up yet, the server keeps retrying in the background (waiting up to a minute between attempts) and connects as soon as it can.
In each example below, replace the paths with your Python executable and the folder that holds lemmeknow.py. The server finds config.py next to lemmeknow.py, so it doesn't matter which folder it starts in.
Starting automatically
Windows
The simplest way on Windows is a Task Scheduler task that runs when you sign in. You can create it from a Command Prompt in one line:
schtasks /Create /TN "LemmeKnow Server" /SC ONLOGON /TR "\"C:\Python313\pythonw.exe\" \"C:\LemmeKnow\lemmeknow.py\""
pythonw.exe runs without a console window. Run schtasks /Run /TN "LemmeKnow Server" to start it now, and schtasks /Delete /TN "LemmeKnow Server" to remove it. To set it up in Task Scheduler instead:
- Open Task Scheduler and choose Create Task.
- On the Triggers tab, add a trigger: At log on.
- On the Actions tab, add an action: Start a program. Set Program to your Python executable (for example
pythonw.exe, which runs without a console window), Add arguments tolemmeknow.py, and Start in to the folder that holdslemmeknow.py. - Save the task.
Because only one copy of the server runs at a time, it's safe if the task fires twice. The second copy notices the first and exits.
Linux
Save this as /etc/systemd/system/lemmeknow.service, with User set to the account that should run the server and the paths set to where you unzipped it. That account needs to be able to write the database file, so set DB_PATH in config.py to a path it owns, such as a file in the server's folder:
[Unit]
Description=LemmeKnow Server
After=network-online.target mosquitto.service
Wants=network-online.target
[Service]
User=you
WorkingDirectory=/home/you/LemmeKnow
ExecStart=/usr/bin/python3 /home/you/LemmeKnow/lemmeknow.py
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Then turn it on and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now lemmeknow
systemctl status lemmeknow shows whether it's running, and journalctl -u lemmeknow -f shows its output, including the server id on the startup line.
With the LemmeSee Hub
If you also run the LemmeSee Hub, add lemmeknow.py as a daemon task instead of starting it yourself. The hub starts it, restarts it if it stops, and shows its status. The hub handles sign-in itself, so the server's own sign-in check stays off while the hub is running. See Tasks.
Checking that it's running
On the phone, the server's status dot turns green once a heartbeat arrives. You can also check from any machine with the Mosquitto command-line tools:
mosquitto_sub -h 192.168.1.10 -t 'lemmeknow/+/heartbeat' -v
The heartbeat is retained, so you see the latest one immediately. Its ts value is the time it was sent, in milliseconds.