Saturday, February 28, 2015

Although RadioShack is significantly more expensive than buying parts online, they have saved my bacon more than once on various weekend electronic projects, when shipping time would have ruined my weekend.

Sunday, February 8, 2015

I had an old Xserve server laying around and wanted to put it to good use. My current Plex server is going away, so this will serve as the replacement. The Xserve line has long since been discontinued by apple and is no longer supported. What is the best solution to bring any old server back to life? Install Linux on it, of course!

Install to USB Drive

One issue I ran into is I could not find a Linux driver for the Xserve RAID controller, so I ended up installing Linux onto a attached USB drive. I had found articles online that talked about swapping out the back-plane with a standard SATA controller, but that is more effort than I wanted to put in for this project.

To keep the server from booting from the local hard drives, I pulled them slightly out.

The server only has USB 2.0 ports (could always install a USB 3.0 controller into one of the two free PCIe slots), but as USB 3.0 drives are pretty much all you can find now I used a USB 3.0 flash drive. I would recommend a SanDisk drive, but I am completely biased. :-)

Installing Ubuntu

To boot from the install CD, hold down the "Alt" key as the system boots.

You will see a white screen ("White Screen of WaitingTM"), and it won't seem like anything is happening for a long time (60+ seconds), but continue to hold down the alt key until the boot menu comes up.

Select the CD labeled "EFI Boot" (Xserver only supports UEFI supported installs), and the installer will continue to load.

After what seems like a really long time, an error will appear. Ignore it and wait some more time, and the Ubuntu installer GRUB menu will appear.

Finally the "purple" Ubuntu installer will appear. The default options on the installer will be sufficient, but you can make any desired changes as well.

Luckily the Intel 82574L Gigabit Network is well supported by Linux. The two connections are labeled on the back of the server.

Eventually you will be asked to choose a storage location for the install. If your USB drive has existing partitions, you will get a warning about unmounting partitions on /dev/sda, do so.

For the partitioning scheme, I am not a fan of LVM (had to many bad experiences trying to recover from issues), so I chose the "Guided - use entire disk" option.

Eventually the installation will complete, and the system will reboot.

Expect another 60 seconds of waiting at the "White Screen of Waiting", before the system actually boots and you get your expected login prompt.

Saturday, February 7, 2015

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Usage

Dependencies

Before you can use dilbert-rss, you will need to install two Python dependencies: BeautifulSoup and PyRSS2Gen

pip install BeautifulSoup PyRSS2Gen

BeautifulSoup and PyRss2Gen

On this topic, learning about the BeautifulSoup and PyRSS2Gen Python libraries were a benefit of using the dilbert-rss project. Both libraries can be used for a number of other useful projects. BeautifulSoup will parse an HTML page turning it into a usable Python object and PyRSS2Gen can be used to easily generate RSS feeds.

Oeey.com Dilbert Feed

Open the URL within an RSS viewer. If you don't have one handy, use Firefox to see the feed as a "Live Bookmarks" view. The content will be rendered. Most other browsers will just show the XML content.

With the above I created the following cronjob:

0 18 * * * python /usr/local/bin/dilbert.py /www/dilbert/dilbert.xml

And the matching Apache configuration, with a default DirectoryIndex pointing to the XML feed:

Friday, January 2, 2015

The Kankun "Small K" (KK-SP3) Smart Wifi Plug Socket is an inexpensive device (~$20) that lets you switch an outlet on and off over Wi-Fi.

Smart Plug is a Controllable OpenWRT Linux BusyBox

Designed to be controlled by a smart phone, some engineering minds posted on Hackaday a way to control the device from any web browser or SSH client. It turns out the Smart Plug is running a version of OpenWRT, which is basically a minimal BusyBox Linux environment (BusyBox: The Swiss Army Knife of Embedded Linux). It also has SSH access turned on by default, and was just a matter of determining the default password (admin, 1234, or p9z34c). Once you have SSH access you can either control the relay directly, or add a CGI script to control from a web browser.

AliExpress

There are a lot of options for purchase, just make sure you pick the US connector version (example), or you will need to buy an adapter (a mistake I made with the first one I ordered).

Smart Plug - US Connector Version

If you do get the wrong one, the front "female" receptacle connector was a universal connector, but the back "male" plug connector is the problem and you have to buy an adapter, so your device will end up looking like this:

Smart Plug - Chinese Connectors with US adapter

I should mention that one plug took 2 weeks to arrive and another took just shy of a full month. Different sellers, but both coming from China.

Factory Reset

As we make changes to the wireless settings, we can recover to the original factory settings by pressing and holding an almost-invisible white button on the surface of the plug for 4 seconds.

Configuring to SmartPlug Wireless Network

To get access and control to the Smart Plug, we first need to configure it.

Out of the box the Smart Plug is set as a Wireless Access Point, with an SSID of OK_SP3 (no password). To be useful, we will need to connect to this temporary access point and configure the device to connect to our home wireless network.

To configure the wireless, we can either:

1. Connect to the SSH service (default ip: 192.168.10.253) and modify the wireless files manually

or

2. We can use the Smart Phone Android/iOS app to configure the Smart Plug

I think the initial setup is easier with the app, so...

Configuring to SmartPlug Wireless Network - Android App Method

1. Download and install the Android Kankun "SmartPlug" app. (I assume the app on iOS is the same, but I haven't verified this)

3. Start the SmartPlug app and click the "Config" button. Note: the "Device" page will be empty, unless you have already configured devices.

4. This is where we will change the Smart Plug's wireless network settings to our home network. Change the "Wifi" item to your home SSID (sorry no discovery option here). Change the Password to your home's wireless password. Ignore the "Encryption" option. Finally click the Configuring button to save the changes.

5. The Smart Plug should now be on your home's wireless network, and your Smart Phone will have been auto disconnected from the OK_SP3 network and also back on your home network. Check the status of the blue LED on the Smart Plug. If the LED is off, everything is good. If the light is blinking, it was unable to connect to your home wireless network.

6. Now check the "Device" list. Your Smart Plug should now be in the device list. Select the device.

Note: The device's Ethernet address (MAC) is also listed. Take note of the MAC, as you will want to check your DHCP server's logs to determine the IP address of your Smart Plug.

7. From here, we can quickly test the Smart Plug. We will be presented with a visual "on/off" button. Click the "on/off" a few times until you are satisfied. You will hear the relay switch on and off, or if you have something plugged into the Smart Plug, you will see it turn on and off.

7. Check your home's DHCP logs to find out what the new IP address of your Smart Plug is. Next we will connect to the Smart Plug over SSH.