Automatically switch Raspberry HDMI between MagicMirror2 and a desktop

Running a MagicMirror on a Raspberry Pi alongside a desktop PC? Tired of manually changing inputs when the PC boots or shuts down? Here’s a simple Bash script plus systemd service that:

  • Blanks the Pi’s HDMI output whenever your desktop (IP 192.168.0.114) is up
  • Restores the Pi’s HDMI when the desktop shuts down

Prerequisites

1. Create the Bash Script

Save the following as /home/pi/autoHDMI.sh and make it executable:

#!/bin/bash
# autoHDMI.sh — turn Pi HDMI off/on based on desktop presence

DESKTOP_IP="192.168.0.114"    # ← your desktop’s IP
INTERVAL=10                   # seconds between checks

hdmi_off=0
while true; do
  if ping -c1 -W1 "$DESKTOP_IP" &>/dev/null; then
    if [[ $hdmi_off -eq 0 ]]; then
      /usr/bin/vcgencmd display_power 0    # blank HDMI
      hdmi_off=1
    fi
  else
    if [[ $hdmi_off -eq 1 ]]; then
      /usr/bin/vcgencmd display_power 1    # restore HDMI
      hdmi_off=0
    fi
  fi
  sleep "$INTERVAL"
done
chmod +x /home/pi/autoHDMI.sh

2. Test the Commands Manually

Before automating, confirm the blank/unblank work:

# Blank the HDMI output
sudo vcgencmd display_power 0

# Restore it
sudo vcgencmd display_power 1

If you see your monitor lose signal on “0” and regain it on “1,” you’re good to go.

3. Automate with systemd

Create the service file at /etc/systemd/system/autoHDMI.service:

[Unit]
Description=Auto‑HDMI switching (Pi ↔ Desktop)
After=network-online.target
Wants=network-online.target

[Service]
User=pi
ExecStart=/home/pi/autoHDMI.sh
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Enable and start it:

sudo systemctl daemon-reload
sudo systemctl enable --now autoHDMI.service

4. How It Works

  1. Ping check every 10 s (ping -c1 -W1) returns exit code 0 if the desktop answers https://ss64.com/bash/ping.html
  2. Blank: when the desktop is up, the script runs vcgencmd display_power 0
  3. Restore: when the desktop goes down, it runs vcgencmd display_power 1
  4. Your monitor, set to Auto‑select input, sees “no signal” on HDMI 1 and switches to your desktop (HDMI 2). When the Pi’s HDMI returns, it flips back to MagicMirror.

5. We run an X‑screen / LXDE

Source: Raspberry Pi forum thread on disabling blanking with xset (forums.raspberrypi.com)

I stopped my MagicMirror Pi’s X screen from going black by editing the LXDE autostart file and adding three xset lines.

Full file with the changes:

# /etc/xdg/lxsession/LXDE-pi/autostart        
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
point-rpi

# keep the X‑screen awake
@xset s noblank     # no blanking
@xset s off         # disable screensaver


Reboot and the display stays on permanently.

Conclusion

With this setup, your MagicMirror display takes over whenever your desktop is off, and your PC display reclaims the screen as soon as it’s available—no manual input switching needed!




Windows 10/11 and SMB guest access

Windows SMB change and how to lock down your Raspberry Pi with SMB3 encryption:

Windows 10/11 and SMB guest access
Starting with Windows 10 version 1709 (Fall Creators Update) and all Windows 11 releases, Microsoft disabled unauthenticated “guest” access over SMB2 and SMB3 by default to block insecure, unencrypted logons (MKS Technology Inc)
URL: https://support.microsoft.com/en-us/help/4046019/guest-access-in-smb2-disabled-by-default-in-windows-10-and-windows-server-2016

Configuring your Raspberry Pi for SMB3-only, encrypted shares
Samba ≥ 4.2 (your 4.17.12 build included) fully supports SMB 3.x and on-the-wire encryption (Server Fault)
URL: https://serverfault.com/questions/913504/samba-smb-encryption-how-safe-is-it

Replace your /etc/samba/smb.conf with this:

[global]
   workgroup = WORKGROUP
   netbios name = raspberrypi
   server string = Raspberry Pi SMB3 Encrypted
   security = user
   map to guest = never
   usershare allow guests = no
   guest account = nobody

   server min protocol = SMB3
   server max protocol = SMB3
   client min protocol = SMB3
   client max protocol = SMB3
   smb encrypt = required

[data]
   comment = Encrypted SMB3 Share
   path = /data
   browseable = yes
   writable = yes
   valid users = pi
   create mask = 0775
   directory mask = 0775

  1. Prepare the share directory and permissions: sudo mkdir -p /data sudo chown pi:pi /data sudo chmod 775 /data
  2. Add pi as an SMB user: sudo smbpasswd -a pi
  3. Apply changes: sudo systemctl restart smbd

This forces only SMB 3.x connections with required encryption, and only user pi can connect (Server Fault)
URL: https://serverfault.com/questions/895570/how-to-configure-samba-to-work-with-windows-10-1709

Verifying your setup

With these steps, your Windows 10/11 systems stay locked against guest shares, and your Raspberry Pi serves its data only over encrypted SMB 3 connections.




AI Agents with n8n

Want to automate tasks in your homelab or explore what AI agents can do? n8n is a free, open-source automation tool that runs perfectly on a Raspberry Pi 5. With it, you can build smart workflows that connect APIs, trigger actions, and even control AI agents like ChatGPT.

What You Can Do with n8n

  • Trigger AI responses with webhooks
  • Connect apps like Gmail, Telegram, or Google Sheets
  • Automate reports, alerts, backups, and file processing
  • Build AI workflows that take action on your data

No coding is required, but you can use JavaScript and expressions if you want more control.


Install n8n on Raspberry Pi 5 (with Docker)

1. Install Docker

sudo curl -fsSL https://get.docker.com -o get-docker.sh 
sudo sh get-docker.sh
sudo reboot

2. Add User to Docker Group

sudo groupadd docker && sudo usermod -aG docker $USER
sudo reboot

3. (Optional) Install Portainer for GUI Management

docker run -d -p 9000:9000 --name=portainer --restart=always --pull=always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /data/portainer_data:/data \
  portainer/portainer-ee:latest

4. Prepare Data Folders

sudo mkdir -p /data/n8n_data /data/compose/n8n
sudo chmod -R 777 /data

5. Create docker-compose.yml

Save this in /data/compose/n8n/docker-compose.yml:

services:
  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - "5678:5678"
    environment:
      - TZ=Europe/Copenhagen
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=xxxxxxxxxxxx
      - N8N_HOST=10.168.0.277
      - N8N_PORT=5678
      - N8N_SECURE_COOKIE=false
    volumes:
      - /data/n8n_data:/home/node/.n8n

⚠️ Replace the IP address with your Raspberry Pi’s actual IP.

6. Launch n8n

cd /data/compose/n8n
docker compose up -d

Now open your browser:

http://10.168.0.277:5678


n8n + AI agents = powerful automation. Run it in your homelab and take full control of your workflows.




Troubleshooting Network Issues on a Raspberry Pi with pfSense

Troubleshooting Network Issues on a Raspberry Pi with pfSense

Recently, I encountered a network connectivity issue with my Raspberry Pi running Raspberry Pi OS Bookworm, where the device was not receiving an IP address from my pfSense router’s DHCP server. After some investigation and adjustments, I was able to resolve the problem successfully. Here’s a detailed blog post to help others facing similar challenges.

Initial Symptoms

The issue was that my Raspberry Pi, connected via a wired Ethernet connection, was not receiving an IP address from my pfSense DHCP server. The default DHCP client, dhcpcd, was active and causing conflicts. Although NetworkManager was installed, it was not active, leading to further issues.

Diagnosing the Issue

Step 1: Check Network Interface Status

I began by checking the network interface status using:

nmcli device status

The output revealed that eth0 was connected but not receiving an IP address.

Step 2: Verify IP Assignment

To verify whether the Raspberry Pi was assigned an IP address, I used:

ip a show eth0

The result showed an IP address (192.168.0.224) and a valid lease from the pfSense DHCP server.

Step 3: Confirm the Default Gateway

Next, I checked the default gateway configuration:

ip route

The default route correctly pointed to the pfSense router at 192.168.0.1.

Changing DHCP Client to NetworkManager

The default DHCP client on Raspberry Pi OS Bookworm is dhcpcd, which can cause conflicts. To switch to NetworkManager, I used:

sudo raspi-config

I navigated to Advanced Options > Network Config > NetworkManager, selected it, and rebooted the Raspberry Pi. This change resolved the DHCP conflict and allowed the device to obtain an IP address correctly.

Testing Network Connectivity

Ping Test

I ran a basic connectivity test:

ping 8.8.8.8
ping google.com

Both tests were successful, indicating no connectivity issues.

Resolving the Issue

The issue was resolved by disabling dhcpcd and enabling NetworkManager using sudo raspi-config. No further DNS changes were required as the default settings pointed correctly to the pfSense router.

Conclusion

After switching to NetworkManager using sudo raspi-config, my Raspberry Pi successfully received a DHCP lease from the pfSense router, and the network connectivity was fully restored. If you’re experiencing similar issues, following these steps can help identify and resolve the problem effectively.

Feel free to share your own network troubleshooting experiences or reach out for further assistance!




Exciting Announcement: New Kubernetes Cluster on Raspberry Pi

I’m thrilled to announce the successful installation of a brand-new Kubernetes cluster on four Raspberry Pi devices! This project, utilizing Bookworm, Ansible, and NFS, showcases the potential of combining powerful software tools with the versatility of Raspberry Pi hardware.

Project Details

Hardware Setup:

  • Devices: 4 Raspberry Pi 4 units
  • Storage: M.2 256GB USB drives (superior to traditional SD cards for reliability and speed)
  • Networking: A small network switch for robust cabled connections

Software Stack:

  • Operating System: Raspberry Pi OS 64-bit Lite (Bookworm)
  • Automation: Ansible for automated and consistent setup
  • Storage: NFS for shared, reliable storage

Installation Overview

The installation process is impressively quick and efficient, taking about 30 minutes from start to finish:

  • 15 minutes: Installing the OS and necessary dependencies using Ansible
  • 15 minutes: Setting up Kubernetes with one master and three nodes, including auto-provisioned storage via NFS

Services Deployed

As part of this new installation, several key services have already been deployed on the cluster using kubectl:

  • Portainer: For managing Kubernetes environments
  • NetAlert: For network monitoring
  • Prometheus and Grafana: For monitoring and visualization
  • Minecraft Server: For gaming and experimentation
  • Homepage Dashboard: For a personalized user interface
  • Searxng: For metasearch engine capabilities

What’s Next?

In the coming days, I will be posting detailed guides and Ansible scripts for setting up these services on my homepage. These resources will include step-by-step instructions to help you replicate this setup and customize it for your own needs.

Stay tuned for more updates and detailed tutorials on my homepage. This new installation demonstrates the impressive capabilities of Kubernetes on Raspberry Pi, and I’m excited to share more about this journey with you.

Thank you for your interest, and look forward to the upcoming posts with detailed guides and scripts!




Automating NFS Mounts with Autofs on Raspberry Pi for Docker Swarm

When managing a Docker Swarm on a fleet of Raspberry Pis, ensuring consistent and reliable access to shared storage across your nodes is crucial. This is where Autofs comes into play. Autofs is a utility that automatically mounts network file systems when they’re accessed, making it an ideal solution for managing persistent storage in a Docker Swarm environment. In this blog post, we’ll walk through the process of installing and configuring Autofs on a Raspberry Pi to use with an NFS server for shared storage.

Step 1: Setting Up the NFS Server

Before configuring Autofs, you need an NFS server that hosts your shared storage. If you haven’t already set up an NFS server, you can do so by installing the nfs-kernel-server package on your Raspberry Pi designated as the NFS server:

sudo apt install nfs-kernel-server -y

Then, configure the NFS export by editing the /etc/exports file and adding the following line to share the /data directory:

/data 192.168.0.0/24(rw,sync,no_subtree_check,no_root_squash)

Restart the NFS server to apply the changes:

sudo /etc/init.d/nfs-kernel-server restart

Verify the export with:

sudo exportfs

Step 2: Installing Autofs on Client Raspberry Pis

On each Raspberry Pi client that needs access to the NFS share, install Autofs:

sudo apt update -y
sudo apt install autofs -y

Reboot the Raspberry Pi to ensure all updates are applied:

sudo reboot

Step 3: Configuring Autofs

After installing Autofs, you’ll need to configure it to automatically mount the NFS share. Edit the /etc/auto.master file and add a line for the mount point:

/-    /etc/auto.data --timeout=60

Create and edit /etc/auto.data to specify the NFS share details:

/data -fstype=nfs,rw 192.168.0.220:/data

This configuration tells Autofs to mount the NFS share located at 192.168.0.220:/data to /data on the client Raspberry Pi.

Step 4: Starting and Testing Autofs

Enable and start the Autofs service:

sudo systemctl enable autofs
sudo systemctl start autofs

Check the status to ensure it’s running without issues:

sudo systemctl status autofs

To test, simply access the /data directory on the client Raspberry Pi. Autofs should automatically mount the NFS share.

cd /data
ls

If you see the contents of your NFS share, the setup is successful. Autofs will now manage the mount points automatically, ensuring your Docker Swarm has seamless access to shared storage.

Conclusion

By leveraging Autofs with NFS on Raspberry Pi, you can streamline the management of shared volumes in your Docker Swarm, enhancing both reliability and efficiency. This setup minimizes the manual intervention required for mounting shared storage, making your Swarm more resilient to reboots and network changes. Happy Swarming!




Setting Up NTP on Raspberry Pi “Bookworm” for Accurate Timekeeping

Introduction

Accurate timekeeping is essential for various applications, from logging to scheduling tasks. While there are numerous public NTP servers, setting up your own NTP server offers more control and can be quite satisfying. In this blog post, we’ll explore how to configure a Raspberry Pi, affectionately named “Bookworm,” to sync time using an NTP server.

Why Raspberry Pi?

The Raspberry Pi is a versatile and affordable piece of hardware that can handle a variety of tasks, including acting as an NTP client. Its low power consumption and ease of use make it an ideal choice for this purpose.

Prerequisites

  • A Raspberry Pi running a compatible Linux distribution (e.g., Raspbian)
  • Basic knowledge of Linux commands and vi text editor
  • Access to an NTP server (In this example, we use 192.168.0.1)

Step-by-Step Guide

  1. Check Current Time Sync Status
   timedatectl show-timesync --all

This command will display detailed information about the current time synchronization status on your Raspberry Pi.

  1. Edit the Configuration File
   sudo vi /etc/systemd/timesyncd.conf

Open the timesyncd.conf file using the vi text editor with superuser permissions.

  1. Set the NTP Server
   NTP=192.168.0.1

Add this line to the timesyncd.conf file to specify the NTP server you want to use. Save and exit the file.

  1. Restart the Time Sync Service
   sudo systemctl restart systemd-timesyncd

Restart the systemd-timesyncd service to apply the changes.

  1. Verify the Changes
   timedatectl show-timesync --all

Run this command again to confirm that the NTP server is now set to 192.168.0.1.

  1. Check the System Time
   date

Finally, use the date command to display the current system time, ensuring that it is accurate.

Conclusion

Configuring your Raspberry Pi “Bookworm” to use a specific NTP server is a straightforward process that ensures accurate timekeeping. This setup is particularly useful for networks where precise time is crucial. With these simple steps, you can achieve better control and reliability in time synchronization.

I hope you find this guide useful for setting up NTP on your Raspberry Pi “Bookworm.” Feel free to adapt these steps according to your specific needs.




How to Upgrade from Debian Bullseye to Bookworm on Raspberry Pi Without Reinstalling

Upgrading your Raspberry Pi’s operating system doesn’t always require a complete reinstallation. If you’re running Debian Bullseye and want to move to the newer Bookworm version, you can do so with a few simple steps. Before proceeding, make sure to back up all important data.

Step 1: Backup Your Data

First and foremost, backup all your important files. This ensures that you can recover your data in case something goes wrong during the upgrade.

Step 2: Update Current System

Open a terminal and run the following commands to update your existing Bullseye system:

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade

Step 3: Change Repositories

Edit the /etc/apt/sources.list file and any files in /etc/apt/sources.list.d/ to replace ‘bullseye’ with ‘bookworm’. You can use the nano text editor for this:

sudo nano /etc/apt/sources.list

Step 4: Update Package List

After updating the repositories, run the following command to fetch the new package list:

sudo apt update

Step 5: Upgrade Packages

Execute the following commands to perform the upgrade:

sudo apt upgrade
sudo apt dist-upgrade

Step 6: Clean Up

Remove any obsolete packages to free up space:

sudo apt autoremove
sudo apt clean

Step 7: Reboot

Finally, reboot your Raspberry Pi to complete the upgrade:

sudo reboot

And there you have it! You’ve successfully upgraded from Debian Bullseye to Bookworm on your Raspberry Pi without a complete reinstallation. Always remember to read the specific release notes and upgrade instructions for your situation.


Feel free to use or modify this blog post as you see fit!




Optimizing Raspberry Pi Performance: Managing Connectivity with rfkill

Raspberry Pi, the credit-card-sized computer, has found its way into a multitude of projects and use cases, from DIY home automation to industrial applications. While its compact size and versatility make it a favorite among enthusiasts, managing certain aspects of its performance can enhance its capabilities. One such aspect is connectivity, specifically Wi-Fi and Bluetooth, which can be controlled using the rfkill utility. In this blog post, we’ll delve into what rfkill is, how to use it on your Raspberry Pi, and whether disabling Wi-Fi and Bluetooth when not in use can truly boost device performance.

What is rfkill?

rfkill is a command-line utility that allows you to interact with the wireless devices on your system, controlling their radio frequency (RF) state. This utility can be incredibly useful when dealing with Raspberry Pi, as it enables you to manage the state of Wi-Fi and Bluetooth modules easily.

Getting Started: Installation and Basics

To begin utilizing the rfkill utility, you’ll need to install it on your Raspberry Pi if it isn’t already present. Open a terminal and type the following command:

sudo apt install rfkill

Once installed, you can start manipulating the Wi-Fi and Bluetooth modules with simple commands.

  • To block Wi-Fi:
sudo rfkill block wifi

  • To block Bluetooth:
sudo rfkill block bluetooth

Conversely, if you want to unblock these modules to re-enable them, you can use:

  • To unblock Wi-Fi:
sudo rfkill unblock wifi

  • To unblock Bluetooth:
sudo rfkill unblock bluetooth

Performance Boost: To Block or Not to Block?

A common question that arises is whether disabling Wi-Fi and Bluetooth when they’re not in use can truly enhance Raspberry Pi’s performance. The answer isn’t straightforward and largely depends on your specific use case.

While it’s true that turning off these modules can free up system resources and reduce potential electromagnetic interference, the impact on overall performance might not be substantial for most projects. If your Raspberry Pi is performing tasks that do not heavily rely on internet connectivity or Bluetooth devices, you might not notice a significant difference.

However, in scenarios where every ounce of performance matters, such as real-time data processing or high-demand computing tasks, disabling Wi-Fi and Bluetooth could provide a marginal advantage.

Verifying the Status

To check the status of wireless modules, you can use the following command:

rfkill list all

This command will display a list of all wireless devices and their corresponding status (blocked or unblocked).

Conclusion

In conclusion, the rfkill utility offers a straightforward way to manage the connectivity of Wi-Fi and Bluetooth modules on your Raspberry Pi. While there might be a slight performance benefit in certain use cases when disabling these modules, the difference is unlikely to be noticeable for most projects. However, it’s always a good practice to know how to control various aspects of your Raspberry Pi’s functionality, as it might come in handy when working on diverse projects with varying requirements.




Creating Your Own Omada Controller for TP-Link Omada Access Points

Managing multiple TP-Link Omada access points can be a breeze when you have your very own Omada Controller set up. In this guide, we’ll walk you through the process of creating your Omada Controller using a Raspberry Pi, giving you the power to effortlessly handle your access points. Let’s dive in!

Preparing Your Raspberry Pi

To start, make sure your Raspberry Pi is up to date:

sudo apt update && sudo apt upgrade -y
sudo reboot

Installing MongoDB

The Omada Controller relies on MongoDB. Let’s install it:

wget https://repo.mongodb.org/apt/ubuntu/dists/focal/mongodb-org/4.4/multiverse/binary-arm64/mongodb-org-server_4.4.18_arm64.deb
sudo apt install /home/pi/mongodb-org-server_4.4.18_arm64.deb

Ensure MongoDB is running:

sudo systemctl daemon-reload
sudo systemctl enable mongod
sudo systemctl start mongod

Installing Dependencies

You’ll need a few more tools. Install them:

sudo apt install curl autoconf make gcc openjdk-11-jdk-headless
sudo apt remove jsvc

Compiling and Installing JSVC

Download and install JSVC:

wget https://dlcdn.apache.org/commons/daemon/source/commons-daemon-1.3.4-src.tar.gz
tar -xzf commons-daemon-1.3.4-src.tar.gz
cd commons-daemon-1.3.4-src/src/native/unix
sh support/buildconf.sh
./configure --with-java=/usr/lib/jvm/java-11-openjdk-arm64
make

ln -s /home/pi/commons-daemon-1.3.4-src/src/native/unix/jsvc /usr/bin/

sudo mkdir /usr/lib/jvm/java-11-openjdk-arm64/lib/aarch64
sudo ln -s /usr/lib/jvm/java-11-openjdk-arm64/lib/server /usr/lib/jvm/java-11-openjdk-arm64/lib/aarch64/

Installing Omada Controller

Now, let’s get the Omada Controller on your Pi:

cd /home/pi
wget https://static.tp-link.com/upload/software/2023/202303/20230321/Omada_SDN_Controller_v5.9.31_Linux_x64.deb
sudo dpkg --ignore-depends=jsvc -i Omada_SDN_Controller_v5.9.31_Linux_x64.deb

Accessing the Controller Interface

You can now access the Omada Controller’s web interface through your browser using:

  • HTTP: http://192.168.0.4:8088
  • HTTPS: https://192.168.0.4:8043

Keeping Things Updated

Keep your system and MongoDB updated:

apt list --upgradable
sudo apt-mark hold mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-tools mongodb-org-mongos mongodb-org-database-tools-extra

Final Checks

Ensure everything is running smoothly:

sudo tpeap status
sudo tpeap start

If you need to stop the Omada Controller:

sudo tpeap stop

And always double-check MongoDB’s status:

service mongod status

With your very own Omada Controller up and running on your Raspberry Pi, you’re now equipped to effortlessly manage and optimize your TP-Link Omada access points. Enjoy the convenience of centralized control and efficient network management!