This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Waveshare

Waveshare makes many SBC accessories

1 - CM4 NAS

This is perhaps the most portable NAS you can put together. Paired with 5V/3A DC power supply like the ones [geekworm] makes (that don’t reset when input power is applied) it travels in the car well.

Configure as a Basic Server

One great use is to add some media, enable it as a HotSpot and share things up with plain-old SMB. Most tablets will easily connect and play with VLC.

  • Install RaspberryPI OS
  • Install Hardware Tools
  • Configure SMB
  • Add a HotSpot

Install RaspberryPI OS

If you have an EMMC based CM4, flip the switch on the back to put it in target mode and power it on while plugged into your PC. You’ll see it appear as a block device and you can image it.

After installation, run these commands on it to set it to US locale and settings.

sudo raspi-config nonint do_change_locale en_US-UTF-8
sudo raspi-config nonint do_configure_keyboard us
sudo raspi-config nonint do_wifi_country US
sudo timedatectl set-timezone America/New_York

Install Hardware Tools

These make the buttons and LCD work as intended. Refer to their wiki for installation - though this may be out of date and require some work as Raspberry Pi updates their OS.

Configure SMB

After you’ve configured the storage, with mdadm, btrfs or mergerfs, you’ll want to share it up simply.

Setup SMB

Add a HotSpot

The easiest way to create a hotspot is with nmcli. It’s already installed and will do the configuration for you. Here’s the command to add a 5GHz connection on channel 161.

sudo nmcli device wifi hotspot ssid SOMENAME band a channel 161 password SOMEPASSWORD ifname wlan0 
sudo nmcli connection modify Hotspot connection.autoconnect yes

This will give you about 72MBits of bandwidth. If you’re getting less, look to see if anything else is using 161 and change as needed.

# What channels can I use?
iw phy phy0 info | grep "MHz \[" | grep -v "no IR" | grep -v "disabled"

# What other things are around me?
sudo nmcli device wifi

# Try on of the ones that might be free
sudo nmcli connection modify Hotspot wifi.channel 149

Not every channel is available in every country. In fact, if you tried to use the default when creating the AP you’d get these errors1.

Error: Connection activation failed: 802.1X supplicant took too long to authenticate brcmfmac: brcmf_set_channel: set chanspec 0xd022 fail, reason -52

If you want to use it as a router as well, say because you’ve plugged it into a LAN cable, you can enable masquerade.

Configure LibreELEC

You can double-down and use this as a media player, in addition to serving up content over the network. A great way to do this is with LibreELEC

Though as Jeff Geerling found you may be doing something dangerous or harmful, so be careful!

Installation

Flashing the OS

This requires either flashing the SD card, or putting the CM4 into USB target mode and using rpiboot to mount the eMMC as a drive so you can use the Raspberry Pi Imager to flash the LibreELEC image.

The LibreELEC folks recently added AHCI support to their CM4 image so you don’t have to re-spin things.

Installing Hostapd

You may want to increase the WiFi performance by installing hostapd, but some assembly is required.

Configuration

You can also install services like Jellyfin. For large libraries, you may want to switch it’s metadata directory by editing:

/storage/.kodi/userdata/addon_data/service.jellyfin

Speeding up Rsync

For smaller CPUs, it can help to use the rsync daemon on-demand to remove the overhead of SSH. Establish SSH keys and write a simple script like below.

Setup Rsync Daemon

Troubleshooting

The USB port isn’t working

Check that the config.txt file contains

dtoverlay=dwc2,dr_mode=host

Jellyfin transcoding is slow

Yes, this is just a Pi4. But you can find versions of ffmpeg optimized for the pi4 hardware and rest replacing the shipped version. Though you’d think that one was already optimized.

2 - UPS

Notes

https://www.waveshare.com/ups-hat-e.htm

The pogo pins didn’t supply voltage until I used a pencil eraser to clean the bottom of the Pi’s contacts, and them too for good measure.

Once working, I downloaded the python same as described in

https://www.waveshare.com/wiki/UPS_HAT_(E)

You must sudo the first example, but the second injects into the GUI seemingly OK (though I didn’t test to see if it was accurate).

Then I used ChatGPT to make a UPS monitoring script. It did a really good job. I’d have hacked something up in bash, but python is better for reading registers (probably)

I had the gui version of RaspOS installed so there might have been other libraries than described in the wiki that were used without being explicitly called out.

sudo vi /usr/local/bin/ups-monitor.py
sudo chmod +x /usr/local/bin/ups-monitor.py
#!/usr/bin/env python3
import time
import subprocess
from smbus2 import SMBus

I2C_ADDR = 0x2D            # UPS HAT (E) I2C address
RUNTIME_LOW  = 0x28        # low 8-bit of remaining time (minutes)
RUNTIME_HIGH = 0x29        # high 8-bit

SHUTDOWN_LIMIT = 20        # minutes

def get_remaining_minutes():
    try:
        with SMBus(1) as bus:
            lo = bus.read_byte_data(I2C_ADDR, RUNTIME_LOW)
            hi = bus.read_byte_data(I2C_ADDR, RUNTIME_HIGH)
            remaining = (hi << 8) | lo
            return remaining
    except Exception as e:
        print(f"UPS read error: {e}")
        return None

def shutdown():
    print("Remaining runtime below threshold — initiating shutdown …")
    subprocess.run(["sudo", "shutdown", "-h", "now"])

def main():
    while True:
        remaining = get_remaining_minutes()
        if remaining is not None:
            print(f"[UPS HAT E] Remaining runtime: {remaining} minutes")
            if remaining < SHUTDOWN_LIMIT:
                shutdown()
                break
        else:
            print("Could not read remaining runtime from UPS — retrying")

        time.sleep(30)  # check every 30 seconds

if __name__ == "__main__":
    main()
sudo nano /etc/systemd/system/ups-monitor.service
[Unit]
Description=Waveshare UPS Runtime Monitor
After=multi-user.target
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=/usr/local/bin/ups-monitor.py
Restart=always
RestartSec=5
User=root

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable ups-monitor.service
sudo systemctl start ups-monitor.service