Thursday, October 8, 2020

My Raspberry Pi 4 Desktop System

 


A couple of months ago, I bought a 4 GB Raspberry Pi 4 and decided to see whether I could use it as a desktop system. After some trial and error, I finally have come up with what seems to me to be a usable configuration.

The first decision I made was the case. I'd read online that heat was an issue with the Pi 4. To keep the Pi from throttling from overheating, you can either use an active heat dissipation system--a fan or even a liquid cooling system--or you can use a passive system, with large heat sinks and enough surface area to shed heat. I don't want a noisy fan, so I read several online reviews and bought a case from Flirc. The Flirc case is designed to be a heat sink. It has a column that seats atop the CPU and conducts heat up into the case. The Flirc works well; my Pi 4 has never come close to throttling due to excessive heat. The idea seems to have caught on, and there are other similar cases on the market now.

Since I was aiming for a cheap desktop system, I didn't want to buy expensive, high-end peripherals. I bought an Acer KA220HQ monitor, and I tried an Amazon Basics wireless keyboard/touchpad before settling on a Logitech K400 Plus wireless keyboard/touchpad. Eventually, I replaced the keyboard/touchpad with a Logitech K380 Bluetooth keyboard and Logitech M535 Bluetooth mouse--more about the monitor and input devices later.

Since my Pi 4 was going to be a desktop system, I wanted it to be able to have adequate audio and video capability. The built-in audio on the Raspberry Pis isn't great, so I looked for a digital-to-analog converter (DAC). Because I'd already ordered the Flirc case, I decided to buy a USB DAC instead of a HAT (hardware attached on top). I picked the Sound Blaster PLAY! 3, a nice reasonably priced USB DAC. I bought Logitech S120 stereo speakers and a Cyber Acoustics ACM-51 microphone to use with the Sound Blaster. For video, I bought a Raspberry Pi camera module V2 and a Makeronics clear acrylic holder case. The ribbon cable is clunky, but it works.

Once I had all the pieces, I plugged them together and had a great little inexpensive desktop system. Well, no, not at first. The first Pi 4 I ordered, I tried several micro HDMI to HDMI cables, but I couldn't get any of them to seat properly in the micro HDMI port on the Pi 4. I contacted Canakit, the company that sold me the Pi 4. They replaced the Pi 4, and the new one worked.

I installed Pi OS (formerly Raspbian) and ran into my second hurdle. The monitor randomly blanked. I read up on display issues with Raspberry Pis--the online documentation for boot configuration options was especially helpful. It appears that the Pi 4 can't read the EDID (extended display identifcation data) from the Acer monitor. I tried downloading the EDID data into a file and editing config.txt to use the file, but that didn't work, either--the system came up in 640x480. I eventually came up with a boot-time HDMI configuration that improved the screen blanking problem, but even with that, I also have to manually set the mode and group for the display each time I booted the Pi 4. The screen still randomly blanks once in a great while--an annoyance, but I can live with it.

The Pi 4 was barely usable as a desktop system. It was slow and not very responsive. Looking around online, I found several blog and video posts that suggested that Ubuntu Mate is much snappier. I installed Ubuntu Mate on a second SD card and gave it a try. It did seem more responsive, and it also seemed to get along better with my Acer monitor--it was able to identify the Acer. My subjective impression was that Ubuntu ran a little hotter than Pi OS. The deal breaker for me was that I never could configure Ubuntu to use the camera.

Doing some more research, I came across suggestions that using an SSD (solid-state drive) instead of an SD card would greatly improve performance. I bought a 120 GB Western Digital Green SATA SSD and a Sabrent M.2 SSD to USB 3.0/SATA III enclosure. I made sure that the Sabrent enclosure could do UASP (USB attached SCSI Protocol) rather than the slower USB storage protocol. When I first got the SSD, USB booting was not in the default critical Pi OS stream, so I had to switch to the stable stream. But it worked, and the SSD really improves performance. And now, USB booting is available in the default Pi OS stream.

By this point, I had only one open USB port available for anything else I'd like to use with the Pi 4, such as a flatbed scanner or a thumb drive, so I bought an Anker 4-port USB 3.0 hub, which worked well. As I plowed through more online articles and videos, it became clear that power can be an issue with the Pi 4. I read advice to use powered USB devices, rather than ones that draw power from the USB bus on the Pi 4. I thought that power could have something to do with the screen blanking problem. So, I bought a  UGREEN SATA to USB 3.0 adapter cable and an Atolla powered USB 3.0 hub. I also got the Logitech Bluetooth keyboard and mouse, to free up another USB 2.0 port. The powered adapter cable worked fine with the Sabrent enclosure. But when I tried using the powered USB hub, it interfered with the SSD--the SSD became corrupted, and I had to reinstall. So, I ditched the powered hub and went back to the Anker.

By now, I had a usable system, but the SSD and USB DAC and the hub were taking over my desk. So, I got a Yahboom Raspberry Pi cluster case. The Pi 4 in the Flirc case sits on top--the case is too tall to fit between the shelves. The Sound Blaster DAC and the USB hub fit in the middle shelf, and the SSD sits on the bottom shelf.

I'm pretty happy with this setup. The system works reasonably well. Once in a great while, the display will blank, and I've changed my browser habits so that I have a minimum number of tabs active at any one time. But this is a usable desktop system.


Saturday, September 19, 2020

Network Monitoring, Static Addresses, and WiFi Extenders

In my previous post, I wrote about turning a Raspberry Pi into a network monitor, using Nagios and arpwatch. If you want to use Nagios to monitor networked equipment, then each piece of monitored equipment needs to have a static IP address--an IP address that never changes. Most networked devices are configured by default to request an IP address via DHCP (Dynamic Host Configuration Protocol) from the WiFi router, and by default, WiFi routers will assign a dynamic IP address--an IP address that might be different each time the device boots up.

There are two ways to go about assigning static IP addresses. You can configure each networked node's network interface, using whatever management tools the node might have. You'd have to manually configure each device, and you'd need to keep track of the IP addresses so that you don't accidentally assign two nodes the same address. You'd also want to be sure that all the IP addresses lie outside the range of dynamic addresses that your WiFi router doles out.

 

The easier, more centrally managed solution is to use your WiFi router to assign static addresses. Most WiFi routers let you configure static addresses that the router will assign via DHCP. This is probably a writable table of MAC (media access control) addresses and their corresponding static IP addresses, as in the image above--on this router, the table is called a DHCP reservations list. The beauty of this approach is that you only need to configure your WiFi router and then reboot your networked equipment. This is the method I used.

All went well--until I added a WiFi extender to our home network. We live in a split-level home, and our WiFi router sits on a shelf in a closet on the ground floor. Signal strength is not the best on the top floor. We'd recently visited some friends, who'd asked me to configure a new WiFi extender they'd bought, a TP-Link AC750. It wasn't hard to set up, and it seemed to work fine. Back at home, I decided to buy one for the top floor. When it arrived, I configured it and reconfigured a couple pieces of equipment to use the extender. The extender worked well, except that monitored devices that used the extender no longer were visible in Nagios. A quick glance showed that they'd new IP addresses, not their static IP addresses. What had happened?

 

I logged into our WiFi router's management interface and looked at the client status. I could see that the TP-Link had changed the MAC addresses of the devices that were using the WiFi extender. The TP-Link had substituted the first three bytes of its MAC address for the first three bytes of each device's MAC address. The simple fix was to change the MAC address in the DHCP reservations list to match the new MAC address the TP-Link was using.

I don't know whether the altering of MAC addresses by the TP-Link is common to all DHCP relays, or whether this is something unique to this brand of WiFi extender. In any case, although it's annoying to have to change the DHCP reservations list every time I switch a device from the WiFi router to the extender or vice-versa, it's not a difficult work-around.


Saturday, August 1, 2020

Setting Up a Raspberry Pi 3 as a Home Network Monitor

I repurposed my Raspberry Pi 3 to monitor our home network. In the picture, it's the small black box underneath the white cable modem and to the right of the cable amplifier. I followed the steps outlined in the article "How to use Raspberry Pi to monitor network? (Nagios)" by Patrick Fromaget, at his website RaspberryTips. I ran into a couple of head-scratchers when I installed Pi OS Lite. Out of the box, the OS was configured for British keyboards, and it was a little tricky choosing the right options for my cheap wireless keyboard/trackpad. The other roadblock was that wi-fi was disabled. To enable it, I had to unblock it:

rfkill unblock wlan
shutdown -r now


I'd had some experience with Nagios, so I had no problems building and installing it from source, following Fromaget's instructions. I customized Nagios to monitor the temperature of the monitoring Pi. First, I added a /usr/local/nagios/libexec/check_cputemp executable. It's a shell script:

#!/bin/bash

cpu_lo_warn=-30
cpu_lo_crit=-40
cpu_up_warn=75
cpu_up_crit=85
cpu_temp=$(</sys/class/thermal/thermal_zone0/temp)
cpu_temp=$((cpu_temp/1000))

if [ -z $cpu_temp ]; then
  echo "UNKNOWN - Undefined CPU temperature"
  exit 3
fi
if [ $cpu_lo_crit -gt $cpu_temp ]; then
  echo "CRITICAL - CPU temperature $cpu_temp too cold"
  exit 2
fi
if [ $cpu_lo_warn -gt $cpu_temp ]; then
  echo "WARNING - Low CPU temperature $cpu_temp"
  exit 1
fi
if [ $cpu_temp -gt $cpu_up_crit ]; then
  echo "CRITICAL - CPU temperature $cpu_temp too hot"
  exit 2
fi
if [ $cpu_temp -gt $cpu_up_warn ]; then
  echo "WARNING - High CPU temperature $cpu_temp"
  exit 1
fi
echo "OK - CPU temperature $cpu_temp"
exit 0

Next, I added a check_local_cputemp command, by adding these lines to /usr/local/nagios/etc/objects/commands.cfg:

define command {

    command_name    check_local_cputemp
    command_line    $USER1$/check_cputemp
}


Then I added a CPU Temperature service to localhost, by adding these lines to /usr/local/nagios/etc/objects/localhost.cfg:

define service {

    use                     local-service
    host_name               localhost
    service_description     CPU Temperature
    check_command           check_local_cputemp
}


Then I restarted Nagios. Now, the services page has a CPU Temperature service for localhost.

I also wanted to monitor new equipment that might pop up on our home network, so I installed the  arpwatch and Postfix packages. I administered  a sendmail server for quite a few years, but that would be overkill for a network monitor. For information about installing and configuring Postfix to send outgoing mail, see Tutorial - Install Postfix to allow outgoing email on Raspberry Pi, at the Ste Wright website. Basically, I did a sudo apt-get install postfix and specified the Internet site and default hostname.

I installed arpwatch with sudo apt-get install arpwatch. Then I configured arpwatch to email me whenever anything new happened on the network, by creating the file /etc/arpwatch/wlan0.iface with the single line IFACE_ARGS="-m my@email.address" (where "my@email.address" is a valid email address to receive arpwatch messages). Then I issued the commands:

sudo systemctl enable arpwatch@wlan0
sudo systemctl start arpwatch@wlan0


For more information about configuring arpwatch, see How to monitor Ethernet Activity using Arpwatch tool, at LinuxHelp.

Once I had the Pi configured, I shut it down and mounted it, headless, on my crude network equipment board. It was easy, the classic Raspberry Pi case has two holes in the base for mounting. I plugged the power supply in, and it works!

Tuesday, June 23, 2020

Greeting My Experience



Why do people give up on meditation? "I can't make my thoughts go away." "It's boring." "Nothing happens." "I get fidgety." These are all variations on the same theme: "When I meditate, I don't have the kind of experience I think I should have." All these reasons not to meditate miss the point of meditation. I don't meditate to have a certain kind of experience; I meditate to be more fully present with whatever experience happens while I meditate.

When I meditate, I try to have an open curiosity about whatever comes up. I don't foster an analytical curiosity, a type of curiosity that tries to identify and understand. Instead, I try to develop more of an artistic appreciation of whatever is happening, a curiosity about what this experience actually is. I don't try to resist or push away anything that arises. Instead, I try to greet everything, to welcome anything that comes up. This doesn't mean I try to like everything I experience while I sit. It's a little like wandering through a museum, or listening to a concert, or watching a movie. I may not like everything I'm seeing or hearing or feeling, but I try to appreciate everything as it is.

So, for example, if I'm having thoughts, I just recognize that I'm thinking, and I let it go. I may have the thought, "I'm thinking--I shouldn't be thinking!" Okay, I realize I had that thought, and I let it go. If I feel I've failed because I'm having thoughts, I say to myself, fine, I'm feeling failure--and then I let it go. The same applies to boredom--okay, I'm bored. No big deal, let it go, on to the next moment. If my entire meditation consists of me releasing thoughts or recognizing I'm bored, then that's what that meditation experience was. The point is to accept the truth of each moment, as it is, without resistance.

Over time, this ability to appreciate each moment begins to affect daily life. As I become less likely to react dramatically, I become better able to pause and consider what has happened, and then, I hope, to act more wisely. I become less caught up in regrets about the past and worries about the future; I become more involved with what is happening here and now.

This is the essence of meditative practice. It's not another means of controlling what is happening, it's not one more expectation to meet, it's not one more challenge that leads to either success or failure. It is simply allowing yourself to greet the present moment, whatever it is. Everything else that you might want to get from a meditation practice flows from this.

Sunday, June 7, 2020

Whole Lotta Nothing



What do you need to meditate? Not much! All you really need is a little time. You can meditate almost anywhere, anytime your attention isn't being demanded. As long as you are conscious, you can meditate.

While you can meditate anywhere, it's best to have a dedicated quiet spot where you aren't going to be disturbed, especially if you're new to meditation. You should have a comfortable place to sit in a position that doesn't foster drowsiness. You can use a cushion, or a chair--you don't have to contort yourself into a pretzel. (If you want to practice walking meditation, you don't even need a place to sit!) Reclining or lying down can invite sleepiness, but if you have some kind of bodily limitation that makes it difficult to sit for long periods, then lying down is a good option.

You probably will want a timer. During meditation, your sense of time can be tricky, so especially when you're beginning a practice, it's good to time your meditation. But you can meditate without a timer--just meditate for as long as feels right. While you can spend a goodly amount on a dedicated meditation timer, it's certainly not necessary. A timer doesn't need to be anything fancy--free timer apps are available on smart phones, or you could use a kitchen timer. You can also use a clock or watch, and peek at the time when you think your meditation period is over.

Some people like to have a meditation altar. If you meditate within a religious or spiritual tradition, an altar might be a nice idea. An altar can reinforce the sense that the place you meditate is dedicated to your practice. But you don't have to have an altar to meditate. Likewise, objects like crystals, statues, pictures, incense, flags and banners might help make your meditation space feel like a special place devoted to practice. But you don't have to have any of those things to meditate, either.

You can pay an instructor and take meditation lessons. Investing a little of your money in your practice might be a good thing--it tells your subconscious that you're serious. It might make it more likely you'll maintain a practice over a long period of time. But it's not necessary. A teacher might grant you some kind of mantra (a phrase to repeat) or some kind of spiritual empowerment. Regardless of whether such things actually have any power, the sense of specialness might energize you. And being part of a student community, a community of practitioners, can only help your practice. But you can meditate without a teacher, without a special mantra, and even without a supportive community.

So if you're curious about meditation, if you have any interest at all, there is nothing stopping you from giving it a try. The only obstacles to meditation lie inside.

Wednesday, April 15, 2020

Meditation and Compassion


A meditation practice can be brutal. Meditation is all about being present with whatever arises. And since I've never been a saint, a perfected being right from birth, some of what arises during meditation is not pleasant. Unhappy memories, feelings of embarrassment and shame, anxieties about the future, anger, frustration--all these boil up at one time or another, along with the more mundane distractions, the shopping lists, the todo lists.

But it's not just while I'm on the cushion. Meditation has given me a small space between provocative stimuli and my habitual reactions, a gap that gives me a chance to catch myself before I react destructively. But that space also can be a harsh spotlight that shines on the uglier sides of my personality, the parts of me that want to lash out in self-righteous anger or that want to numb out with mindless entertainment or a drink or two.

Meditation provides me with a mirror, both while meditating and while going about daily life. I don't know very many people who look in a mirror and like everything they see. By itself, a meditation practice can become a harsh, tyrannical court of self-condemnation. That's why practices to develop compassion are a necessary complement to meditation practice.

In my experience, compassion means shadow work. All the parts of me that I don't own, that I project outward onto others--that's shadow. Shadow contains all those unpleasant bits of self that cause embarrassment, shame, guilt, everything I don't like. Shadow also contains treasures, hidden talents, secret passions. There are many ways to work with shadow--Jungian depth psychology, dreamwork, shamanic practice, and many types of Buddhist practice, for a few. All center around reintroducing the self to the parts that have been pushed aside.

Shadow work is self-expanding, heart-opening, empathy-developing. It's the essence of compassion. It allows me to sit with myself as I am, to embrace whatever arises, on the cushion or off. Open-hearted mindfulness, compassionate presence--this is the center of my practice. And "practice" is definitely the right word; I haven't mastered this yet, and may not ever. But sometimes, in the gap between stimulus and reaction, when I can stand there and be compassionately present, wisdom can miraculously appear. And that's when the wonderful, mysterious, healing magic happens, the magic of responding with wisdom, rather than reacting mindlessly.

That's what it's all about.


Sunday, April 5, 2020

Meditation 101

I'm offering my services as a meditation mentor, so I thought I'd begin posting a few pieces about meditation. So for this inaugural meditation article, I'd like to begin with what I feel is the most essential item you need to begin a meditation practice--commitment.

You have many reasons to begin meditating. You might be seeking relief from pain, or a lower risk of heart disease, or mitigation of the effects of stress. Medical research has shown that meditation can have many benefits for your health and well-being. Or, you might be trying to improve your golf game--many top athletes and coaches practice meditation. Or you might want to achieve enlightenment, or develop the special powers mentioned in the Yoga Sutras. But your initial motivation can change or even disappear with time. Your medical condition might resolve, you may lose interest in golf, you might lose interest in your spiritual or esoteric path.

Difficult circumstances can challenge a meditation practice. It's easy to meditate when there's plenty of money, no danger of losing your apartment or home, no chance you'll miss a meal. When you have plenty of leisure time, it's not hard to spend a few minutes each day meditating. But circumstances change, you may lose your job, or you may get a new more demanding job, or you may start a family. Time may become more precious.

But there is one thing that will guide your meditation practice through the perils of shifting motivation or challenging times, and that is commitment. Commitment to a meditation practice--internal commitment, not commitment to someone else or some group--this is what will keep your practice alive.

How can a person have commitment? By realizing that a meditation practice is worthwhile in and of itself. This only happens via meditation--more meditation can develop more commitment. It cannot be put into words easily. It's an inner knowing that builds up slowly as you experience meditation over time.

An enduring, resilient meditation practice stems from meditation practice. Whatever gets you on the cushion or the chair seat at first, whatever put the idea of developing a meditation practice in your head--that will take you only so far, like the push a parent gives a child when they start learning how to ride a bike. You have to start pedaling yourself. That's when commitment will grow and your meditation practice will really start rolling.