Some Bits: Nelson's log

10 posts about raspberry-pi

PiKVM for a remote console

Following up on my efforts for a remote PC console, I gave PiKVM a try. Very impressive! A great first experience: once you find your way to the right docs it is great. This remote console option is a winner and I’m going to stick with it.

Skip down to the section about software if you’re curious what it’s like to use the thing. I spent a lot of time hacking up some hardware to run it so first notes on that.

Hardware

PiKVM runs an Raspberry Pis. The simple thing is to buy an assembled device from them. You get a CM4, video capture device, an ATX power controller, a power supply, and other stuff all in a nice case. I think the V4 Mini at about $300 is what I’d need. It’s not a bad price for the convenience. OTOH at that price you have a choice of other IP KVMs. I’m not sure if PiKVM is the best choice.

Update: I bought the PiKVM Mini v4. It’s a very nicely prepared product, well built and nicely packaged with plenty of cables. The Mini isn’t just cheaper than the Plus, it’s smaller too. Not a huge thing but I appreciated it. I should have just bought this to start, could have saved myself a fair amount of time.

I’m stubborn and wanted to build my own. They have a very nice guide on doing that, including what hardware to buy. I took their recommendations. $50-$100 depending on what parts you may have lying around already.

  • Raspberry Pi Zero 2 W. A tiny $15 computer, these things are very versatile. I had one lying around.
  • A HDMI-CSI bridge. A $30 HDMI capture device. It takes HDMI as the input. The output is an RPi Camera device (Camera Serial Interface).
  • A CSI ribbon cable. $9 for a set of cables, you only need one. This adapts the wider CSI output to a narrower CSI input on the RPi Zero.
  • A quality USB power supply for the RPi.
  • An ordinary Micro USB to USB A cable (maybe with some tape, see below)
  • Optional: an ATX power interface. This seemed complicated to build, I haven’t looked at it.

The drawback with the RPi Zero is both USB ports are busy doing things and it’s not really practical to have an ethernet adapter. I’m OK just using on-board WiFi but obviously that’s not ideal.

Also this camera interface is pretty hacky. They say it’s capable of 1080p@50 maximum, the product page says 1080p@30. Either way it can’t do the bog-standard 1080p@60 that everything expects these days and that could cause a problem. My Linux PC is happily putting out 720p for it and that works fine.

Physical challenges

The ribbon cable is very fiddly to install. this is not a normal consumer connector. I found this video helpful. Basically you have to unsnap something in the connector, stick in the cable, then snap it in again.

It’d be nice to have a case. The parts are all exposed circuit boards and a delicate ribbon cable. And the HDMI and USB cables are heavier than the computer, which ends up putting a lot of strain on that delicate ribbon cable connector.

No one seems to have a case that fits both boards at once but this 3d printed kludge looks plausible. There’s lots of pre-fab cases for the RPi Zero by itself, that might help.

A note on power

The RPI Zero 2 W has pretty squirrely power. The board has one USB 2.0 port just for power and one just for data. But the power lines of both USB ports are hardwired together. This means if you provide power to the power port you may be dumping that power down the data port into the PC you’re plugged in to. Not good! Alternately, if you only plug the data port into the PC then the RPi will more or less manage to power itself off the data port, which isn’t reliable.

For the problem of backfeeding power to the PC, the PiKVM docs suggest taping off the power leads on your USB cable plugged in to your PC. That’s probably a good idea but I haven’t bothered and so far haven’t fried anything. Here’s hoping my PC’s motherboard is robust. OTOH I ordered this USB power blocker: $6.50 for peace of mind.

What about powering the PiKVM just off the data port connected to the PC? It sorta works! In a previous experiment I measured the RPi Zero 2 W using 165 mA when idle at 570 mA at max load. The USB spec promises 500 mA of power from the USB port so it’s almost enough, and in practice probably is enough if you’re not at max load. PiKVM does work and is usable with just data port power. But then it failed on me once and I have no idea why, was it a brownout? Also it makes the PiKVM dependent on the PC’s power and USB ports which is probably not a great thing in a debugging tool. Independent power seems like a good idea.

One last power note: RPis have a WiFi power saving mode that can cause problems for long-running servers like PiKVM. It’s easy to turn off. PiKVM doesn’t by default. (They wisely don’t recommend using WiFi at all.)

Software: Installation and use

The docs are pretty great and easy to follow. Basically you flash an SD card with their OS. Then edit a text file in a FAT32 partition for initial setup options (like wifi password). Then boot and it’s all pretty automatic. From there it’s all a pretty standard Linux experience. Arch, btw.

But I’ll say this, the PiKVM web interface is great. It was very easy to get it up and going and see my PC’s screen and type at the PC. Super easy to do the basic thing. And the screen sharing UI has nice options like shortcuts for sending weird keystrokes (Ctrl-Alt-Del or Alt-PrScr-T).

One weird thing: the PiKVM filesystem is mounted readonly by default. You have to explicitly issue an rw command to switch to read-write, then ro to go back. In practice you almost never need to do this manually, maybe when you’re changing the root password or something.

I’ve noticed the video feed flakes out when the PiKVM system is busy installing upgrades or fetching system logs. (Even when it has a separate power supply). It may be the RPi Zero CPU is just not powerful enough to keep up. Shouldn’t matter in normal use.

Advanced capabilities

There’s lots of cool hacker extras beyond the basic IP KVM. Some things it can do:

  • Tailscale
  • Cellular backup network connection
  • Fancy HDMI and video options. They seem to care about providing a good video feed, not just an adequate one.
  • OCR for the video feed so you can get text of what’s on the screen.
  • Audio and microphone
  • ATX power control so you can reset or power off/on your PC
  • Serial and Ethernet over the USB link to the PC
  • GPIO access on the RPi for special-purpose hacking
  • VNC server
  • An HTTP API
  • Extra hardware for a KVM switch for four devices

It’s a remarkably impressive product.

I noticed my Linux box sees a bunch of USB devices when I plug in the PiKVM: keyboard, mouse, CDROM. And I guess ethernet and serial are also possible if I enabled them.

Linux serial console in 2025

I wanted remote access to my Linux PC and decided to try a very old fashioned idea, a serial console. Normally a Linux PC’s console is a keyboard and video device. But it can also just be a serial device. Either an old school DB9 connector on an ancient PC or some modern thing plugged in with a serial connection. Then you need a second device to act as a serial terminal.

In theory the serial device is simpler and is more likely to work even if the network isn’t working. In particular the Linux PC’s kernel is managing the serial console and so as long as Linux is operating, there’s a good chance that serial connection will be.

I tried using a Raspberry Pi Zero 2 W for the terminal, plugged in to my Linux PC via a USB cable.

I got this sort of working and then quit. I realized there’s few cases where a serial connection will really help. Ie: the Linux machine is up but its networking is down, however the whole LAN is still up. It happened to me this week! But I’m going to look for a full IP KVM solution so I can do things even if Linux is busted.

Update: this set of docs may be useful.

Serial connection: USB Gadget / On-the-Go

The first complication: who has a real serial port anymore? I haven’t seen a DB9 in years. It’s all USB ports. And you can’t just plug a USB cable in between two computers because they are both in host mode, not device mode.

There’s hardware hacks for true serial. Plenty of USB-to-Serial adapters out there that give you a DB9 (or an RJ45 with serial). Also RPi hardware has UARTs that you can use with the GPIO pins, hack up your own serial port. All that conversion seemed du mb to me, particularly since I’d need two adapters on either end.

The hack I’m using is OTG / Gadget mode on my RPi Zero 2 W. The micro USB port is an OTG port, you can plug that in directly with a cable to a PC’s USB A socket. The PC is a USB host, the OTG port is a USB device. This actually works! No special cable or adapter needed, just an ordinary USB cable between the two computers. (Mine was male Micro-B to male A.) However, it still takes a lot of doing to get it going.

Getting serial working manually

Here’s how I got a serial connection working manually in Linux.

On the RPi Zero 2 W: steps to enable OTG mode and use the USB as a serial port

  • enable dtoverlay=dwc2 in /boot/firmware/config.txt and reboot
  • modprobe dwc2
  • modprobe g_serial
  • verify there’s a new /dev/ttyGS0 on the RPi

On the Linux server (after the modprobe on the RPi)

  • lsusb and verify there’s something named “Linux-USB Serial Gadget”
  • Verify there’s a new /dev/ttyACM0
  • Run getty -L 9600 ttyACM0 vt100 to create a login prompt on the serial port

Back on the RPi, connect to the Linux server.

This all works! I can now connect from one machine to another via a serial interface.

Proper server setup

The next big step is getting the server to run that console all the time. The simple way is to add ttyACM0 to the list of things that systemd should run a getty on. But that doesn’t catch the kernel. What you really want is to modify the Linux kernel command line to treat this serial port as a second terminal, not just for getty but also for kernel errors, etc. I didn’t do this step.

Proper terminal setup: ConsolePi

Any old serial terminal would work and that screen hack I tried is actually not bad if you only have a single server to connect to. But there’s a fancy OS purpose-built for being a serial terminal with a lot of nice extra features: ConsolePi. The key component is ser2net, that’s a Linux service that proxies all serial ports to TCP network ports. Then ConsolePi wraps that up in a nice UI.

I tinkered with it a bit but didn’t get it working. Honestly I found the docs confusing and was running out of patience. The main snag I ran into is ser2net doesn’t seem to find devices named ttyGS* by default, or at least I couldn’t figure it out. I’m sure that’s hackable.

Update: Conserver may be worth a look as a different app for monitoring serial ports.

Electron bloat vs RPi 4

Running a Linux desktop on a slowish RPi 4 with 4GB of RAM sure makes you appreciate just how bloated and slow Electron apps are. Should it really take 300MB to run a fancy IRC client or 150MB to grep a password file? Some example memory sizes, as reported by conky’s summary of free system memory and then ps_mem. Bolded numbers are what I think is the fairest measurement.

  • 1password: 181MB, 152MB, 196+124=320MB
  • webcord: 355MB, 308MB, 277+115=391MB
  • chromium (1 blank tab): 265MB, 250MB, 196+136=332MB
  • VS.Code (1 .py file): ?, 550MB, 439+122=561

(For each process I first tested what corky said was memory in use when I ran just that app and no other Chrome stuff. Then launching it with other Chrome stuff in memory. The third set of numbers is what ps_mem.py reports. These measurements are complicated by how you account for sharable memory and the details of that are inscrutable).

Memory aside these things also take enormous amounts of CPU. And are very slow, latency when typing in them is quite apparent in some part of every app. I’ve known Electron was bloated but stopped noticing on high powered desktops. We lose a lot when we give up on optimized native apps.

Raspberry Pi 4 as a Ubuntu desktop

Update this whole post was written using Ubuntu 64 bit with Gnome on an RPi 4. I’m trying a second time now with Raspberry Pi OS (LXDE) and it’s going much better, new post coming.

I decided to give a Raspberry Pi 4 a go as a Ubuntu desktop. It did not go very well. I think the hardware is just too underpowered. Which is a little ridiculous given how much more capable this hardware is than the systems of 10 years ago. I’m using this on a stock RPi4 with 4GB of RAM and the basic boost overclocking enabled. The system is installed to a SSD connected with USB3 that gets 250MB/s in benchmarks. (Which itself is odd; it should be 500MB/s. RPi4 I/O is limited I guess). My screen is 3440x1440.

Installation is remarkably easy and clean. The Raspberry Pi people have a GUI app that installs bootable operating system images. Basically plug and play. Newer RPi4 can boot directly off USB, no need for an SD card at all. Which is good; SD card I/O is slow. Graphics and sound basically worked out of the box. Even Bluetooth audio.

Performance is very rough though. There’s regularly 5 second delays between typing something and it showing up on my screen; here in the Wordpress editor, in the URL bar of a browser, pretty much in any GUI. Sometims keystrokes get lost. It’s much better in a Gnome terminal but even then there’s sometimes a perceptible subsecond delay. I really don’t understand the terrible latency on user inputs, even when several CPUs are idle and I have 1.0GB RAM available (currently allocated to buffers and cache). I wonder if something more serious is wrong?

I’m using the default Ubuntu 22.04 Gnome desktop. I might have luck with lighter GUIs - Lubuntu and Xfce are both recommended. I briefly tried them and they did seem faster but they were also uglier.

Update: I tried LXDE on Ubuntu, the desktop environment Raspberry PI Desktop uses, and it’s much better. The ubuntu install I did is pretty janky but that’s probably my fault, I bet the integrated Raspberry Pi Desktop experience is nicer. Responsiveness is much better and memory usage is much lower although this Wordpress editor still drags. LightDM is a big improvement too; the Gnome Display Manager is a huge hog for something that’s just a freakin’ login box.

Update 2: Raspberry Pi Desktop is indeed better. It’s much lighter weight than Ubuntu Gnome and it’s coherent in the RPi build, much better than my janky LXDE. Bluetooth config works! Youtube audio playback is mostly fine but pauses every once in awhile when something else is happening. The wordpress editor is worse than ever though. Beginning to suspect a bug in their Javascript code exacerbated by the relatively low system.

I started with Firefox which was a mistake; the aarch64 build of that is really slow and memory hungry. Chromium is a little better, apparently someone put some real effort into optimizing it for the RPi. It’s still not good though. Super sluggish, regularly pins all 4 CPUs at 100%, and uses a lot of memory per tab. I can’t watch a single Youtube video at 240p even with nothing else going on and the window minimized (sound, no picture). CPUs aren’t overtaxed but the sound playback is choppy and awful. Again, maybe a symptom of something more serious being wrong than just system load.

Update: the fix for Youtube is apparently the h264ify Chrome extension, which forces Youtube videos to H.264 instead of VP9. Which allows for hardware decoding. Shame YouTube isn’t smart enough to do that for you.

Gnome on Ubuntu 22.04 looks fairly good. But the moment you start pushing on stuff it breaks down. There’s two separate programs called “Software Updater” but what you really want is a third program “Ubuntu Software” which installs Snap apps. 1Password requires a manual install; they haven’t built aarch64 packages (But do have a tarball). Lots of weird off-brand Linux choices for ordinary user apps. I never could get the Gnome system monitor to show up in my task bar.

I had a much better experience using this environment on my fast desktop PC. Ubuntu Gnome does at least work on RPi 4 but it’s so slow that it is a miserable experience. Maybe next time I try this I’ll use the Raspberry Pi OS build instead.

OpenWRT on Raspberry Pi 4

I’m fed up with my Ubiquiti routers. UnifiOS has a bunch of bugs related to WAN failover that have been there for a year+. Also a lot of mysterious behavior and some odd engineering problems. And still no official solution for Wireguard last I looked. So I want to switch (back) to OpenWRT for routing. I want three ethernet ports in the end; LAN, WAN, and backup WAN. I’m not using the WiFi on the RPi4 at all. I could, but I have hardware with better antennas.

These notes are a work in progress and are not a fully followable cookbook. It took me like 5 hours of tinkering in different orders to get this going. Don’t worry, it’s not normally that hard. Here are some other sources I found helpful for doing this: one, two, three.

Step 1: Hardware and device drivers

OpenWRT runs on all sorts of hardware but I’m going to do this with a Raspberry Pi 4. It’s way more powerful CPUs and RAM than a typical router. The networking is a bit weaker though. The RPi4 gives you one ethernet port on the PCIe bus and the rest have to be USB ports. The TP-Link UE300 is a commonly recommended USB adapter, it has an RTL-8053 which is well supported. My LAN will be on the on-board ethernet, the WAN links on USB. I think this setup is good enough to support gigabit throughput and is certainly good enough for Starlink’s max 200 Mbps. I’m told you can do traffic shaping and VPN stuff with very good speeds using the RPI4 CPU, but I haven’t tested it. (Few consumer routers can do gigabit Internet with these fancies.)

Another interesting hardware option is an RPi CM4 with a router board. That gives you two full Gigabit ethernet ports connected to the PCIe bus. A third option is to only have a single ethernet port and use VLAN tagging so the router can work in a “router on a stick” mode.

Step 2: Basic install

OpenWRT has pretty good docs for running on an RPi 4, I just followed them to get a basic system going. Note that the RPi 4 is way more powerful hardware than OpenWRT is normally aimed at, so some of the extreme things that OpenWRT does to save resources may not be necessary. Some folks recommend using ext4 as the filesystem instead of the compressed SquashFS. There’s also something about resizing the partition to use all the SD card storage. I didn’t bother.

Flash your SD card, then boot the router without the USB ethernet devices plugged in. (Or with, it doesn’t matter, but don’t plug in any WAN cables yet.) Plug a laptop ethernet into the on-board ethernet port. OpenWRT should come up and be serving DHCP on the ethernet. Point your laptop to http://192.168.1.1/ and you’re logged in to LuCI, the OpenWRT web interface. Note that OpenWRT will call this ethernet port eth0 and it will be bridged into br-lan.

Update May 2023: this HOWTO is more up to date than my notes. It uses OpenWRT’s firmware selector to prepare a download with the ethernet drivers you need in step 3.

Step 3: enabling your USB ethernet device

There’s one hard thing setting this up; OpenWRT doesn’t have the kernel drivers for USB ethernet installed by default. You need the kmod-mii, kmod-usb-net, and kmod-usb-net-rtl8152 opkg packages (IPK files) installed. No configuration needed, but you do have to install the packages. The problem is you’re not connected to the Internet to just install them.

You have several options for getting them installed. My choice was to manually download the needed packages from the OpenWRT repository to my laptop, then upload them via LuCI to the router. (You have to install them one at a time and click “Dismiss” manually on the install popup). It’s also possible to plug a WAN cable into the one working ethernet and get access to the router somehow (keyboard and screen? routing tricks?) to install them. I like the “2nd way” in the linked Reddit post; you make a custom OpenWRT image that included the necessary drivers.

Step 4: configuring the WAN

Now that there’s an ethernet device for the WAN you have to configure it. Do this in LuCI; go to Network / Interfaces and add an interface for eth1. Call it WAN and then go to firewall settings and put it in the WAN zone. This is a little mysterious but I think that’s all you have to do. I rebooted somewhere in here just to be sure that it was all working right.

Step 5: Improve OpenWRT

The blessing (and curse) of OpenWRT is it’s a very flexible Linux system and you can do a lot with it. A search for packages matching “luci-app-*” is a good way to see what’s available. Here’s some of what I’ve done.

Update the software lists and manually update each package one at a time. The updates aren’t exactly recommended but before I did that some new LuCI stuff I installed broke the old LuCI install until I updated it.

Install some quality of life packages: less, bash, curl, nano, mg (for me).

Install luci-app-statistics. You also have to enable this by going to Statistics / Setup and saving the config.

TODO / options

Some things I have not yet done but may get around to (and update this blog post if so)

Install mwan3 for failover. Done, see this post for my notes.

Install wireguard for a VPN. Done, see this post for my notes.

See if I can export monitoring stats somehow to my InfluxDB instance for plotting in Grafana.

Install luci-app-sqm for traffic shaping

My own notes

Some notes of interest to me only.

The network interfaces are:
LAN eth0/br-lan E4:5F:01:5F:AB:D8
WAN1 eth1 5C:A6:E6:AA:BC:9A
Wireless not enabled

System / logging / external system log server to my Linux server on the LAN

DHCP range: 192.168.3.2 - 192.168.3.199

Override DNS servers and use 8.8.8.8 and 8.8.4.4

Set a static route for Starlink for 192.168.100.1 / 255.255.255.255 on eth1.

Some static leases (all have a lease time of 86400)
gvl 94:c6:91:1e:c8:38: .75
printer 84:25:19:0e:7b:0b: .67
pvspi0 e4:5f:01:78:d7:f9: .140

Debugging a WiFi problem

Still tinkering with Raspberry Pis and my Sunpower PVS6 solar controller. I had it all set up with a new RPi Zero 2 W when I had a new problem; the WiFi was flaky. It kinda sorta mostly worked well enough, I could get the HTTP requests through to it usually. But ping was showing 40% or more packet loss with a latency of 200+ms. I have a very clean WiFi environment, that should be 0% loss and 2ms latency.

A whole lot of testing later and I established that the problem is some sort of interference on 2.4GHz Channel 1, but only in my garage near the Sunpower box. That corner also has all my other ethernet equipment, is where the generator and solar feeds come in, and where the utility power and electrical panel are. So a lot of wires. None of that stuff should interfere with 2401-2423Mhz and there are a lot of mysteries still.

Switching my access point to channel 3 (2411-2433Mhz) seems to solve the problem. Part of the root cause of my troubles is I’d pinned the WiFi channel in the garage to 1 a year or more ago, I forget why. I’ve now set it to auto. I’ve had experiences where it seemed to be working for a few hours at a time before, so I don’t fully trust it yet. Edit: after rebooting the AP went back from channel 3 to 1. So I’ve configured it to hardcode channel 3 instead of “auto”. Whatever the interference is, the Ubiquiti hardware isn’t detecting it.

The most useful thing I did in the end was get 2 access points and 3 clients and try moving them around every few hours to see what triggered the problem. I used telegraf to ping them once a minute or so (but see below) for long term monitoring, and then occasional command line pings once a second for short term testing. Over two days I was able to narrow the problem down to the one channel in the one location, but it’s not related specifically to any particular hardware.

Some things I learned:

  • wavemon is a helpful tool on Linux for showing WiFi status. so is /proc/net/status and learning all the arcane options to the iw command.
  • The UniFi dashboard has some decent stats of its own hidden away under “Air Stats” for each individual access point device.
  • WiFi has its own link layer retransmit; lots of those might account for higher latency. But I don’t know what timescale it is on: 1 ms? 500ms? You can see WiFi retransmits in wavemon as “failed” and in Air Stats as “retry”.
  • Despite all these diagnostics none of them really showed me evidence the link was bad. All the basic link quality reports were 90% or better. No ridiculous number of retries (although it is 16% at the access point.)
  • Linux machines, including RPis, need to be configured for the country for wifi to work at its best. Particularly important for 5GHz.
  • Even with a perfectly good 5GHz channel available an RPi4 might still choose 2.4GHz. I could not find a way to reliably coerce it to use 5GHz.
  • Raspberry Pis have a variety of low power optimizations that mean they may not respond well to a ping every minute when otherwise idle. My RPi4 regularly takes 100ms to answer the first ping, then is a solid 2ms after. My original RPi Rev B just misses pings entirely if nothing else is happening on it. The RPi Zero 2 W seems pretty solid but then I’ve got it doing other real computation. Anyway my once-a-minute ping was showing phantom errors where there were none. A once-a-second ping test worked better.
  • There’s a power saving mode in the RPi radio hardware itself you can turn off with iw.
  • Raspberry Pis may in general just not be very good at wifi.
  • Don’t use mDNS names for ping testing. The mDNS query itself may get lost to a flaky / low power Pi and you never find the host.
  • TCP retransmits hide a lot of sins. But it only works right until it doesn’t. When my WiFi link was bad about 5% of my requests wouldn’t get through at all.

WiFi on Linux: country registration (Raspberry Pi)

My Raspberry Pi 4 would not talk via 5GHz to my Ubiquiti Access Point. Turns out the problem is the AP was running on channel 157 (5785MHz, 80MHz wide) which is not a globally allowed WiFi channel. It is allowed in the United States. Ubuntu on RPi4 has no country configuration for the WiFi unless you set it explicitly. Setting it for US jurisdiction should fix it.

On Ubuntu the config file /etc/default/crda is where to set it. Note you have to set it to “US”; “us” does not work. On Raspberry PI OS it’s in raspi-config under Localisation options. It’s also configurable in the wpa_supplicant.conf file you create when setting up a headless RPi.

Once the system is running you can inspect the state of your current wifi config with the commands iw reg get and iw phy phy0 channels, see output below. There’s documentation on how this works here, here. The apt packages crda and wireless-regdb are also of interest, as is /lib/crda.

$ iw reg get
global
country 00: DFS-UNSET
        (2402 - 2472 @ 40), (N/A, 20), (N/A)
        (2457 - 2482 @ 20), (N/A, 20), (N/A), AUTO-BW, PASSIVE-SCAN
        (2474 - 2494 @ 20), (N/A, 20), (N/A), NO-OFDM, PASSIVE-SCAN
        (5170 - 5250 @ 80), (N/A, 20), (N/A), AUTO-BW, PASSIVE-SCAN
        (5250 - 5330 @ 80), (N/A, 20), (0 ms), DFS, AUTO-BW, PASSIVE-SCAN
        (5490 - 5730 @ 160), (N/A, 20), (0 ms), DFS, PASSIVE-SCAN
        (5735 - 5835 @ 80), (N/A, 20), (N/A), PASSIVE-SCAN
        (57240 - 63720 @ 2160), (N/A, 0), (N/A)

phy#0
country 99: DFS-UNSET
        (2402 - 2482 @ 40), (6, 20), (N/A)
        (2474 - 2494 @ 20), (6, 20), (N/A)
        (5140 - 5360 @ 160), (6, 20), (N/A)
        (5460 - 5860 @ 160), (6, 20), (N/A)

$ iw phy phy0 channels
Band 1:
        * 2412 MHz [1]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 2417 MHz [2]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 2422 MHz [3]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 2427 MHz [4]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 2432 MHz [5]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40- HT40+
        * 2437 MHz [6]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40- HT40+
        * 2442 MHz [7]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40- HT40+
        * 2447 MHz [8]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40- HT40+
        * 2452 MHz [9]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40- HT40+
        * 2457 MHz [10]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 2462 MHz [11]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 2467 MHz [12]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 2472 MHz [13]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 2484 MHz [14] (disabled)
Band 2:
        * 5170 MHz [34] (disabled)
        * 5180 MHz [36]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 5190 MHz [38] (disabled)
        * 5200 MHz [40]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 5210 MHz [42] (disabled)
        * 5220 MHz [44]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40+
        * 5230 MHz [46] (disabled)
        * 5240 MHz [48]
          Maximum TX power: 20.0 dBm
          Channel widths: 20MHz HT40-
        * 5260 MHz [52]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5280 MHz [56]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5300 MHz [60]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5320 MHz [64]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5500 MHz [100]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5520 MHz [104]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5540 MHz [108]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5560 MHz [112]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5580 MHz [116]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5600 MHz [120]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5620 MHz [124]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5640 MHz [128]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5660 MHz [132]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40+
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5680 MHz [136]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz HT40-
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5700 MHz [140]
          Maximum TX power: 20.0 dBm
          No IR
          Radar detection
          Channel widths: 20MHz
          DFS state: usable (for 726 sec)
          DFS CAC time: 0 ms
        * 5720 MHz [144] (disabled)
        * 5745 MHz [149] (disabled)
        * 5765 MHz [153] (disabled)
        * 5785 MHz [157] (disabled)
        * 5805 MHz [161] (disabled)
        * 5825 MHz [165] (disabled)

Customizing a Raspberry PI Zero 2 W for PVS6

Awhile back I set up a Raspberry Pi to be a gateway to get access to my SunPower PVS6 monitoring system. That’s going great; the extra status info is really helpful and interesting. (Bonus screenshot below). I just bought a Raspberry Pi Zero 2 W to be the new computer for this. It’s so tiny it’ll fit entirely in the PVS6 box, powered by the USB that’s in there.

It works! The wifi is pretty flaky, despite me getting an amazing -30dB signal. It seems to be a problem with one specific access point, need to tinker some more. (Update: it may be wifi power saving.) The cable mess is pretty janky but it’s going to be shut inside a box, not sure I care. A smaller ethernet adapter would sure be nice.

Here’s my detailed software notes on setting this up.

  1. Mostly I’m just following this guide
  2. Use the RPi image installer to burn RPi OS Lite to a new SD card. Note this is a 32 bit OS.
  3. Create and configure a wpa_supplicant.conf file on the DOS partition of the SD card
  4. Create an empty ssh file on the DOS partition
  5. Boot the RPi, find its IP address via my DHCP server. (The name raspberrypi.local might also work.)
  6. Log in with ssh as pi/raspberry. Ignore locale complaints.
  7. Change the password for pi
  8. Become root
  9. apt update; apt upgrade. (This takes awhile!)
  10. Enable console autologin using raspi-config
  11. Fix locale using raspi-config
  12. Change the hostname to “pvspi0” using raspi-config
  13. Edit /etc/dhcpcd.conf so the ethernet is not used as a gateway
  14. apt install chrony
  15. apt install avahi-daemon
  16. Disable wifi power saving
  17. Reboot the pi
  18. Log in to pvspi0.local using pi/newpassword.
    Note mDNS takes awhile to start working, a minute or two after the RPi starts up
  19. Install haproxy
  20. Configure /etc/haproxy/haproxy.cfg. I did not include stats.

A brief note on power consumption. Idle the RPi Zero 2 W seems to use about 165mA (at 5W). Running stress-ng -c 4 peaked at 570 mA. The magic number here is 500 mA, that’s the minimum power for a USB port. I expect the system to basically be idle all the time so I think I’m safe with no extra measures. But some ideas on reducing power consumption.

  • Turn off HDMI. Instructions don’t work.
  • Turn off LEDs
  • Use fewer than 4 cores
  • Turn off unnecessary daemons. bluetoothd, hciattach (the serial console)

Here’s the bonus snapshot of some of my Grafana config. Not running on the RPi; all its doing is proxying requests. These graphs are centered on showing the status of all 28 separate panels, something you can only do by accessing the PVS6 data directly.

Raspberry Pi 4 thoughts

I got a new Raspberry Pi 4. It’s neat! Some thoughts on it. Bottom line: it’s a great little computer and my only complaint is the SD card I/O is slow.

First, context. A friend gave me an original RPi Rev B way back in 2012 or so. I’ve used it every year or two when I needed a small Linux box to do something. For awhile I had RetroPie on it for gaming. I dusted it off last week to serve as a network proxy for my SunPower PVS6 solar power monitoring system. It’s working great for that! But it’s a very slow, limited system.

So I bought a new RPi4. I got a Vilros kit that includes a case, a power adapter, heatsinks, an SD card, various cables. It’s very convenient. The core computer is $55 but the kit is $135. Probably not a great value but this was in stock at Amazon; like everything else these days, availability is not great.

The RPi4 is the first RPi capable of running a 64 bit OS. The ARM Cortex-A72 CPU in it is quite capable but nothing too exciting, but since it’s the ARMv8-A architecture it’s pretty well up to date. You have your choice of 1-8GB RAM wired on the board. And all the IO integration that makes the RPi so popular. 4 USB ports, gigabit ethernet, two HDMI ports, WiFi and Bluetooth built in, an audio jack, and of course the famous GPIO pins for hackery.

A word on cases. A nice case goes a long way to making it feel like a “real” computer. The Vilros case is a nice aluminum case that fits just right. RPi4s apparently run hot, at least when actively used. My case has an always-on fan. There’s a bunch of passive cooling cases that basically turn the whole chunk of aluminum into a heatsink, that seems like a better idea if it’s sufficient.

On power: the RPi4 uses 3-5 watts. Everyone recommends a good USB power supply, the official one is 5.1V/3.0A. Alternately the RPI4 can be powered over ethernet with a small extra board. Note 3A is a lot of power for USB; that’s a device intended for charging, not just a random computer’s 0.5A USB port.

Operating system

Vilros shipped an SD card with Raspberry Pi OS (aka Raspbian) installed. Full desktop environment. I used it for a few minutes and it seemed to work but was as unlovely as any Linux desktop. Also slow; you could see the background picture repaint when I dragged windows. I only want this as a headless server so I wiped it and put Ubuntu 21.10 server on it. How about that? Stock Ubuntu, compiled for aarch64 and with a clean boot loader. Shout out to the RPi folks for creating a great disk imager. There was also a thing called NOOBS, a small boot system which let an RPi install its own OS, but I guess that’s deprecated.

The RPi4 has some complex boot loading and firmware overlay stuff. I don’t understand it but it seems to work. USB booting is supported via a bootloader on the SD card.

One drawback with Ubuntu is it’s less clear how to tinker with the Raspberry Pi-specific stuff. Raspbian has raspi-config which lets you adjust things like clock speeds, GPU memory usage, etc. It looks like you can just edit config.txt on the Ubuntu boot partition, this works sort of like BIOS settings but for the RPi.

Another useful tool for RPi-specific hacking is vcgencmd. This lets you get at a bunch of state on the GPU, which apparently in this Broadcom implementation is controlling the whole system. This lets you get at things like how much RAM is dedicated to video (78MB for me) and what the current temperatures, voltages, etc are.

There’s a whole lot of software dedicated to working with the GPIO pins. This capability is the really neat hidden feature of the RPi and gets pretty complex as you mess with different modes of I/O: I2C, Serial, etc.

Performance

No one buys an RPi4 for performance. But it’s pretty impressive, particularly by historical standards. Unfortunately it feels slow for interactive stuff. But then I’m spoiled by fast machines with SSDs. The main issue with the RPI4 is the SD card is slow. Some comparisons to an Intel NUC based on a i5-7260U.

With the cheap SD card Vilros sent me hdparm reports about 45 MB/s. Compare 100 MB/s for a spinning disk on an Intel NUC or 1600 MB/s to SSD. I’d hoped the SD would be faster. And that 45MB/s is for synthetic tests: this blog post says 7 MB/s for reads for random access reads. SD cards are clearly not a fast medium. This blog post suggests 100-300MB/s with a proper SSD drive plugged in to USB 3, which is big boy PC speeds but nothing amazing. The RPi4 can boot off USB so you can eliminate the SD entirely if you want. It’s too bad they don’t have an NVMe interface, but then that’d require a PCI bus. (The Compute Module product does have one.)

Another word on I/O: older RPis implemented ethernet on the USB bus so performance was severely limited, particularly if you wanted to use it as a router with multiple ethernet interfaces. Raspberry Pi 4 has a dedicated channel for its ethernet separate from USB, so that helps.

RAM is reasonably fast. Testing with sysbench I get about 4GiB/s on the RPi 4; compare 17GiB/s on the Intel NUC.

CPU is impressively fast. Again testing with sysbench, using one or two threads the RPi was about 1.35x faster than the i5-7260U. With 4 threads the RPi is 1.6x faster. The Intel CPU is 4 threads but only 2 real cores; the RPi4 has four cores. I have no idea if this is a real world CPU benchmark, probably not.

I played around with overclocking a bit. Boosting CPU speed from 1500MHz to 2000MHz gave me about 1.3x speedup. Max temps were 45C and 52C respectively. Then I found the arm_boost=1 config.txt setting, which apparently gets you 1800MHz as a temporary boost with extra voltage. I don’t normally overclock but since they say it’s safe I’ll leave that enabled.

I found a note in the docs that suggests there is no hardware support for video decoding.

Thoughts

What an impressive bit of kit. What I like best is how contained it is; a small pack of cards running a real 64 bit Ubuntu with zillions of hardwaer ports. The only drawback from a conventional computing point of view is you’re limited to USB 3 for disks. And hell that’s not bad at all, with an SSD significantly faster than computers I was using on the daily a few years ago. If I were using the RPi 4 interactively I’d be sure to set up USB booting to a fast disk.

But I’m not using it interactively. In fact I probably won’t use this RPi4 much at all. The old RPi B is doing fine as my proxy device. But now I’ve got this little swiss army knife computer sitting around for the next project where I need something this flexible. I’d like to learn more about ARM as a practical server platform. Or maybe I’ll use it as a web a server for my plotter. Or a base for some home automation tinkering via those tasty GPIO pins.

One other thought; the RPi 4 is the flagship product but there’s other devices. The Raspberry Pi Zero 2 W is a smaller, cheaper system suitable for less demanding uses (like being a web proxy). I/O ports are limited but for a certain type of application it might be more suitable. There’s also a Compute Module which looks like an RPi 4 only without all the I/O ports (and with the SD card built in). I think this may only be of interest to folks designing embedded systems.

Raspberry Pi notes

Raffi gave me a Raspberry Pi, the $35 ARM based Linux system. Capable little beast: 256MB RAM, 700MHz ARM processor, a GPU that can drive 1080p and decode video, it’s an interesting device. Some notes:

Hardware

Batteries not included. In addition to the board itself, I needed:

Hilariously the whole machine reboots when I plug in the WiFi adapter; my guess is a power problem. It boots fine once it’s plugged in though.

RAM is shared with the GPU. The split is (now) configurable, so I have 192MB system RAM and 64MB GPU RAM. Newer boards have 512MB on board.

Software

The primary software distribution people use is Raspbian, a giant 1.5 gig full Debian system. It’s cool that you get a full normal Unix system but boy are we a long way from an embedded OS. The architecture is “armhf” with a change, using hardware floating point in the ABI. Apparently there’s several incompatible Debian ARM versions running around; armel, armhf (soft float), armhf (hard float), etc.

There is no BIOS on the board and no LILO or GRUB bootloader has been ported to the Pi yet. The bootstrap expects a FAT filesystem that it can execute a kernel off of. Raspbian has a small FAT partition with a kernel and then a big ext4 partition for the rest. There is an effort for a bootloader called Berryboot but it boots off of SquashFS filesystems which AFAIK are read only. Haven’t tried it.

Raspbian out of the box works well. Username: pi, password: raspberry. You’ll want to use rsapi-config to set the keyboard if you have a US keyboard.

The main thing I had to do was set up wifi, which uses wpa_supplicant. I found this example config file helpful. End of the day, all I needed to do to get wifi working was add the following little block to /etc/wpa_supplicant/wpa_supplicant.conf. (Note, both my SSID and password are wrapped in quotes for the config file.)

network={
  ssid="mySsid"
  psk="my password in quotes"
}

Voila! With all that set up I now have a working underpowered Linux box. So what is this thing actually good for? To me what’s most exciting is the HDMI output; it can drive a TV! To that end I found two possible end uses. OpenELEC, for viewing videos via XBMC. Or MAME/MESS for playing games.

MAME

So what about MAME? My first try was PiMAME 0.3, a full distribution that boots right into AdvanceMAME for a chooser. Looking at it, it’s basically Raspbian with some extra software installed and a login script to launch MAME. (An annoying one, I might add; it’s awkward to get a shell and virtual consoles don’t seem to work). Also the setup isn’t usable with just a USB joystick now, you really need a keyboard to drive both AdvanceMENU and AdvanceMAME itself. Full props to the PiMAME author for working on a convenient turnkey distro, but it’s not there yet. I think I’d rather use a plain Raspbian distribution and build up my own MAME environment, using his packages.

So how to install by hand? I followed notes from this blog post, skipping over the “how to use Unix” parts and getting right to MAME. In a nutshell:

  • Install the AdvanceMAME .deb by hand, downloading from http://sheasilverman.com/rpi/raspbian/debs/
  • Create a MAME user strictly for running MAME. Put it in group video
  • Launch “mame mspacman” from a local console to play a totally legitimately acquired copy of the Ms. Pac-Man ROM.

It works! It’s very slow compared to PiMAME 0.3; I imagine I’m running into the same problem the PiMAME guy is having with the most recent raspbian distributions. Also I haven’t tried sound yet. And AdvanceMAME is some 7 years old; in theory the mainline MAME 0.147 should work on Raspberry Pi but the details of getting SDL and Sound working in this environment are rumored to be difficult.

Thoughts

The Raspberry Pi is an impressive little device. For the size, power (3W), and price it’s amazing to have a full real Unix distribution. I’m not sure what it’s actually for though. Its creators talk about education, about giving kids an affordable hackable platform. I think that’s awesome but is this really it? Maybe so, but I’d think a discarded PC would be just as good. Or something with a portable screen and input method.

As a general purpose hack thing it’s a lot of fun. What’s missing though is some sort of hardware bridge, say Arduinio.

As an embedded device it’s impressively capable. It’s nice to imagine building a whole Internet TV device on it, for instance, with a full real Unix behind it and not having to fart around with an embedded OS or iOS or something. I’m sure there’s drawbacks, but..

I’m trying to get my head around having a full Debian system on this. I’ve been conditioned to think of embedded devices as black boxes; you flash the firmware every six months and then run what’s there, no upgrading or changing. Raspbian feels more like a persistent OS to me, something I’m going to add and upgrade and change rather than wipe and start over regularly.