Back to Projects & Articles
Raspberry Pi & PicoIoT & Smart HomeHome AutomationLEDs & NeoPixels

Building a Raspberry Pi 5 Family Location Tracker with Node-RED, Mosquitto, and OwnTracks

A journey into home automation and real-time location sharing, with a healthy dose of head-scratching and eventual triumph.

Apr 11, 2025
11 min read
LED family location tracker wall display — a work in progress
LED family location tracker wall display — a work in progress

My latest tinkering has a distinctly familial focus, and this time it’s going to be a visually striking addition to the home! I’m currently wrestling with the exciting challenge of building a custom family tracker LED display that will eventually grace our wall. This meant diving headfirst into getting a Raspberry Pi 5 to play nicely with Node-RED, MQTT, and OwnTracks. The goal is to create a vibrant, at-a-glance representation of where everyone is.

Eventually the display will function like a map, with individual pyramids representing members of our family
Eventually the display will function like a map, with individual pyramids representing members of our family.

Why Node-RED, Mosquitto, No-IP and OwnTracks?

For those new to these tools, here’s a quick rundown of what each piece of the puzzle does:

Node-RED

A visual, flow-based programming tool. Think “drag-and-drop” for connecting hardware, APIs, and online services. I planned to use it to visualise and process the incoming location data.

Mosquitto (MQTT)

A lightweight “message broker” that uses the MQTT protocol. A central hub for devices and mobile phones to send and receive real-time location telemetry efficiently.

No-IP Dynamic DNS

Gives your home Raspberry Pi a stable hostname (like my-pi.ddns.net), even when your home ISP address changes. Essential for external connections.

OwnTracks

An open-source mobile app (iOS and Android) that securely publishes your phone’s live GPS coordinates directly over MQTT to Mosquitto.

Screenshot of visual flow in Node-RED
Screenshot from Node-RED flow editor visualising incoming MQTT coordinates
Screenshots from the Android OwnTracks App — right most screen showing the connection error
Screenshots from the Android OwnTracks App — rightmost screen showing the error which gave me the most grief.

Prerequisites

Before you dive in, you’ll need:

  • A Raspberry Pi 5 (or similar model).
  • Raspberry Pi OS (the latest stable 64-bit version is best).
  • A reliable internet connection with router admin access for port forwarding.
  • A bit of familiarity with the Linux command line (don’t worry, I’ll guide you!).
  • The OwnTracks app installed on each phone you want to track.
Raspberry Pi 5 with SSD ready to serve Node-RED and the Mosquitto broker
Raspberry Pi 5 with SSD ready to serve Node-RED and the Mosquitto broker

Installing the Core Components

Installing Node-RED

I started with Node-RED, eager to get my location visualisation flows up and running. I found a command online that looked promising:

terminal
1bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-install/master/deb_pi.sh)

But, alas, I was greeted with this:

terminal
1/dev/fd/63: line 1: 404:: command not found

A bit of digging revealed that the installation script’s URL had changed. Always a good reminder to check the official Node-RED documentation! The correct way to install Node-RED on Raspberry Pi OS is globally via npm:

terminal
1sudo npm install -g --unsafe-perm node-red

This command uses npm which comes with Node.js, installing Node-RED globally. The --unsafe-perm flag allows npm to run package scripts with elevated privileges when necessary.

Adding User Authentication to Node-RED

To secure your Node-RED web editor with a username and password, you modify the settings.js configuration file:

  1. Stop Node-RED:
    terminal
    1node-red-stop
  2. Open the settings file in nano:
    terminal
    1sudo nano ~/.node-red/settings.js
  3. Find the httpAdminAuth section: Scroll through until you locate the commented-out section:
    ~/.node-red/settings.js
    1// When enabled, you will be asked for this username and password when
    2// you access the Node-RED editor.
    3// httpAdminAuth: {
    4// user: "admin",
    5// pass: "password"
    6// },
  4. Uncomment and set your initial credentials:
    ~/.node-red/settings.js
    1httpAdminAuth: {
    2 user: "my_secure_username",
    3 pass: "my_very_strong_password"
    4},

    Important: This password is plain text initially. In the next step, Node-RED will hash it for production security.

  5. Save changes: Press Ctrl+X, then Y, then Enter.
  6. Start Node-RED in verbose mode:
    terminal
    1node-red -v
  7. Access the editor: Navigate to http://<your_pi_ip>:1880/ in your browser and enter your credentials.
  8. Copy the hashed password: Look at the terminal output for the string starting with Password hash:. Copy that long hash.
  9. Stop Node-RED: Press Ctrl+C.
  10. Update settings.js with the hash:
    ~/.node-red/settings.js
    1httpAdminAuth: {
    2 user: "my_secure_username",
    3 pass: "the_long_hashed_password_string_you_copied"
    4},
  11. Save and start Node-RED:
    terminal
    1node-red-start
Key Node-RED Commands
node-red-start
Start the editor
node-red-stop
Stop the service
node-red-restart
Restart the service
sudo systemctl enable nodered.service
Start on boot

Installing Mosquitto (The MQTT Broker)

Next up was Mosquitto, the crucial component for OwnTracks to communicate. Thankfully, the basic installation was straightforward:

terminal
1sudo apt update
2sudo apt install mosquitto mosquitto-clients
3sudo systemctl start mosquitto
4sudo systemctl enable mosquitto

Testing Mosquitto Locally

To confirm Mosquitto is operational, test pub/sub in two terminal sessions:

Terminal 1 (Subscriber):
terminal-1
1mosquitto_sub -v -t "test/topic" -u "your_username" -P "your_password"
Terminal 2 (Publisher):
terminal-2
1mosquitto_pub -t "test/topic" -m "Hello from Raspberry Pi!" -u "your_username" -P "your_password"

If working properly, the message appears immediately in Terminal 1, proving the broker is routing topics across clients.

Installing and Configuring No-IP (Dynamic DNS for Remote Access)

No-IP was essential to allow my family’s OwnTracks apps to connect to my Mosquitto broker from outside my home network.

First, sign up for a free account at No-IP.com and register a free hostname (e.g., my-pi.ddns.net). Then on the Pi:

terminal
1cd /usr/local/src/
2sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
3sudo tar xf noip-duc-linux.tar.gz
4cd noip-2.1.9-1/ # Adjust this directory name if it differs
5sudo make install
Important No-IP Configuration Tip: If you signed up for No-IP using social sign-in (such as Google), you must generate a dedicated Dynamic DNS Key / Authentication Token in your No-IP account settings. The command-line client cannot authenticate using your Google password!

To run the Dynamic DNS client automatically on boot, create a systemd unit file:

/etc/systemd/system/noip.service
1[Unit]
2Description=No-IP Dynamic DNS Client
3After=network.target
4
5[Service]
6User=root
7WorkingDirectory=/usr/local/src/noip-2.1.9-1/
8ExecStart=/usr/local/bin/noip2
9Restart=on-failure
10
11[Install]
12WantedBy=multi-user.target
terminal
1sudo systemctl enable noip.service
2sudo systemctl start noip.service
3sudo systemctl status noip.service # Confirm status

Setting Up OwnTracks for Family Location Sharing

Now for the core of the project: configuring Mosquitto to authenticate each family member’s phone independently.

Create Mosquitto Users (One Per Phone)

Use -c for the first user only (to create the file), and -b for subsequent users so they are appended without overwriting:

terminal
1# First user (creates password file):
2sudo mosquitto_passwd -c /etc/mosquitto/passwd dad
3
4# Subsequent users (appends without overwriting):
5sudo mosquitto_passwd -b /etc/mosquitto/passwd mum mum_password
6sudo mosquitto_passwd -b /etc/mosquitto/passwd child child_password

Then edit /etc/mosquitto/mosquitto.conf and add these security directives at the bottom:

/etc/mosquitto/mosquitto.conf
1allow_anonymous false
2password_file /etc/mosquitto/passwd
terminal
1sudo systemctl restart mosquitto.service
Router Port Forwarding

You must forward external port 1883 on your home broadband router to the local internal IP address of your Raspberry Pi. This enables phones roaming on 4G/5G mobile networks to reach the broker.

Protocol: TCPExternal Port: 1883Internal IP: <Raspberry Pi IP>Internal Port: 1883

Configuring the OwnTracks App on Each Phone

  1. Install OwnTracks: From the iOS App Store or Google Play Store.
  2. Select MQTT Mode: Choose “MQTT” (or “Private MQTT”). Do NOT select HTTP.
  3. Enter Broker Details:
    • Host: Your No-IP hostname (e.g., yourpi.ddns.net).
    • Port: 1883
    • Username: The username you created in Mosquitto (e.g., dad).
    • Password: The corresponding user password.
    • Client ID: Unique per device (e.g., dad-phone).
    • Tracker ID: 2-character or short person identifier (e.g., da).
    • TLS: Disabled for initial setup.
  4. Connection Tuning: Adjust Desired Accuracy and Distance Filter to strike the ideal balance between location granularity and phone battery life.

Troubleshooting: Lessons from the Frontlines

This is where the real learning (and frustration) began. I encountered a series of errors that tested my patience and problem-solving skills.

1. Mosquitto Authentication Puzzle: “Connection Refused: not authorised”

After setting up credentials, OwnTracks failed to connect, throwing “Connection Refused: not authorised” errors even though I was certain the passwords matched:

OwnTracks error message: Connection Refused: not authorised
Connection Refused: not authorised error dialog in OwnTracks

The Investigation:

  • Verified Mosquitto was running: sudo systemctl status mosquitto.service.
  • Fixed file permissions:
    terminal
    1sudo chown mosquitto:mosquitto /etc/mosquitto/passwd
    2sudo chmod 640 /etc/mosquitto/passwd
  • Discovered I had accidentally overwritten earlier users by using mosquitto_passwd -c repeatedly!
  • The Root Cause: In modern versions of Mosquitto, the broker defaults to listening only on the localhost loopback (127.0.0.1). It was silently rejecting external connections!
The Fix: Add an explicit listener directive in /etc/mosquitto/mosquitto.conf:
/etc/mosquitto/mosquitto.conf
1listener 1883

2. No-IP Service Startup Failure (CHDIR Error)

The No-IP systemd service failed with a cryptic log entry:

systemctl status noip.service
1Failed at step CHDIR spawning /usr/local/bin/noip2: No such file or directory

ChatGPT pointed out that the WorkingDirectory in the service file was pointing to the temporary build folder rather than the binary location.

The Fix: Change WorkingDirectory=/usr/local/src/noip-2.1.9-1/ to:
/etc/systemd/system/noip.service
1WorkingDirectory=/usr/local/bin

Security Recap: Best Practices

Strong PasswordsNon-negotiable for Raspberry Pi OS user, Mosquitto accounts, and Node-RED admin.
Disable AutologinEnsure the Raspberry Pi requires password authorization upon reboot.
Firewall & Port AuditingOnly expose port 1883 externally; do not expose Node-RED or SSH ports without a VPN.
Logging & MonitoringKeep sudo tail -f /var/log/mosquitto/mosquitto.log handy to verify connection attempts.

Setting up a home automation system and a real-time family location map with OwnTracks is a deeply rewarding endeavour. Yes, there were hurdles along the way, but with patience and a little debugging, you can build something truly personalized for your household.

If you’d like to see how my Raspberry Pi family tracker wall display develops into its final LED form, follow along on YouTube . Happy tinkering!