The Power of Raspberry Pi–rethinking and restructuring to do even more with less

To start this story at the very beginning, go to this post. To go to the previous post in this series, go here. As it may be clear from the discussion so far, I have a tendency to increasingly add more requirements and functionality to my Raspberry Pi (and/or the newer version 2 RPI-2) computer until it cries “uncle”–or more often than not, just quietly dies under the extreme load. This post is about adding more functionality, but by being smarter, avoiding the dying part–at least for now.

myth tv running on raspberry pi
Every traditional boatwright needs to watch the Woodwright’s Shop for inspiration.

One of our luxurious activities when paying to be at a marina with shore power is to run my Shuttle small-form-factor (SFF) computer with its Intel i7 CPU and lots of RAM and lots of storage space. When it is running, it records over-the-air–using an antenna–HDTV movies and shows according to various rules we have programmed. Those shows are re-encoded by the Shuttle computer in a very efficient format to make the files smaller–1/3 to 1/5 original size–and then saved to a hard drive for later viewing–like when storm-bound in a remote bay somewhere in Alaska.

Our time in marinas is limited and the Shuttle requires too much power to run just for recording shows (producing non-shore power electricity is very expensive) and the movie recording program is way too demanding for a regular RPI. But now I thought maybe, just maybe, the new RPI-2 could record TV programs–of course I really mean do that in addition to all the other stuff the RPI-2 already does.

The program we use to record over-the-air shows is called MythTV. I have a love-hate relationship with MythTV, but we have been using it for about 10 years and it keeps track of every show ever recorded by us so that it doesn’t re-record something we already have on a hard disk or DVD or CD-ROM somewhere on Mahdee or in storage. The challenge for us is that the database for MythTV has a huge number of recordings (way over 10 thousand) to keep track of and the scheduler needs to sort through all of our rules (which are numerous and have evolved from our refinements over those same 10 years) and compare rule-matching scheduled showings to already recorded shows and determine which shows to actually record when so as to optimize the recordings. I had my doubts that even the RPI-2 would be capable–let alone doing that task while also doing the really important stuff like keeping track of the weather and how well the anchor is holding–after all, we do have to keep our priorities straight.

To make the RPI-2 able to record TV movies we had to make some changes.

1. We bought a network HDTV tuner (HD HomeRun Extend HDTC-2US) that has a built-in transcoder that re-encodes the movies in a more space-efficient format (H-264) on-the-fly. This removes the requirement for the RPI-2 to re-encode the recordings–which it couldn’t do anyway–and keeps the file sizes reasonable. In addition, H-264 is an open standard whereas the original inefficient proprietary format used in over-the-air transmissions requires one to buy a MPEG license before the RPI-2 can perform hardware decoding for viewing. So not only is the output of the HD HomeRun more space efficient, it also uses an open standard that doesn’t require the purchase of a license. The HD HomeRun even runs on 12V DC which is nice. So we installed a 60W regulated 12V DC power supply on Mahdee to use the HD HomeRun off a 12V DC battery.

2. The other change was to continually power up the Linksys Wifi router. The Linksys is also powered by 12V DC–so it can use the same newly installed regulated power supply as the HD HomeRun. Earlier, we tried to make the RPI be Mahdee’s Wifi access point in order to save the power required to run the Linksys. Running the Linksys offloads the Wifi access point functions but more importantly, also provides a needed Ethernet hub. The hub makes is possible for the HD HomeRun tuner to be available to the RPI-2, as well as to my Shuttle computer, all over fast Ethernet rather than Wifi. Further, we decided that we could also keep running the old RPI and use it via Ethernet to offload some functions from the new RPI-2–such as internet gateway, firewall, GPS server, network time server using GPS, secondary/backup anchor position alarm, Scrabble game server (oh–didn’t I mention that requirement), as well as that coveted contact and calendar schedule web server.

The net result is that, even though we now have two Raspberry Pi’s running (an RPI and an RPI-2) along with a network TV tuner and a Linksys router (the latter two alone adding 24 amp-hours a day to our afloat battery usage), our electric power usage is less than half of what it was at the dock with the Shuttle computer running. We are now getting recordings and a practical, fun to use computer that is available 24-7 even while at anchor. All that while logging weather and boat data and monitoring that important data with alarms to keep us safe. The RPI-2 has been exceptionally reliable with our previous and current up-time exceeding three weeks since the last intentional reboot.

When passage making, we can turn off the network TV tuner, Linksys router and the RPI to reduce power usage without loosing any important functionality–e.g. don’t really need our contact server in the middle of the ocean. And with no TV tuner, we can turn off MythTV and have plenty of CPU capability on the RPI-2 to run the OpenCPN chart plotter which can use either the weather/boat data pseudo serial port on the RPI-2 for GPS data or the GPS data on the RPI if it hasn’t been secured to save power. With this nice flexible and stable setup, I have to keep telling myself not to add anything new. Unfortunately, I know that it is only a matter of time before I come up with new ideas of things/tasks/programs to add to the RPI-2. With any luck, a new more capable RPI-3 will come out before I completely overload the RPI-2. Right now, however, I am really happy with both my RPI and RPI-2.  Next I will cover some tips for running MythTV on the RPI-2 without impacting all the other stuff the RPI-2 needs to do.

Fires and Fire Ants

We recently arrived at one of our favorite, idyllic anchor spots. It’s a spot that is sheltered from wind and has reliable stretches of warm dry weather–perfect for varnishing. Our arrival this year was about a week too soon because the temperatures have been way too hot (upper 90’s F with a couple days over 100F) for either sanding or varnishing. As a result, we have spent time on the computers interspersed with two or three leaps overboard into the very pleasant 78F water to cool off. Night time temperatures cool off nicely, but the ship’s cat has been a real complainer–her thick Norwegian Forrest cat fur being just too much for the local conditions and she has never been one for swimming.

The first sign of real trouble was a huge dragon fly that I had earlier admired on the fore-deck was later covered in and being consumed by ants. I threw the carcass overboard and hosed down the deck and regretted not taking a picture of the big dragon fly before its demise. Then Brenda noticed some ants down below one evening, and more the next evening. Brenda remarked that a visiting friend, Milly, had mentioned ant problems on their boat last year. The pieces were beginning to click together. We wondered where the ants could be coming from. In the light of day, there were no ants on any shore lines. Ants can’t swim, so we wondered if a few were dropping from the over hanging tree limbs or being carried by the wind.  We didn’t yet realize that the ants on Milly’s and our boat were no ordinary ants.

The two mile stretch of water on either side of where we anchor is a posted 5 mile-per-hour (mph) no wake zone to protect the embankments. It is one of just a few areas in the California Sacramento Delta that still has large trees lining the banks and excessive wakes erode the soil around tree roots and leads to fallen trees. During our varnish-fest stay here, we feel we are doing a great public service by giving speed boats another reason to slow down to something near the posted 5 mph limit; the drivers may not be literate because before and after passing us, many are going closer to 50 mph and throwing out huge wakes.  But, where the speed limit signs don’t work, a sense of courteous behavior sometimes does.

The waterway is a little wider where we anchor, but it is important to keep Mahdee near the embankment so that she is out of the way of passing boats. Further, to ensure that wind or wakes of law breaking boaters (without even a sense of what’s courteous) don’t throw Mahdee onto the rocky embankment, we usually have four lines holding us in position; the bow anchor, a stern anchor, a bow shore line and a stern shore line. It takes a little effort to get everything right, but with two of us on board we can get secured pretty fast and we sleep well at night.

Our friend Milly sails solo and so I volunteer to run the shore lines for her boat when she visits and anchors nearby. This year, when we were tying up Mahdee, I recognized the tree trunk from a previous visit, but initially thought it was a tree that I had once tied Mahdee to. The appearance of ants was a clue that perhaps this was the tree trunk that I had tied Milly to last year.

Then Brenda developed a nasty painful blistery welt and I remarked that I hadn’t seen such a welt since we lived in Texas and had fire ants in the yard and eventually the house too–a nightmare. We thought that fire ants couldn’t be this far north in California. I remembered seeing that they had been seen and reported in the LA/San Diego areas, but they couldn’t be this far north near San Francisco and Sacramento–could they?

Some online searching revealed that fire ants love a drought and that the current California drought has enabled the northward spread of these awful creatures.  California has classified fire ants as an invasive species and they are so destructive that some jurisdictions will quarantine an area, but fighting the spread of aggressive fire ants is a losing proposition. It was clear that not only were we once again in fire ant country, we had tied up right next to a big nest of them and they were in our virtual back yard–there goes the neighborhood.

In the video–a hint of things to come: I’m securing the shore line in entirely the wrong spot. The high crotch in a big tree seen towards the end of the video ultimately ended up being our safe-from-all shore anchor spot.

Shore anchor from Schooner People on Vimeo.

It was after dark and the cat’s water bowl was swarming with ants and she was clearly very distressed. I went outside with a flashlight and discovered that the bow shore-line was now twice its normal one inch diameter, thick and brown with an awe-inspiring invading army–now I was distressed too. We went to general quarters and locked down the boat. Our goal was to make it until morning when the ants would go into hiding from the heat and we could see well enough to reposition the shore line away from any fire ant nests.

Brenda prepared a bowl of boric acid and I sprayed and washed the deck and lines to knock off as many ants as possible. We left a dry segment of line where it came aboard the boat and coated that with powdered boric acid. We surrounded the water bowl with more powdered boric acid and put her food bowl in a moat using a baking pan of water. Poor kitty spent a miserable night in the heat and confused about how to flip her dry food out of the moated bowl and onto the floor which she does before eating each morsel. She whined and complained all night so that Brenda could hardly sleep and in the morning the moat around the food bowl was full of soggy uneatable cat food.  I was worried that while sleeping, I would roll over onto a string of these biting ants and be covered in painful welts. No one aboard Mahdee was happy.

First order of business the next morning was to relocate the bow shore line. Fortunately, the wind was blowing from Mahdee’s stern.  I untied Mahdee from the tree trunk and was very careful not to disturb the sleeping ants in the now obvious nest.  This stretch of slough has lots of trees to choose from so I picked the biggest tree and put the line way above ground level.

We are still left with a huge, but diminishing number of ants on the boat which are now cut off from their home nest. As we find them, we are killing and washing them overboard using the deck/anchor wash-down. With relaxed security measures, the ship’s cat is returning to her happy normal self and so are the humans.

In keeping with current events, I am now doing periodic “border patrols” to ensure our shore lines are not breached again and Brenda knows why Milly hasn’t been back to visit this year–she is reluctant to accept my misguided helpful actions of tying her boat up to a fire ant nest. The following morning, during a patrol I found the deck covered in black and white grit–another mysterious first. It turns out that a middle of the night wind-shift carried ash and soot from the devastating wildfires and coated our decks. We realized that the same drought that has enabled the fire ants to move here is also enabling horrific fires–a real double whammy for the area.

The Power of Raspberry Pi–the new resurrection

beryl and RPI On Lap Monitor
For background and to start this story at the beginning, go to this post. To go to the previous post in this series, go here. The Raspberry Pi (RPI) on Schooner Mahdee has continued to work well in its primary task–weather and boat data logging to hard drive and serving and displaying that data plus tides and currents as well as performing alarms for anchor position and wind speeds.

The RPI was clearly not good at interactive GUI applications except simple email and very basic web surfing. It was also not working satisfactorily as an Internet gateway and a Wifi access point. The harder we pushed the RPI, the more often it crashed and shutdown. Then the RPI-2 was released with 4-CPU cores and 1G RAM–four times the cores and twice the memory of the RPI–and I thought maybe now I can get everything I want.

The new RPI-2 is designed to use a more advanced ARM architecture which meant that a standard Linux distribution could be used rather than the Raspbian distribution required for the RPI. I like Debian, so I installed Jessie on our new RPI-2. The RPI-2 has a different setup of IO-ports so our woody Ti-Bow case was not usable. That gave me an excuse to keep the RPI in its case and temporarily mount the RPI-2 next to it without a case.

During the extended transition of applications and functionality from the RPI to the RPI-2, I connected the two together with a simple Ethernet cable–no hub needed. The 50W regulated 5V DC power supply we have on Mahdee has more than enough capacity to run both Pi’s, the HDMI monitor, Passport hard drive, along with various other USB accessories and device charging requirements. I describe installing Debian Jessie and setting up the RPI-2 to run the chart plotter OpenCPN here. That article also includes a link to download an installable copy of OpenCPN that I created.

Because we are sometimes without any Internet access, I try to anticipate and install applications before they are needed and while we have good Internet access. Whereas the RPI is well equipped with a 16G SD card, the Sandisk Extreme SD card we purchased for the RPI-2 has a capacity of 64G. More than 6000 packages are now installed on the RPI-2 using over 80 percent of those 64G. SD storage is primarily programs and their documentation because most data is saved on the external Passport USB hard drive. So we have lots and lots of programs. More programs than may ever be used.

There is some stuff (actually a lot) on the SD card that really isn’t needed there. Given our experience driving an SD card to its premature death by writing gigs and gigs of weather data to it, we are sensitive to this. Further, an SD Card with more free space will distribute writes so as to extend its life; a nearly full SD Card can not do this and is more likely to fail prematurely. Since the Passport USB hard drive is always connected (using an entry in /etc/fstab), we can move a few things there. My criteria is to only move things that are not needed to boot the RPI-2 and preferably things that have lots of writes; mostly static files that are primarily read can be left on the SD Card.

I create a directory on the Passport drive such as rpi2_rootdir and in that directory, I create the subdirectory rpi2_rootdir/var/cache. Then I move /var/cache/apt into that subdirectory and create a link to the new location in its place. The only time I really need the apt cache is when updating and upgrading and that subdirectory ends up with lots of data and writes that I would rather have on the Passport. Another file with lots of activity is /var/swap which is used by the package dphys-swap. That file is a swap file for when memory is scarce and therefore (unfortunately) can be heavily used in my setup. One can also move the /var/log directory to the Passport once everything is stable. Further, I create a subdirectory in my user home directory which links to a directory on the Passport drive and I use that directory (on the Passport) for most of my user data–e.g. my email folder, downloads folder, music folder, application data, etc.. With those changes, my usage of the SD card is now less than 50 percent–including a complete copy of NOAA charts on the SD Card as a backup.

After email (using Mutt) and general writing using VI/VIM, my most used interactive application is a web browser. In the original RPI, I often tried to use Midori, but it’s development fell behind and it failed to render a lot of sites. Net Surf and some other light browsers don’t work well for me. The new official light browser for the Pi is the Epiphany Browser. I have not been impressed by that browser either. Google Chrome is not available from the Debian ARM repository and I have not found an easy way to get it. My favorite browser, therefore, is Iceweasel (the Debian fork of Firefox). I install the Vimperator add-on which makes the browser usable without a mouse–you just need the keyboard–and then my web browser works much like my VI editor which provides a user interface consistency that is very nice. But, Iceweasel/Firefox is a resource hog! Fortunately, there are several configuration changes that can greatly improve the usability of Iceweasel/Firefox on a resource-limited device like the RPI or RPI-2. I use the modifications described here. Also, I add the following line to my .profile:

export set MOZ_DISABLE_IMAGE_OPTIMIZE=1

Before these changes, Iceweasel would slow down the RPI-2 the more it was used until the RPI-2 was virtually unresponsive. With the changes the RPI-2 works great with Iceweasel. I do try to limit the number of open tabs in Iceweasel, but I currently have 25 tabs, along with about a dozen terminal windows, my QT Weather program, XTide and can even use LibreOffice and have the interface feel responsive! All in all, a very nice computer experience.

The Debian Jessie install went great and the only real hitch for me is not limited to the Raspberry Pi. Jessie uses the new SystemD and that breaks a lot of UDev scripts I wrote to automatically start services such as the Weather data logger when the Airmar USB cord is plugged in, and the GPS position and time servers when the USB puck is plugged in, and the Internet gateway when the Palm is tethered. Jessie has packaged some automatic scripts which work with common new devices, but not our GPS, Palm, or Airmar. For the Airmar, it turns out that my automatic testing and recovery scripts will get the data logging started. The problems with my other old devices may not affect those with newer devices, but my solution for them will be covered in the next post along with some new stuff.

Google Analytics Alternative