NB fo RPI Zero stick to Bookworm, Zero 2 can even use 64bit Trixie
See the above heading link to Tom's Hardware for Raspberry Pi Imager instructions and this video showing how to SSH from the PC to RPI terminal windows
After downloading rpi OS onto micro sd card, insert into rpi and boot up.
Allow a while to connected to the lan.
On a PC open the command prompt and ping the rpi hostname to confirm connected to lan.
Connect PC to terminal window to rpi terminal window.
Enter ssh pi@rpiCam and then enter password for pi device as requested.
As an alternative to using lan to SSH is to plug the rpi directly into a PC's USB via the rpi 's "data" (OTG) USB connector and connect to the USB Ethernet/RNDIS Gadget (may need to update PCs drivers). More information at https://notenoughtech.com/featured/raspberry-pi-zero-ssh-usb/ and at https://www.youtube.com/watch?v=XaTmG708Mss&t=6s
But before doing so need to reinsert SD card into SD card reader and alter files, possible to have more than one dtoverlay so just add to end of Config.txt file.
RasberryPi Software Code (Delete Quote Marks)
-------------------------------------------
Config.txt: "dtoverlay=dwc2"
Cmdline.txt: "modules-load=dwc2,g_ether" add inline immediately after rootwait
To connect via the USB Ethernet/RNDIS Gadget
Enter ssh pi@rpiCam.local and then enter password for pi device as requested.
This is a very common scenario, and simple to fix just enter the command e.g.
# ssh-keygen -R <host>
ssh-keygen -R 192.168.1.8
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null pi@<hostname_or_IP>
sudo systemctl restart vncserver-x11-serviced
From ssh command line access on PC
Enter the command sudo raspi-config.
Use the arrow keys to select Interfacing Options and press Enter.
Use the arrow keys to select VNC and press Enter.
You will be prompted to enable VNC Server. ...respond YES
...may take a while before informed connected, then respond OK
Set to 1024x768 or 1280 x 720 or 1280x1024 or 1600x1200
``
The Pi Zero 2W has 512M of memory and the default swap space to do a memory update may be insufficient.
From a Terminal window, enter the command swapon. The answer gives the file name, size, and usage of the swap file. The default swap file size is 100M and that probably is not sufficient with 512M memory.
Enter sudo nano /etc/dphys-swapfile and change CONF_SWAPSIZE=100 to 1024. Reboot and then before doing anything enter the command "swapon" in a terminal window to see the swap space usage.
Steps to Increase Zram Swap on Pi OS Trixie
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 416Mi 208Mi 119Mi 8.8Mi 149Mi 207Mi
Swap: 415Mi 104Mi 311Mi
So propose to increase swap to 2048Mi
Open the configuration file:
The modern Trixie OS uses /etc/rpi/swap.conf or configuration snippets in the /etc/rpi/swap.conf.d/ directory to control swap size. Open the primary configuration file with nano:
sudo nano /etc/rpi/swap.conf
Edit the configuration:
Inside the file, look for a line under the [File] section that might say FixedSizeMiB or MaxSizeMiB. The default MaxSizeMiB might already be 2048.To force the size to be exactly 2048MB, you can either edit the main file {remove '#' comment) or , even better, create a custom drop-in file as recommended for systemd configurations:
Exit nano if you opened the main file (Ctrl+X).
Recommended Method
Create the necessary configuration directory :
sudo mkdir -p /etc/rpi/swap.conf.d/
Now, create and open the custom configuration file:
sudo nano /etc/rpi/swap.conf.d/80-custom-size.conf
Add the configuration content:
Paste the following lines into the nano editor to set the swap size to 2048 MiB (2GB):
ini
[Main]
# Use zram mechanism
Mechanism=zram
[Zram]
# Set a fixed size of 2048 MiB (2GB) for the swap
FixedSizeMiB=2048
Save and exit nano (Press Ctrl+O, then Enter, then Ctrl+X).
Reboot the system:
The rpi-swap service reads this configuration file only during boot, so a reboot is required.
sudo reboot now
Verify the new swap size:
After the Pi reboots and you log back in then,
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 416Mi 262Mi 126Mi 10Mi 90Mi 153Mi
Swap: 2.0Gi 149Mi 1.9Gi
or run swapon to confirm the change:
swapon
# or use zramctl for more details
zramctl
The output should now show /dev/zram0 with a size of approximately 2048M (or 2G).
The Eclipse Paho MQTT Python library provides a client client class to enable applications to connect to the MQTT Eclipse Mosquitto broker to publish messages and to subscribe to topics and receive published messages.
Add/Remove search for mosquitto and install MQTT compatible message broker for Mosquitto. The client library will be added automatically.
Unless the configuration File is modified MQTT only runs on same computer as localhost.
Starting with the release of Mosquitto version 2.0.0, the default configuration will only bind to localhost. To enable remote access so that we can communicate with other IoT devices, we need to edit/create a configuration file.
1) Run the following command to open the mosquitto.conf file.
sudo nano /etc/mosquitto/mosquitto.conf
2) Move to the end of the file using the arrow keys and paste the following two lines:
listener 1883
allow_anonymous true
Mosquitto configuration file to allow remote connections and anonymous users
3) Then, press CTRL-X to exit and save the file. Press Y and Enter.
4) Restart Mosquitto for the changes to take effect.
sudo systemctl restart mosquitto
When configuring MQTT server in Node Red, in the MQTT broker node set the Protocol to MQTT V5.
(v3.x no longer supports Nodejs 12 )
then add --node18 to bash script
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node18
For a specific version of Node Red add for eg --nodered-version="3.0.1"
Assumes standard raspberry pi installation with headless setup.
Install Bluepy from https://github.com/IanHarvey/bluepy .
To install the current released version, on most Debian-based systems:
$ sudo pip3 install bluepy
$ sudo setcap cap_net_raw+e <PATH>/bluepy-helper
$ sudo setcap cap_net_admin+eip <PATH>/bluepy-helper
Where <PATH> is the place where bluepy-helper is installed; it's easiest to just search for this,
e.g.
$ find /usr/local/lib -name bluepy-helper
Raspian may already have WiringPi installed. Check by entering
gpio -v if bash: gpio: command not found then need to install WiringPi.
then install WiringPi. Unfortunately it has been deprecated and sudo apt-get install wiringpi no longer works. The GPIO Zero library is now the default installed on Debian!
Follow setup instructions in link below.
433Utils is made by GitHub user wolfeidau code allows reading and sending commands over 433MHz. The fork by jstevenperry works whereas the original didn’t!
The following instructions are based on Steven Perry’s Home Automation Series (video) (wordpress)
To install run following commands
$ mkdir HA
$ cd ~/HA
$ git clone --recursive https://github.com/jstevenperry/433Utils no longer available but could copy from PC backup seems to have a few differences from the original then follow instructions below
$ cd 433Utils/RPi_utils
$ make
**Moved 433Utils folder to HA folder (my folder for Home Automation projects)
**If recovering 433Utils in HA folder from a backup held on PC, need to
$ cd HA/433Utils/RPi_utils
$ make
Because Node-RED standard logs are kept in a volatile memory buffer (RAM) by default, running node-red-log will only show the logs since the most recent reboot and will not retain data from before the crash.
To find out exactly what happened immediately prior to the crash, you must look at the persistent Linux system logs via your Raspberry Pi's terminal.
You can tell the Pi to save its logs permanently to disk by creating a dedicated log folder. Run this command in your terminal:
bash
Use code with caution.
From this moment forward, the -b -1 command we tried earlier will actually work if the system reboots or crashes again.
1. View the Previous Node-RED Service Logs
Since Node-RED runs as a systemd service (nodered.service), the Linux system log manager (journalctl) saves previous boot logs to disk. Run this command to isolate the Node-RED logs from just before the last reboot:
bash
journalctl -u nodered.service -b -1 -e
Use code with caution.
-b -1: Targets the previous boot cycle (the one that crashed).
-e: Jumps straight to the end of that log so you can see the final lines written right before the system went down.
2. View the Entire System Failure Log
If Node-RED didn't cause the crash, but the Raspberry Pi itself froze or lost power, look for system-wide critical errors or kernel panics directly preceding the crash using:
bash
sudo journalctl -b -1 -p 3
Use code with caution.
-p 3: Filters the log to show only critical Errors and Critical/Alert states, filtering out normal background noise.
3. Check for Power Failures (Undervoltage)
If the logs abruptly cut off with zero error messages or a string of binary garbage characters (^@^@^@), it means the Pi instantly lost power or suffered a severe brownout. You can check if the system registered a low-voltage warning prior to shutting down by searching the kernel messages:
bash
sudo dmesg -T | grep -i voltage
sudo mkdir -p /var/log/journal enables Linux's official built-in logging system. You don't have to worry about this one filling up your card at all. Linux has a strict built-in safety cap that automatically limits system logs to a maximum of 10% of your disk space, and it automatically deletes the oldest logs to make room for new ones.
Ah, that explains it! You are running Raspberry Pi OS Trixie.
In the Trixie release, the Raspberry Pi engineers added a specific drop-in rule (/usr/lib/systemd/journald.conf.d/40-rpi-volatile-storage.conf) that forces the log storage to stay volatile, explicitly overriding whatever you change in the standard /etc/systemd/journald.conf file. They do this by default to save micro-SD card life on the Pi.
The cleanest and official way to bypass this restriction on Trixie is to use the built-in configuration utility:
The Fix for Trixie
Launch the configuration menu by running:
bash
sudo raspi-config
Navigate to: Advanced Options → Logging → Persistent.
Select Yes/Enable and finish out of the menu.
Finally, reboot the Pi to apply the system change:
bash
sudo reboot
Once your Pi boots back up from that restart, try checking the folder again:
bash
ls -l /var/log/journal
.
Let me know if the unique machine ID folder finally shows up after that reboot! Once it works, would you like to check how much free RAM you have left for your Matter nodes
Free Memory after reboot
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 415Mi 184Mi 196Mi 308Ki 88Mi 231Mi
Swap: 414Mi 116Mi 298Mi
pi@piZero2:~ $
Free Memory when Node Red Running
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 415Mi 354Mi 29Mi 1.4Mi 85Mi 60Mi
Swap: 414Mi 161Mi 253Mi
pi@piZero2:~ $
What this data tells us
Your system is currently on the edge of its performance limits. When a Raspberry Pi drops below 50–60Mi of available memory, it enters a high-pressure zone.
If you open your Node-RED editor, deploy a new flow, or if your Matter devices broadcast a heavy burst of status updates all at once, that remaining 60Mi cushion will instantly vanish. When that happens, the Linux kernel triggers the OOM (Out Of Memory) Killer, which immediately terminates the heaviest process—Node-RED—causing your entire smart home setup to instantly freeze or crash.
How to stabilize your Pi Zero 2 right now
You can easily protect your Pi from crashing by increasing your emergency Swap memory from 414Mi to 2048Mi (2GB). This gives your Pi a much larger safety buffer on your micro-SD card to soak up those sudden memory spikes.
How to Expand Swap on Trixie
The Correct Tailored Structure for /etc/rpi/swap.conf
Open the primary file:
bash
sudo nano /etc/rpi/swap.conf
Clear out the contents and ensure it looks exactly like this layout:
text
[Main]
Mechanism=zram
[Zram]
MaxSizeMiB=2048
RamMultiplier=4
Technical Breakdown:
[Main] and [Zram]: These block declarations are mandatory; without them, Trixie ignores the entries entirely.
Mechanism=zram: Instructs the system to rely exclusively on compressed volatile RAM modules and bypasses SD card file allocation.
RamMultiplier=4: : Trixie's default safeguards calculate swap based on your physical RAM size (512MB). Without forcing a multiplier of 4, the system will clamp your ZRAM at 512MB. This setting acts as the override mechanism to safely inflate the partition to your desired 2GB profile.
Save your modifications by pressing Ctrl + O, confirm with Enter, and exit using Ctrl + X.
Rebuild and Initialize
Because rpi-swap acts as an early-stage systemd device generator, the parameters require one clean system cycle to map.
bash
sudo reboot
Once the Pi Zero 2W comes back online, open a shell and run your validation:
bash
free -h
Free Memory before Node Red
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 415Mi 234Mi 117Mi 8.2Mi 123Mi 180Mi
Swap: 1.6Gi 75Mi 1.5Gi
pi@piZero2:
and after node-red-start
pi@piZero2:~ $ free -h
total used free shared buff/cache available
Mem: 415Mi 321Mi 94Mi 276Ki 48Mi 93Mi
Swap: 1.6Gi 209Mi 1.4Gi
pi@piZero2:~
The configuration worked beautifully! Your Swap total successfully jumped from its original 414Mi up to a massive 1.6Gi.
The reason it reads 1.6Gi instead of a flat 2.0Gi is simply because the rpi-swap generator calculates compressed boundaries using a safety percentage of your physical chip limits, but this gives you a huge safety cushion.
What the logs are telling us right now:
Before Starting Node-RED:
Your system was sitting comfortably with 180Mi available memory and was only using a tiny 75Mi of swap space for basic OS background functions.
After Starting Node-RED (The Workload Jump):
The moment Node-RED and your Matter smart home network initialized, your physical RAM filled up quickly, leaving 93Mi available.
The ZRAM Engine at Work: Look closely at the Swap row—your swap usage immediately jumped from 75Mi to 209Mi. Your Pi successfully intercepted that initial startup surge and seamlessly compressed 134Mi of background data into your new virtual RAM pool.
The Verdict on the ZRAM Experiment
Because your available memory is at 93Mi (safely above the critical 50Mi danger zone) and you have 1.4Gi of free swap space left to absorb any sudden automation spikes, your Pi Zero 2W is in a much more stable position than it was before we started.
Monitor your Node-RED flows over the next 24 to 48 hours. If the system remains stable, your ZRAM configuration is a complete success. If you see the system randomly freeze or drop offline again under heavy automation traffic, it means the Pi's tiny processor is getting overwhelmed trying to compress and decompress that data live, and we can switch to the hybrid disk-backed layout instead.
Keep your eye on things, and let me know:
Is your Node-RED editor dashboard responding quickly right now?
Are your Matter devices successfully responding to commands, or do they seem slightly delayed?
If your Pi ever locks up or reboots unexpectedly from this moment forward, simply log back into your terminal and run this exact command to see what happened right before the drop:
bash
journalctl -u nodered.service -b -1 -e
Things to watch out for in those logs:
Out of Memory (OOM) Triggers: If you see lines mentioning Out of memory: Killed process or oom-kill, it means even the 1.6Gi ZRAM wasn't enough, and we will need to pivot to the Hybrid layout to use the physical SD card space.
Undervoltage / Sudden Cut-offs: If the log abruptly stops mid-sentence with no error messages at all, it usually indicates a physical power drop or brownout on the Pi's micro-USB port.
For now, your smart home environment is in the best possible shape to run stably and protect its data.
Let's see how it behaves over the next few days. If you notice any unusual delays in your Alexa state updates or if you want to check your ZRAM performance after a few days of runtime, just let me know and we can run a quick check!
How ZRAM Works on Your Pi
Instead of writing temporary memory files to the physical SD card (which is slow and wears out the card), ZRAM takes a portion of your physical 512MB RAM chip and sets it aside as an internal, compressed drive.
When your Node-RED flows or Alexa integrations require extra memory, the operating system compresses that data on the fly (using the fast lz4 engine we verified) and squeezes it into this hidden RAM section.
Because it compresses data at a ratio of roughly 2:1 or 3:1, it allows your 415MB of usable physical RAM to behave like a much larger 1.6Gi pool without ever touching a single byte of your micro-SD card storage space.
The Clear Advantage
Zero SD Card Wear: Your micro-SD card is completely safe from the constant read/write cycles that traditional swap memory causes.
Maximum Speed: Because everything stays on the RAM chip, it is significantly faster than using a physical swap file on a card.
Your micro-SD card is only being used to store the lightweight text logs inside /var/log/journal that we configured earlier [|]. Everything else is handling itself safely in memory!
# This file is part of rpi-swap.
#
# Defaults are provided as commented-out options. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the swap.conf.d/ subdirectory. The latter is generally recommended.
#
# See swap.conf(5) for details.
[Main]
Mechanism=zram
[File]
#Path=/var/swap
RamMultiplier=4
MaxSizeMiB=2048
#MaxDiskPercent=50
#FixedSizeMiB=
[Zram]
#RamMultiplier=1
#MaxSizeMiB=2048
#FixedSizeMiB=
# Writeback settings (for zram+file mechanism):
#WritebackTrigger=auto
#WritebackInitialDelay=180min
#WritebackPeriodicInterval=24h
# This file is part of rpi-swap.
#
# Defaults are provided as commented-out options. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the swap.conf.d/ subdirectory. The latter is generally recommended.
#
# See swap.conf(5) for details.
[Main]
#Mechanism=auto
[File]
#Path=/var/swap
#RamMultiplier=1
#MaxSizeMiB=2048
#MaxDiskPercent=50
#FixedSizeMiB=
[Zram]
#RamMultiplier=1
#MaxSizeMiB=2048
#FixedSizeMiB=
# Writeback settings (for zram+file mechanism):
#WritebackTrigger=auto
#WritebackInitialDelay=180min
#WritebackPeriodicInterval=24h