tag:blogger.com,1999:blog-34418810717179603292024-03-05T14:54:09.459-08:00TeknynjaAn uneasy mix of technology, science, religion and politics.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-3441881071717960329.post-6781926001605508922016-06-09T08:01:00.000-07:002016-06-09T11:04:41.676-07:00Using the SN75176A in NeoPixel & Other ApplicationsI have received many great comments and emails regarding my post on <a href="http://www.teknynja.com/2014/02/driving-ws2812neopixels-rgb-leds-over.html" target="_blank">Driving WS2812/NeoPixels RGB LEDS over CAT5 Ethernet Cable</a>, and it is in fact one of my most popular posts. A few people have requested that I go into a bit more detail on how the <a href="http://www.ti.com/lit/ds/symlink/sn75176a.pdf" target="_blank">SN75176A</a> chip is used in this application, so in this post I will explain a bit more detail about using this device.<br/>
<br/>
The SN75176A is a Differential Bus Transceiver, which means that it is used to convert back and forth between a normal "single-ended" signal on one side and a "differential signal" on the other. There is a good <a href="https://en.wikipedia.org/wiki/Differential_signaling" target="_blank">Wikipedia article</a> that goes into great detail on the benefits of differential signaling, but the quick overview is that it provides lower signal degradation and better noise immunity than single-ended signaling, allowing us to send our <a href="http://learn.adafruit.com/adafruit-neopixel-uberguide/overview" target="_blank">NeoPixel</a> data over much longer distances.<br/>
<br/>
There seems to be a bit of confusion with some readers regarding the SN75176A's ability to be used for both to sending and receiving differential signals, so let's see if we can clear things up a bit. This device contains both a single-ended to differential "transmitter" and a differential to single-ended "receiver". Depending on how a couple of control lines on the device are set, we can enable one or both components as needed. The following diagram shows how things are hooked up inside the chip:<br/>
<br/>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxfDK8bKhSm-6wuqNixybkyRH-6-1bR52ItytOkphp1wwGY-EBs1WlNFaXlqj-LGpNTSn3mEya9eQwcYZtbxecXhBxe3T0HM69UivOfPC8lxvgdRGXozmx49a6YT3JQiKY90_zdApM-84/s1600/sn75176.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxfDK8bKhSm-6wuqNixybkyRH-6-1bR52ItytOkphp1wwGY-EBs1WlNFaXlqj-LGpNTSn3mEya9eQwcYZtbxecXhBxe3T0HM69UivOfPC8lxvgdRGXozmx49a6YT3JQiKY90_zdApM-84/s1600/sn75176.png" /></a></div><br/>
<br/>
The "A" and "B" pins are the differential signal lines which are connected to the long run of cable between devices. The "D" pin is used to send data on the differential pins and the "R" pin has the received data from the differential lines. Finally, the "<span style="text-decoration: overline;">RE</span>" and "DE" pins are inputs to the device that enable the receiver and/or transmitter, respectively. Notice the "bar" over the <span style="text-decoration: overline;">RE</span>, indicating that it is "active-low", meaning the a low input enables the receiver and a high input disables it.<br/>
<br/>
If you want to configure the device as a <b>transmitter</b>, you would connect both the <span style="text-decoration: overline;">RE</span> and DE pins to VCC – this disables the receiver and enables the transmitter so that any data applied to the D line is sent to the differential outputs on A and B. Now if you want to configure the device as a <b>receiver</b>, you would connect the <span style="text-decoration: overline;">RE</span> and DE pins to ground, disabling the transmitter and enabling the receiver so that data received on the A and B pins is converted to a single-ended signal on the R pin.<br/>
<br/>
You may be wondering what happens if the <span style="text-decoration: overline;">RE</span> and DE signals are not tied to the same high/low levels. If you connect the <span style="text-decoration: overline;">RE</span> low and the DE high, both the transmitter and receiver are enabled, and any data sent out using the D pin is "looped-back" or echoed on the "R" pin. This can be useful in some configurations to confirm data being sent or to detect collisions with other transmitters on the differential lines. The other configuration is when the <span style="text-decoration: overline;">RE</span> pin is high and the DE pin is low. In this configuration, both the transmitter and receiver are disabled, effectively preventing data from being sent or received on the differential pins.<br/>
<br/>
Now it's not needed in my NeoPixel application because data is always flowing in the same direction, but if you needed to both send and receive data over the differential pins, you could connect the <span style="text-decoration: overline;">RE</span> and DE lines to your microcontroller, allowing it to select the data direction, either transmitting or receiving as needed. Notice that even though you can enable both the transmitter and receiver at the same time, you are not able to send and receive data between two such devices at the same time, as only one device at a time can be in transmit mode, otherwise the data gets corrupted (just like two or more people talking at the same time makes it difficult to understand what anyone is saying).<br/>
<br/>
Hopefully this explanation will help out some of you that have been looking to tweak or modify the circuit in my long-distance NeoPixel post, or just give you a better understanding of how the design works, and maybe inspire you to try applying this idea in your own design. Also, thanks to Leo B. for prompting me to finally get around to writing this post!teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com5tag:blogger.com,1999:blog-3441881071717960329.post-23562840050264420712015-05-23T12:03:00.000-07:002015-05-23T16:15:51.904-07:00Giving VirtualBox Guests Access to the Internet Without Exposing the Host's NetworkI have a virtual machine running under <a href="https://www.virtualbox.org/" target="_blank">VirtualBox</a> that needs to be able to get updates from the Internet. Using VirtualBox's normal network interface methods (<a href="https://www.virtualbox.org/manual/ch06.html" target="_blank">NAT or Bridging</a>), the guest machines not only have access to the Internet, but also to all the interfaces on the host machine and their networks! Googling around for a solution didn't turn up anything useful, and VirtualBox seems reluctant to provide a Internet only option either.
<br /> <br />
After trying for about a day to mess with various <span style="font-family:monospace">iptables</span> solutions and coming up empty handed, I decided to try a different approach to the problem. My solution is to create another “router” virtual machine and connect the main virtual machine through it to the rest of the network. All network traffic for the guest would go through an “Internal Network” connection to the router VM, and then the router would provide NAT, DHCP, and DNS services for the guests. This solution also has the benefit of providing multiple guest VMs with Internet-Only connections.
<br /> <br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguSuvT_Y0kH3CC9ODnF3oRKhM7xn0IGvXv1szkbbL7HVBb9LRMsvSvRqQaQFVLCHvZWorDDOoTJW3CHvcDnbY_NCZ4wpFXAC0GKbk5rbASXICUjAegk__ZVREZRJ5ylCZEzPOIkQfc54c/s1600/vbxrouter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguSuvT_Y0kH3CC9ODnF3oRKhM7xn0IGvXv1szkbbL7HVBb9LRMsvSvRqQaQFVLCHvZWorDDOoTJW3CHvcDnbY_NCZ4wpFXAC0GKbk5rbASXICUjAegk__ZVREZRJ5ylCZEzPOIkQfc54c/s640/vbxrouter.png" /></a></div>
The router VM is very lightweight and doesn't require too much in the way of resources. I used Ubuntu Server 14.04.2 (32 bit), creating a virtual machine with 512MB of RAM and 10GB hard drive. (You could probably get away with less RAM and drive space, but I haven't played with trimming it down yet.) The secret sauce is in how the network adapters for these machine are configured. For the guest machine, you need to set up a single network adapter on an “Internal Network” (named vbx-router in this case). You can do this from VirtualBox GUI or the command line as follows:<hr /><pre>vboxmanage modifyvm "guest-vm-name" --nic1 intnet --intnet1 vbx-router</pre><hr />
The router VM will have two adapters, the first one bridged to the host's main network interface (typically <span style="font-family:monospace">eth0</span> on Linux hosts), and the second one using the same internal network we defined for the guest VM. The command line for this would look something like:<hr /><pre>vboxmanage modifyvm "router-vm-name" --nic1 bridged --bridgeadapter1 eth0
vboxmanage modifyvm "router-vm-name" --nic2 intnet --intnet2 vbx-router</pre><hr />
After installing the Ubuntu 14.04.2 x32 Server (you can use your favorite flavor of non-GUI Linux, your mileage may vary), make sure it is up-to-date (<span style="font-family:monospace">sudo apt-get update</span> and <span style="font-family:monospace">sudo apt-get upgrade</span> on Ubuntu/Debian). It's also probably a good idea to install OpenSSH Server, especially if your virtual machines are headless like mine. Next, it's time to install and configure the routing services. These instructions are based off a <i>really</i> useful blog post over at <a href="http://blog.noviantech.com/2010/12/22/debian-router-gateway-in-15-minutes/" target=”_blank”>The Novian Blog</a>.
<br /> <br />
<h1>Configure the Interfaces</h1>
Edit the <span style="font-family:monospace">/etc/network/interfaces</span> file so it looks similar to this:<pre><hr />
# The loopback network interface
auto lo
iface lo inet loopback
# The WAN (bridged) interface
auto eth0
iface eth0 inet dhcp
# The LAN (internal) interface
auto eth1
iface eth1 inet static
address 10.0.2.1
netmask 255.255.255.0
network 10.0.2.0
broadcast 10.0.2.255
</pre><hr />You can set up the WAN interface with a static IP if you'd like, but the LAN interface should be static so that guest VMs can always find it. The addresses for the LAN interface were chosen to be similar to the default NAT configuration provided by VirtualBox.
<br /> <br />
<h1>Install and configure DNSmasq</h1>
DNSmasq is a simple to setup DHCP server and DNS forwarder, install it with the command:<hr /><pre>
sudo apt-get install dnsmasq</pre><hr />
Then add the following to the bottom of <span style="font-family:monospace">/etc/dnsmasq.conf</span>:<hr /><pre>
interface=eth1
domain=home.teknynja.com
dhcp-range=10.0.2.10,10.0.2.99,12h
</pre><hr />
Of course you will want to change the domain to something suitable for your network.
<br /> <br />
<h1>Enable IP Forwarding</h1>
Un-comment the following line in <span style="font-family:monospace">/etc/sysctl.conf</span>:<hr /><pre>
net.ipv4.ip_forward=1</pre><hr />
<h1>Configure iptables</h1>
Create the file <span style="font-family:monospace">/etc/iptables.rules</span>:<hr /><pre>
*nat
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
*filter
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -j DROP
COMMIT
*raw
-A PREROUTING -i eth1 -d 192.168.0.0/16 -j DROP
COMMIT
</pre><hr />
This configuration does the following:
<ul>
<li>Sets up NAT outbound on eth0</li>
<li>Allows all inbound localhost traffic</li>
<li>Allows inbound established connections</li>
<li>Allows SSH connections from WAN to our router</li>
<li>Drops anything else coming in from eth0</li>
<li>Drop packets coming from eth1 destined for host's local network(s)</li>
</ul>
Activate the rules (as a quick sanity check before rebooting!):<hr /><pre>sudo iptables-restore < /etc/iptables.rules</pre><hr />
Now try to ssh into the router and verify that you can connect. Once you verify that the rules are working, configure iptable rules to load on network startup. Add the following to <span style="font-family:monospace">/etc/network/interfaces</span> after the line iface lo inet loopback:<hr /><pre>
pre-up iptables-restore < /etc/iptables.rules
</pre><hr />
<br /> <br />
<h1>Profit!</h1>
Reboot your router virtual machine to make sure it loads all your new configuration. Next double check your VirtualBox network configuration on the guest VM then go ahead start it. Check to make sure the guest picks up an IP address from the router VM, and proceed to test your guest's network. You should now be able to access the Internet, but be unable to access anything on your local network (including the host!)
<br /> <br />
Hopefully this will help you create an isolated guest with Internet access in your setup. I've been needing something like this for a while, and now that I've figured it out I felt like I needed to share. If you see anything wrong with this setup, or know how to make it more secure, please feel free to leave a comment.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-637322396394549012015-05-17T15:19:00.000-07:002015-05-18T14:10:23.195-07:00How to Remove the GUI from your Raspberry Pi<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh-iSlVIOFdEC6YXA3CgboxV2Najj_W1qw7A15G08ZOdfJxWWkRVWf29sASe_nRj01xW4r5Ju8Xadi7TQIA02Hg2FFG5bAqvl7EHb9RYLERyl12-nG80x9R5Oyw5P7HL5l6GQEjfnjNX8/s1600/raspigui.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh-iSlVIOFdEC6YXA3CgboxV2Najj_W1qw7A15G08ZOdfJxWWkRVWf29sASe_nRj01xW4r5Ju8Xadi7TQIA02Hg2FFG5bAqvl7EHb9RYLERyl12-nG80x9R5Oyw5P7HL5l6GQEjfnjNX8/s320/raspigui.jpg" /></a></div>
I was getting prepared to start another headless Raspberry Pi project (an IoT gateway) and reached for my old standby command line operating system, <a href="http://minibianpi.wordpress.com/" target="_blank">Minibian</a>. I grabbed the latest version, copied the image to the memory card, and <a href="http://www.teknynja.com/2014/03/raspberry-piminibian-adjusting-locale.html" target="_blank">started setting things up</a>. I ran into a problem when I tried to get the RaLink RT5370-based USB WiFi Adapter working - the kernel seemed to recognize the device, but I just couldn't get it working. After digging through the system logs it became apparent the firmware required by the adapter was not present in Minibian (Only later did I realize that I may have just needed to install a package to get the required firmware). After trying to get the WiFi adapter to work for a few hours, I gave up and switched to <a href="https://www.raspbian.org/" target="_blank">Raspbian</a>. I was then able to get everything working (including the WiFi adapter), but was left with a GUI and it's associated bloat that I didn't really need, so I set about seeing what packages could be removed and still leave me with a fully functioning command-line based system.<br />
<br />
Initially, I just did a search on the web and found a few different posts and conversations that dealt with removing the GUI and combined them to get things slimmed down quit a bit. After that, I started listing the installed packages and removing the ones that looked like they would not be needed. (It was at this point I noticed the <span style="font-family:monospace">firmware-ralink</span> package that I could have probably installed on Minibian to get the WiFi adapter working there – maybe next time).<br />
<br />
My first stop was a conversation on <a href="http://raspberrypi.stackexchange.com/questions/4745/how-to-uninstall-x-server-and-desktop-manager-when-running-as-headless-server" target="_blank">raspberrypi.stackexchange.com</a> where it was suggested that you could rip out the X window system by the roots by simply removing ''libx11-.*''. That <i>did</i> remove a lot of packages from the system! Other blog posts like this one at <a href="http://www.richardsramblings.com/2013/02/minimalist-raspberry-pi-server-image/" target="_blank">Richard's Ramblings</a> added to the list of packages to remove.<br />
<br />
Finally, I used the <span style="font-family:monospace">dpkg --get-selections | grep -v deinstall</span> command (thanks <a href="http://askubuntu.com/questions/17823/how-to-list-all-installed-packages" target="_blank">askubunut.com!</a>) to list all the remaining packages on the Raspberry Pi and removed all the ones that look like I could do without. There were a few times when I removed too much and had to re-install a package or two, but eventually boiled it down to the following commands to convert a normal GUI Raspbian installation to a lean command-line only version (Be sure you don't have any important files or configuration on your system before doing this, and don't blame me if your mission critical Raspberry Pi application gets lost in the process!).
<br />
<em><i>A word of caution:</i></em> One of the uninstalled packages took the <span style="font-family:monospace">/etc/network/interfaces</span> file with it, so before stripping all these packages, you should make a copy somewhere else on the device and then restore it before rebooting your system, or you will have no networking available after rebooting!<br />
<br />
<pre>
sudo apt-get remove --auto-remove --purge libx11-.*
sudo apt-get remove --purge raspberrypi-artwork triggerhappy shared-mime-info gcc-4\.[0-7].*
sudo apt-get remove --purge gdb gdbserver penguinspuzzle samba-common omxplayer
sudo apt-get remove --purge alsa-.* build-essential gstreamer1.0-.* lxde-icon-theme
sudo apt-get remove --purge desktop-file-utils gnome-themes-standard-data menu menu-xdg
sudo apt-get autoremove
</pre>
After all was said and done, I was able to reduce the size of the file system from 2.5GB down to just 800MB. Along with the size savings, there are also fewer programs running and fewer packages that need updating. Not to mention having less software on the system creates a smaller attack area for hackers to leverage.<br />
<br />
So if you find that you need to remove the GUI from your Pi, hopefully this information will help you with your cleaning task. And of course, if you need something even smaller, there's always Minibian for a really stripped-down configuration.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-32285225421527643142014-03-01T07:59:00.000-08:002014-08-08T08:18:10.690-07:00Raspberry Pi+Minibian: Adjusting the Locale and Time ZoneI really have enjoyed playing with the Raspberry Pi, but many of my projects don't require a GUI (for example OpenVPN and web servers). For projects like these, I usually install <a href="http://minibianpi.wordpress.com/" target="_blank">Minibian</a> which is a great, small version of Raspbian with all the GUI goodness removed. It is a perfect starting point for my headless projects, except that out of the box, it comes setup with locale and timezones configured for Great Britian. This causes some strange characters to come up when typing on the keyboard, and the clock doesn't reflect my local time zone.<br/><br/>
Fortunately, these issues are easy to address, and I will show you the steps I take to configure my system for my locale and time zone (us-EN & America/Los_Angeles). Just use your locale and time zone in the steps below to configure your system as desired.<br/><br/>
<ol>
<li style="margin-bottom:10px;">Install Minibian on your SD card following the <a href="http://minibianpi.wordpress.com/setup" target="_blank">provided instructions</a>. Insert the card into your Raspberry Pi, power it up, and log in. (The default username/password is root/raspberry). You may also want to change the name of your system from the default "raspberrypi" by editing the <code>/etc/hostname</code> file.</li>
<li style="margin-bottom:10px;">Change the keyboard locale. Run the following command:<pre style="border:1px dotted; padding:5px;">dpkg-reconfigure keyboard-configuration</pre>then
<ul>
<li>Set your "Keyboard model" to "Generic 105-key (Intl) PC".</li>
<li>Set the "Country of origin for the keyboard" and "Keyboard layout" both to "English (US).</li>
<li>Next for the "Key to function as AltGr" choose "The default for the keyboard layout".</li>
<li>For "Compose key" I chose "No compose key".</li>
<li>Finally, choose "No" for "Use Control+Alt+Backspace to terminate the X server".</li>
</ul>Once the command completes, reboot your Raspberry Pi to pickup the new keyboard layout.</li>
<li style="margin-bottom:10px;">Now change the system local. Run the command<pre style="border:1px dotted; padding:5px;">dpkg-reconfigure locales</pre>and de-select "en_GB.UTF-8 UTF-8" and select "en_US.UTF-8 UTF-8", then set the default locale to "en_US.UTF-8" on the next screen.</li>
<li style="margin-bottom:10px;">Edit the <code>/etc/default/locale</code> file and change/add the following lines:<pre style="border:1px dotted; padding:5px;">LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANGUAGE=en_US.UTF-8</pre>then log out and back in again to pick up the new locale.</li>
<li style="margin-bottom:10px;">Finally, run <pre style="border:1px dotted; padding:5px;">dpkg-reconfigure tzdata</pre>and select "America", then "Los_Angeles" to set the local time zone for your system.</li>
<li style="margin-bottom:10px;">Now that your system understands you a little better, it's probably a good time to update your system using<pre style="border:1px dotted; padding:5px;">apt-get update
apt-get upgrade</pre>then reboot your system again.</li>
</ol>
<br/><h2>Optional Tweaks</h2><br/>
If you'd like to make your system a little more secure, you can enable sudo and disable the root login with the following steps:
<ol>
<li style="margin-bottom:10px;">Install sudo:<pre style="border:1px dotted; padding:5px;">apt-get install sudo</pre></li>
<li style="margin-bottom:10px;">Create your new user. For example, to add the user "bob" run the command<pre style="border:1px dotted; padding:5px;">adduser bob</pre>and follow the prompts.
<li style="margin-bottom:10px;">Add your new user to the sudoer's list. Run <code>visudo</code> then add the following line (changing the username to the user you just added) after the <code>root ALL=(ALL:ALL) ALL</code> line:<pre style="border:1px dotted; padding:5px;">bob ALL=(ALL:ALL) ALL</pre></li>
<li style="margin-bottom:10px;">Now disable the root user with the command<pre style="border:1px dotted; padding:5px;">passwd -l root</pre>(note that is a lower-case L, not a one)</li>
<li style="margin-bottom:10px;">Now log out of your root session and log in as your new user.</li>
</ol>
Finally, it's a good idea to change the SSH server keys because the ones that come with the image file make it easy to impersonate your system (since everybody has access to those keys):<pre style="border:1px dotted; padding:5px;">sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server</pre><br/>
Now you should have a headless Raspberry Pi system that you can use for various server projects that is customized for your locale and timezone! If you have any questions or comments on this procedure, please feel free to leave a comment.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com2tag:blogger.com,1999:blog-3441881071717960329.post-14774581948559420152014-02-08T19:32:00.000-08:002016-06-09T08:09:54.167-07:00Driving WS2812/NeoPixels RGB LEDS over CAT5 Ethernet CableI was recently working on a project using <a href="http://learn.adafruit.com/adafruit-neopixel-uberguide/overview" target="_blank">Adafruit NeoPixels</a> (WS2812) RGB LED strips where a single controller was supposed to drive five strings of 30 pixels that were physically located several feet apart. I knew right away that there was going to be a couple of problems trying to drive the strings over more than 20 feet of cable. First off there is the voltage drop issue - these strings can draw several amps, and could easily drop around 1 volt or more, depending on the cabling and connectors. The other issue is the integrity of the data signal being sent to the string. The pixels are very timing sensitive, and noise or ringing caused by a long wire run could easily introduce errors, or even result in a completely non-functioning string. This last issue was made even worse by my choice of controller, the <a href="http://www.pjrc.com/store/teensy3.html" target="_blank">Teensy 3.0</a> which is a 3.3V part, while the pixels require a 5V input. (By the way, the Teensy 3.0/3.1 + the <a href="http://www.pjrc.com/teensy/td_libs_OctoWS2811.html" target="_blank">OctoWS2811 library</a> is an awesome choice for driving dozen to hundreds of RGB pixels!)
<p>While it seems that many people have successfully driven NeoPixel/WS2812 strings directly from the Teensy using a small resister to reduce ringing, I was pretty sure that wouldn't work over any appreciable distance. It also appears that the newer WS2812B pixels won't work at all with just a 3.3V signal. It didn't take me too long to come up with the solution for the data issue - RS-422/485 drivers and receivers! Since the pixel data is really just serial data, I figured using RS-485 balanced transmission lines to send the data would work perfectly. The data signal is well within the bandwidth these chips are capable of, and as a bonus, the <a href="http://www.ti.com/lit/ds/slls039b/slls039b.pdf" target="_blank">SN75174 Quad Differential Line Driver</a> IC inputs will easily accept the 3.3V outputs from the controller! On the receiving end, I went with <a href="http://www.ti.com/lit/ds/slls100a/slls100a.pdf" target="_blank">SN75176 Differential Bus Transciever</a> chips because I had several of those on hand in my parts bin. I just needed the receiver part of the chip, and it was quite easy to disable the transmitter portion.</p>
<p>Next up was the power-drop issue. Right about the same time I was dealing with this I discovered these <a href="http://www.amazon.com/gp/product/B008BHAOQO" target="_blank">LM2596 DC-DC Buck Converters</a> on Amazon - they were perfect! Their low cost, small size, high efficiency and wide input voltage range made them a snap to integrate into my project. (Just make sure you check/adjust the output voltage on these before you use them!). Now I could feed 12V into my long cables feeding the remote strings, and use these power supplies on the receiving side to drop it down to the needed 5V. Since I was only driving about 30 pixels on each line, the 3A output was more than enough to drive each string.</p>
<p>With all the pieces in place, it was time to test out my ideas. First, I wanted to test out driving the data signal using the differential converts, so I wired up a transmitter and receiver on each end of 100 feet of CAT5 cable, connected up my controller to the transmitter and 5 meters (150 pixels) on the receiving end. For now, I just connected up a beefy 5V/10A power supply at the receiving end to power the string. After connecting everything up, it worked like a charm! Every pixel was responding as though it was sitting right next to the controller.<p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_S2NPzMfdHSCjzifqBODO6JEGgifsCAAO4QyS9xyGDOA8TKdDA3L12PLmNOTyDi37UMqS-CvnyO_s2MbHLKrAlo53lR2ZLbb657FPidMH64XEOWmGAU7UfeunmO4eXt-3liipcbcYXWo/s1600/cable-test.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_S2NPzMfdHSCjzifqBODO6JEGgifsCAAO4QyS9xyGDOA8TKdDA3L12PLmNOTyDi37UMqS-CvnyO_s2MbHLKrAlo53lR2ZLbb657FPidMH64XEOWmGAU7UfeunmO4eXt-3liipcbcYXWo/s400/cable-test.png" /></a></div>
<p>Next up, I cut the string up into 5 lengths of 30 pixels each, and wired them up as shown below, using the differential transmitters/receivers and the DC/DC converters (again making sure they were adjusted to provide 5V output!), powering everything with a large 12V power supply. Everything worked as expected, the pixels were changing colors as commanded, with no color shift or dimming caused by voltage drops.</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgg0KqgnhRMAKiDdmTvDrwPu3Cxby1hZEI0kCRSU8Ig2uXHeOy_Fsijs_obacw0SL0t-GfRdsbGRstEWZKei4VJLgZj8DKh6pAPzCsqSu9qoEVTgZQi1OS-N9YvYo-53M1FW0fb_xwN3A/s1600/rgb-cat5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgg0KqgnhRMAKiDdmTvDrwPu3Cxby1hZEI0kCRSU8Ig2uXHeOy_Fsijs_obacw0SL0t-GfRdsbGRstEWZKei4VJLgZj8DKh6pAPzCsqSu9qoEVTgZQi1OS-N9YvYo-53M1FW0fb_xwN3A/s640/rgb-cat5.png" /></a></div>
<p>Notice that I am calling out the color codes for the CAT5 wiring - it is important that at least the data wires are on twisted pair of conductors (blue/blue-white in this case). I also like to have the power wires paired as well, with all the +V connections on the solid wires and the -V connections on the white-striped wires, which helps with noise immunity on the power lines. In my project, I used 4 position connectors and just tied all the +V wires together on one terminal and all the -V wires on another (with the data on the remaining two terminals). Using all the extra wires in the cable for power helps reduce the resistance, and thus the power drop on the cables.</p>
<p>In the end, my project worked well, with the strips connected via 15 - 25 foot lengths of CAT5 cable all connecting back to my central controller. If you have a project where you need to have several remote RGB pixel strips all controlled from a single controller, hopefully by using this approach you can make your pixels work just like they were connected directly to the controller. As usual, your feedback is always appreciated, and if you have any questions please feel free to leave a comment.</p>
<p><b>UPDATE: </b>I've just added a new <a href="http://www.teknynja.com/2016/06/using-sn75176a-in-neopixel-other.html" target="_blank">post</a> that goes into more detail about using the SN75176A chip in this design, for those of you who have asked about variations of the above circuit.</p>teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com66tag:blogger.com,1999:blog-3441881071717960329.post-60288220149613439542013-06-09T14:05:00.000-07:002013-08-30T07:04:42.099-07:00Making kvm/qemu/libvirt Play Nice with PulseAudio on a Headless Ubuntu 12.04 Server
I've been running over a dozen virtual machines on my headless server for almost two years now, and for all that time I've always missed being able to hear the audio from those machines. I would occasionally try to figure out how to make audio work over VNC, but never could find a solution on the Internet. Finally last week I decided to at least get part-way there by getting the audio to play on the server's speaker port.
The first step was pretty easy – installing <a href="http://www.pulseaudio.org/" target="_blank">PulseAudio</a> on the server:
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">sudo apt-get install pulseaudio
</pre></div><br/>
Now from what I could gather on the Internet, it seems like I needed to run PulseAudio in system mode, despite all the warnings that it should probably not be run that way. I figured that since I don't usually have any logged in users on the system, it would just be better to have it running all the time. In order to do that, I edited the <tt>/etc/default/pulseaudio</tt> file, and changed the following settings to:
<br/><br/>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">PULSEAUDIO_SYSTEM_START=1
DISALLOW_MODULE_LOADING=1
</pre></div><br/>
Then I added my user and the <tt>libvirt-qemu</tt> user to the <tt>pulse-access</tt> group:
<br/><br/>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">sudo adduser myuser pulse-access
sudo adduser libvirt-qemu pulse-access
</pre></div><br/>
You'll need to log out and back in again for the new group to be picked up on your shell. Finally, I started the PulseAudio service:
<br/><br/>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">sudo service pulseaudio start
</pre></div><br/>
Now a quick test to make sure the sound subsystem was working:
<br/><br/>
<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">paplay test-sound.wav
</pre></div><br/>
In my case, I could barely hear the sound playing, so I did a <tt>pactl list sinks</tt> to figure out which sink was being used, then issued <div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">pactl set-sink-volume 1 100%
pactl set-sink-mute 1 0
</pre></div> to set the volume level of sink 1 to the maximum and unmute it. Now I could hear the sound just fine!
<br/><br/>
The next hurdle was to get the sound from the virtual machines to play through PulseAudio. It turns out there are quite a few obstacles to achieving that goal. First off, libvirt automatically disables audio if you are using a VNC client! It turns out to be fairly simple to fix that though, simply edit <tt>/etc/libvirt/qemu.conf</tt> and change the following setting to:
<br/><br/>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">vnc_allow_host_audio = 1
</pre></div><br/>
After restarting the libvirt daemon using <tt>sudo service libvirt-bin restart</tt> I could see in the syslog file that libvirt/kvm was trying to use the PulseAudio subsytem, but <a href="http://wiki.apparmor.net/index.php/Main_Page/" target="_blank">apparmor</a> was blocking access to several key files/directories. I never did find a working answer by Googling, but I worked out the following settings for the <tt>/etc/apparmor.d/abstractions/libvirt-qemu</tt> file. I changed <tt>/{dev,run}/shm r,</tt> to <tt>/{dev,run}/shm rw,</tt> then added <tt>/{dev,run}/shm/pulse* rw,</tt> right after that line. Finally I added <tt>/var/lib/libvirt/.pulse-cookie rwk,</tt> (<i>note the trailing commas on those lines!</i>) then told apparmor to reload the configuration:
<br/><br/>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">sudo invoke-rc.d apparmor reload
</pre></div><br/>
I fired off a Windows XP x32 guest, and was able to hear sound, but it was very distorted and choppy. The solution to that was to change the sound hardware in the virtual machine's configuration file from <tt><sound model='ac97'></tt> to <tt><sound model='es1370'></tt>. After that, I was getting perfect sound from my virtual machine!
<br/><br/>
Now for a few caveats – it seems that changing any of the PulseAudio configuration or restarting the service while the virtual machine is running can cause problems like the sound no longer working, all the way to the virtual machine's OS hanging up trying to play sounds. So once you started your virtual machine, leave things alone! I have also been working on trying to forward the sound over the network to my workstation, but so far I am having mixed results with that. Hopefully I'll have another post soon describing how to make that work.
<br/><br/>
And here is the usual warning that goes with tweaking your system like this: These instructions worked for me, but your mileage may vary. Also, I won't be responsible if any of this causes your machine to stop working or catch on fire – but this stuff should be pretty straight-forward and not cause any serious issues that can't be reversed. Hopefully my adventure will help you to enjoy hearing from your virtual machines. If you have any questions or corrections, please feel free to post them in the comments.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com1tag:blogger.com,1999:blog-3441881071717960329.post-82259244693215825682013-05-27T13:58:00.000-07:002013-05-27T14:02:02.112-07:00Time-Lapse Video Capture From Network Cameras (Linux)I have several network cameras watching the outside of my home, monitored by <a href="http://www.zoneminder.com/" target="_blank">ZoneMinder</a>. I have it set up so that when there is motion detected, it will record for several seconds and send me an email with stills of the incident. While this is nice and gives me a little peace-of-mind, I've always thought about having it record continuously. While it is easy enough to do in ZoneMinder, I didn't really want to use up that much storage recording video and then have to scroll through it to find anything interesting.<br />
<br />
The other day I saw a blog post where someone was using a Raspberry Pi and a webcam to do some time-lapse photography, and that sparked an idea that seemed easy enough to do in an afternoon – I could come up with a Python script to grab images from the network cameras at fixed intervals, and write them to a video file in order to generate a time-lapse video!<br />
<br />
The first step was to figure out how to build a video file a frame at a time using Python. I had played with the motion-jpeg (<a href="http://en.wikipedia.org/wiki/Motion_JPEG" target="_blank">mjpeg</a>) format in the past, which pretty much consists of jpeg images streamed one after the other in a file (sometimes with a boundary record between them). I discovered that I could simply capture and append jpeg images to a file and get a video file that could be read by a few video players and converters. Best of all, I could use a simple avconv (formerly ffmpeg) command to convert the mjpeg files to mp4, which is smaller and viewable by almost any player.<br />
<br />
Next, I wanted to be able to time-stamp each image so that I could tell when the video was created. For this I stumbled across the <a href="http://www.pythonware.com/products/pil/" target="_blank">Python Imaging Library (PIL)</a> which supports several image formats, including jpeg. Using it, I was able to select a font and write a time-stamp on each image as it was captured before adding it to the mjpeg video file. If it isn't already installed on your system, you can install it using <pre>sudo apt-get install python-imaging</pre> for Debian-based systems or by using the appropriate package manager for your distro.<br />
<br />
With all the pieces in place, I developed a little Python script that periodically grabs images from several network cameras and builds a separate mjpeg file for each of them:<br />
<br />
talicam.py:<br />
<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #8f5902; font-style: italic">#!/usr/bin/python</span>
<span style="color: #8f5902; font-style: italic"># Number of seconds between frames:</span>
<span style="color: #000000">LAPSE_TIME</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #0000cf; font-weight: bold">30</span>
<span style="color: #8f5902; font-style: italic"># Name of truetype font file to use for timestamps (should be a monospace font!)</span>
<span style="color: #000000">FONT_FILENAME</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #4e9a06">"UbuntuMono-B.ttf"</span>
<span style="color: #8f5902; font-style: italic"># Format of timestamp on each frame</span>
<span style="color: #000000">TIMESTAMP_FORMAT</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #4e9a06">"%Y-%m-%d %H:%M:%S"</span>
<span style="color: #8f5902; font-style: italic"># Command to batch convert mjpeg to mp4 files:</span>
<span style="color: #8f5902; font-style: italic"># for f in *.mjpeg; do echo $f ; avconv -r 30000/1001 -i "$f" "${f%mjpeg}mp4" 2>/dev/null ; done</span>
<span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">urllib</span>
<span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">sys</span><span style="color: #ce5c00; font-weight: bold">,</span> <span style="color: #000000">time</span><span style="color: #ce5c00; font-weight: bold">,</span> <span style="color: #000000">datetime</span>
<span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">StringIO</span>
<span style="color: #204a87; font-weight: bold">import</span> <span style="color: #000000">Image</span><span style="color: #ce5c00; font-weight: bold">,</span> <span style="color: #000000">ImageDraw</span><span style="color: #ce5c00; font-weight: bold">,</span> <span style="color: #000000">ImageFont</span>
<span style="color: #204a87; font-weight: bold">class</span> <span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #204a87; font-weight: bold">def</span> <span style="color: #000000">__init__</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">name</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">url</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">filename</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">name</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">name</span>
<span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">url</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">url</span>
<span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">filename</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">filename</span>
<span style="color: #204a87; font-weight: bold">def</span> <span style="color: #000000">CaptureImage</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #000000">camera</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">urllib</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">urlopen</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">url</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">image_buffer</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">StringIO</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">StringIO</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #000000">image_buffer</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">write</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">camera</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">read</span><span style="color: #000000; font-weight: bold">())</span>
<span style="color: #000000">image_buffer</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">seek</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">image</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">Image</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">open</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">image_buffer</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">camera</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">close</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #204a87; font-weight: bold">return</span> <span style="color: #000000">image</span>
<span style="color: #204a87; font-weight: bold">def</span> <span style="color: #000000">TimestampImage</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">image</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #000000">draw_buffer</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">ImageDraw</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">Draw</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">image</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">font</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">ImageFont</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">truetype</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">FONT_FILENAME</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">16</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">timestamp</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">datetime</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">datetime</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">now</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #000000">stamptext</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #4e9a06">"{0} - {1}"</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">format</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">timestamp</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">strftime</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">TIMESTAMP_FORMAT</span><span style="color: #000000; font-weight: bold">),</span> <span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">name</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">draw_buffer</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">text</span><span style="color: #000000; font-weight: bold">((</span><span style="color: #0000cf; font-weight: bold">5</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">5</span><span style="color: #000000; font-weight: bold">),</span> <span style="color: #000000">stamptext</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">font</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #000000">font</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #204a87; font-weight: bold">def</span> <span style="color: #000000">SaveImage</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">image</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #204a87; font-weight: bold">with</span> <span style="color: #204a87">open</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">filename</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"a+b"</span><span style="color: #000000; font-weight: bold">)</span> <span style="color: #204a87; font-weight: bold">as</span> <span style="color: #000000">video_file</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #000000">image</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">save</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">video_file</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"JPEG"</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">video_file</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">flush</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #204a87; font-weight: bold">def</span> <span style="color: #000000">Update</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #000000">image</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">CaptureImage</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">TimestampImage</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">image</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">SaveImage</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">image</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #204a87; font-weight: bold">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"Captured image from {0} camera to {1}"</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">format</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">name</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #3465a4">self</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">filename</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #204a87; font-weight: bold">if</span> <span style="color: #000000">__name__</span> <span style="color: #ce5c00; font-weight: bold">==</span> <span style="color: #4e9a06">"__main__"</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #000000">cameras</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000; font-weight: bold">[]</span>
<span style="color: #000000">cameras</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">append</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"porch"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"http://username:password@10.17.42.172/SnapshotJPEG?Resolution=640x480&Quality=Clarity"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"cam1.mjpeg"</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #000000">cameras</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">append</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"driveway"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"http://username:password@10.17.42.174/SnapshotJPEG?Resolution=640x480&Quality=Clarity"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"cam2.mjpeg"</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #000000">cameras</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">append</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"backyard"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"http://username:password@10.17.42.173/SnapshotJPEG?Resolution=640x480&Quality=Clarity"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"cam3.mjpeg"</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #000000">cameras</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">append</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"sideyard"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"http://10.17.42.176/image/jpeg.cgi"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"cam4.mjpeg"</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #000000">cameras</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">append</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">Camera</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"stairway"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"http://10.17.42.175/image/jpeg.cgi"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #4e9a06">"cam5.mjpeg"</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #204a87; font-weight: bold">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"Capturing images from {0} cameras every {1} seconds..."</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">format</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #204a87">len</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">cameras</span><span style="color: #000000; font-weight: bold">),</span> <span style="color: #000000">LAPSE_TIME</span><span style="color: #000000; font-weight: bold">))</span>
<span style="color: #204a87; font-weight: bold">try</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #204a87; font-weight: bold">while</span> <span style="color: #000000; font-weight: bold">(</span><span style="color: #3465a4">True</span><span style="color: #000000; font-weight: bold">):</span>
<span style="color: #204a87; font-weight: bold">for</span> <span style="color: #000000">camera</span> <span style="color: #204a87; font-weight: bold">in</span> <span style="color: #000000">cameras</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #000000">camera</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">Update</span><span style="color: #000000; font-weight: bold">()</span>
<span style="color: #000000">time</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">sleep</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">LAPSE_TIME</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #204a87; font-weight: bold">except</span> <span style="color: #cc0000; font-weight: bold">KeyboardInterrupt</span><span style="color: #000000; font-weight: bold">:</span>
<span style="color: #204a87; font-weight: bold">print</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"\nExit requested, terminating normally"</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">sys</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">exit</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">)</span>
</pre></div>
<br />
Notice the URLs supplied in the Camera constructors. These are specific to each brand of camera, but you can usually find the format with a little Googling. In my program above, the first three cameras are <b>Panasonic BL-C101A</b> network cameras, the last two are a <b>D-Link DCS-930L</b> and a <b>TrendNet TV-IP551W</b> which both have very similar software and URLs.<br />
<br />
The font file referenced above needs to be located in the same directory as the Python script, and for best results should be a mono-space font. I just grabbed the <a href="http://font.ubuntu.com/" target="_blank">Ubuntu Monospace Bold</a> TrueType font file for use here, but you could use anything you like.<br />
<br />
You will probably want to launch this as a background task so that it can run for extended periods of time. I have it running on the same server that runs my ZoneMinder setup, so it can run 24-7 collecting time-lapse video. I also wrote a quick little script file that iterates the mjpeg files it finds and converts them to mp4 for easier viewing and archiving:<br />
<br />
mjpeg2mp4:<br />
<!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #8f5902; font-style: italic">#!/bin/bash</span>
<span style="color: #204a87">echo</span> <span style="color: #4e9a06">"Removing old files..."</span>
rm -fv *.mp4
<span style="color: #204a87">echo</span> <span style="color: #4e9a06">"Converting files to mp4..."</span>
<span style="color: #204a87; font-weight: bold">for </span>f in *.mjpeg ; <span style="color: #204a87; font-weight: bold">do</span>
<span style="color: #204a87; font-weight: bold"> </span><span style="color: #000000">t</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #204a87; font-weight: bold">${</span><span style="color: #000000">f</span><span style="color: #000000; font-weight: bold">%mjpeg</span><span style="color: #204a87; font-weight: bold">}</span>mp4
<span style="color: #204a87">echo</span> <span style="color: #4e9a06">" Converting $f to $t"</span>
avconv -r 30000/1001 -i <span style="color: #4e9a06">"$f"</span> -q 5 <span style="color: #4e9a06">"$t"</span> 2>/dev/null
<span style="color: #204a87; font-weight: bold">done</span>
<span style="color: #204a87">echo</span> <span style="color: #4e9a06">"Done!"</span>
</pre></div>
<br />
I had a lot of fun learning a few new tricks while working on this, and hopefully you can use it as a starting point for your own time-lapse adventure. If you find this post useful, or have questions about how it works, please leave a comment below.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com2tag:blogger.com,1999:blog-3441881071717960329.post-13219261905128622972012-06-20T18:08:00.001-07:002012-06-23T16:25:25.519-07:00Low-Voltage Controlled AC Power Strip<br />
<b>NOTE: This hack involves working with dangerous voltage levels, which can result in </b><b>property damage, </b><b>injury, or </b><b>death</b><b>! Proceed at your own risk. If you are not comfortable working with power circuits and wiring, you may want to consider using something like the <a href="http://www.adafruit.com/products/268" target="_blank">PowerSwitch Tail II from Adafruit</a> instead.</b><br />
<br />
As part of a larger project I'm working on, I needed a way to control five AC powered devices from a small microcontroller. At work, we use <a href="http://www.opto22.com/site/pr_selector.aspx?cid=7&qs=1003#10071003" target="_blank">Opto 22 G4 Solid State Relays</a> in our industrial control systems. They are small and convenient to work with, but I was looking for something more compact. Searching around the web, I noticed that many hobbyist were working with <a href="http://sharp-world.com/products/device/lineup/data/pdf/datasheet/s108t02_e.pdf" target="_blank">Sharp S108T02</a> Solid State Relays, but doing a little research at <a href="http://www.digikey.com/scripts/DkSearch/dksus.dll?vendor=0&keywords=S201S06V" target="_blank">Digikey</a> I decided to use the similar <a href="http://sharp-world.com/products/device/lineup/data/pdf/datasheet/s101s06v_e.pdf" target="_blank">Sharp S201S06V</a> instead.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr-8cGu9pYrUZKltWSDThOm1_18cRMM7C1xRZFb8UY64LLajPhoGwkyVI4is3AheTNx_SO8exnSjzzja19OPKlydZ3qn3uY9bHzN6RmDMb6LclLY5D9um4dt4iHcMNmtHTj9CQ01buu3g/s1600/psdiagram.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr-8cGu9pYrUZKltWSDThOm1_18cRMM7C1xRZFb8UY64LLajPhoGwkyVI4is3AheTNx_SO8exnSjzzja19OPKlydZ3qn3uY9bHzN6RmDMb6LclLY5D9um4dt4iHcMNmtHTj9CQ01buu3g/s320/psdiagram.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">S201S06V Solid State Relay Diagram</td></tr>
</tbody></table>
<br />
Next, I needed to find a way to provide outlets to plug the controlled devices into. I thought about using a project box and mounting three standard dual outlet wall sockets on it, then using a standard outlet cover on those. That would work, but it would still be on the large side. I then considered using a standard six outlet power strip. I headed down to my local Home Depot to see what options I had there, and returned with a nice, metal cased <a href="http://www.homedepot.com/Electrical-Electrical-Cords-Cord-Management-Surge-Protectors-Power-Strips-Converters/h_d1/N-5yc1vZbm60/R-100663221/h_d2/ProductDisplay" target="_blank">power strip</a>. I removed the four screws holding the bottom on and checked to see if my relays would fit:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmrxiwcMqr4Lsf16Po8bp25PfVZ8F9vLtBWj2Ova-7lXkAKpH5XR0s1iod_884Ps-DCaL6y_1qY4Xga5-lQU_Efez5Cx2w6SjQE3ZFYa8MbfB7UvecHiMFnuXYb170KUSBKUqByBO-HY/s1600/powerstrip1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmrxiwcMqr4Lsf16Po8bp25PfVZ8F9vLtBWj2Ova-7lXkAKpH5XR0s1iod_884Ps-DCaL6y_1qY4Xga5-lQU_Efez5Cx2w6SjQE3ZFYa8MbfB7UvecHiMFnuXYb170KUSBKUqByBO-HY/s640/powerstrip1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Ready for surgery</td></tr>
</tbody></table>
<br />
It looked like everything would fit! As a bonus, mounting the relays flat against the bottom would allow the metal to act like a heat sink. I measured to get them evenly spaced, drilled the mounting holes, and attached the relays using a bit of thermal compound for good heat transfer. (I thought I would be able to attach the wires after the relays were mounted, but it turned out to be easier to do with them unmounted, so next time I would wait on the thermal compound).<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwc-RJPR3jUMFXta-LEilKeZEllUUcb6QmE2V0C03A9xtqfK8zi-3u5U8XudyG2V0wCR92ayq3oJj8oX-Jd5iAqIbAABuRqx442knF5jFBhRx-wWvm9a_0Sbi_A0BSGNv49hSybmg7GHo/s1600/powerstrip2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwc-RJPR3jUMFXta-LEilKeZEllUUcb6QmE2V0C03A9xtqfK8zi-3u5U8XudyG2V0wCR92ayq3oJj8oX-Jd5iAqIbAABuRqx442knF5jFBhRx-wWvm9a_0Sbi_A0BSGNv49hSybmg7GHo/s640/powerstrip2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Power and control bus wiring</td></tr>
</tbody></table>
<br />
I started by soldering the common buses for the AC power and DC control lines, covering all the exposed wiring with heat shrink as I went. Once I had the common wiring done, I added the individual AC output wiring using different colors for each – I picked colors that matched the low-voltage cable's colors. For the low-voltage cable I just used the cable from an old PS/2 mouse that had a 6 pin DIN connector, which gave me 5 lines for control signals and 1 for ground. The mouse cable works nicely here because it is long and flexible. Before you start wiring the DC cable, drill a hole in the upper part of the case near the power cable, big enough for an appropriate strain-relief. Then run the cable through that hole, before you begin soldering it! I also made sure to write down the sequence of wire colors on the DC cable that corresponded to the pin numbers on the DIN connector, so that I could attach the AC control wire colors in the same sequence.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfJfAHWNg63qaCc4ytWnpU1x28TdVEUwscptbSOfP10Msrh-ffb8k6zUcvVL09rPbR3MR3om3-IuWIg0gDyNCcT6RfJyPJKlsq2RjqifLNnvsZngKQ9sZQCSxEj-RJaCvozMyRWPVVBcY/s1600/powerstrip3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfJfAHWNg63qaCc4ytWnpU1x28TdVEUwscptbSOfP10Msrh-ffb8k6zUcvVL09rPbR3MR3om3-IuWIg0gDyNCcT6RfJyPJKlsq2RjqifLNnvsZngKQ9sZQCSxEj-RJaCvozMyRWPVVBcY/s640/powerstrip3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Added power control wiring</td></tr>
</tbody></table>
<br />
After getting all the AC and DC wiring attached to the solid state relays, I mounted everything to the bottom plate of the power strip, and routed the wires, with the inputs coming from the side where the power cable comes in, and the outputs at the opposite end. As you can see, I also added some cable tie points to make sure the wires did not get pulled out or shorted.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgklCcOUAgLYACocKhzqhVYQ3Rrk4QUXszSTv7fkoK_rgBtpM5dnocdduZsXfjYw8yyB-u2SkG8jo8T5EXmDpNClctWpuA6rz8w9GMBaS5XyBH0LUNroE69QKDzaDx5EwaUFkOEmLBMy8/s1600/powerstrip4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgklCcOUAgLYACocKhzqhVYQ3Rrk4QUXszSTv7fkoK_rgBtpM5dnocdduZsXfjYw8yyB-u2SkG8jo8T5EXmDpNClctWpuA6rz8w9GMBaS5XyBH0LUNroE69QKDzaDx5EwaUFkOEmLBMy8/s640/powerstrip4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Solid state relays wired and mounted</td></tr>
</tbody></table>
<br />
Next, I removed the black “hot” bus from all but the outlet closest to the power cord, and broke the jumpers on the hot side between the top and bottom outlet of each outlet pair that connected them together. I am leaving the outlet closest to the power cord always hot, so I have some place to plug in the project's controller. I can still turn the entire thing on and off using the existing power switch. Now that that the remaining five outlet's hot sides are disconnected, it's time to start wiring them up.<br />
<br />
Since these outlets use “slide in” connections intended for lower gauge solid core wire, and I am using smaller gauge stranded wire, I soldered the ends of the stranded wire to form a stiff end that would easily slide into the outlet connections. You can sort of see the soldered end of the red wire in the next photo.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-1WYJ3T76EyGtpgZSxI2928dmaqYzvR2CBgjW0GDej8mv0pyAjCEEV0mRcj08v5cMsrud-6K2gl4vzhPjAFstcrDaJ815mOeLid6D3AoIKtQBZ6fWwSRvDhyphenhyphencyTWe9mgNuPi1r8lDinY/s1600/powerstrip5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-1WYJ3T76EyGtpgZSxI2928dmaqYzvR2CBgjW0GDej8mv0pyAjCEEV0mRcj08v5cMsrud-6K2gl4vzhPjAFstcrDaJ815mOeLid6D3AoIKtQBZ6fWwSRvDhyphenhyphencyTWe9mgNuPi1r8lDinY/s640/powerstrip5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connecting the power wiring</td></tr>
</tbody></table>
<br />
Now I attach each of the AC control wires to the corresponding outlet, making sure to keep them in the same order as the relay (and DIN connector) wiring. I cut each wire to the proper length, so that I wouldn't have a lot of extra wire to try and tuck inside. Here it is all wired up:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit7YmU4nqa3nMSN0qbyNbOOssAXOaKsHUS4eLdrW700Y9RCR5DTH2QXF9vlN_UquBBwlnrnrO4uH1Pz00_cm2bkjLmPsjnpkD_MbuYKWN7di-JtCs3MMOQuLymT4MiP4enDOJbTSpS4Rg/s1600/powerstrip6.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit7YmU4nqa3nMSN0qbyNbOOssAXOaKsHUS4eLdrW700Y9RCR5DTH2QXF9vlN_UquBBwlnrnrO4uH1Pz00_cm2bkjLmPsjnpkD_MbuYKWN7di-JtCs3MMOQuLymT4MiP4enDOJbTSpS4Rg/s640/powerstrip6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Ready to close</td></tr>
</tbody></table>
<br />
And now all assembled and ready to go with its new “tail”:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGX1BkQ8HQ_OeHUAYkgtvW9bTNfs-X1bcMmXa-T9ZXtFrnNJM4-Q0bonFCcaMaFkPZf3T5NEuEBG769Lir72N_zOzur0d37iDHXz6E5ehlc0rSBdixT7jxHBVeDk6HAC-irG17Z_5NYJk/s1600/powerstrip7.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGX1BkQ8HQ_OeHUAYkgtvW9bTNfs-X1bcMmXa-T9ZXtFrnNJM4-Q0bonFCcaMaFkPZf3T5NEuEBG769Lir72N_zOzur0d37iDHXz6E5ehlc0rSBdixT7jxHBVeDk6HAC-irG17Z_5NYJk/s640/powerstrip7.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Ready for work</td></tr>
</tbody></table>
<br />
Now I should note that the solid state relay inputs are simply LEDs, and require a current limiting resistor in series or you will destroy the devices. In this design, those resistors are located on the controller board, but you could easily include them inside the power strip by soldering them inline with the DC control wires. If you are going to use this with multiple projects, I would suggest including the resistors in the power strip to help protect the relays from damage.<br />
<br />
This hack worked out very nicely, and it's been working for several months without any issues. Once again, since this project involves dangerous voltages, you should exercise extreme caution when building and using this hack. I am not responsible if you decide to duplicate this project and you electrocute yourself, set your house on fire, or encounter some other mishap. You have been warned.<br />
<div>
<br />
<b>Update</b><br />
<br />
Several of the commenters over at <a href="http://hackaday.com/" target="_blank">Hack a Day</a> noted that I didn't mention the solid state relays I'm using are only rated for 3 amps (and you would likely need a heat sink for that). Although that is fine for my project, you probably shouldn't try to control your air conditioner using these devices! You could do a similar hack using a larger power strip with more internal room and beefier solid state relays, and along the way provide either fusing or circuit breaker protection for the individual outlets.</div>teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com8tag:blogger.com,1999:blog-3441881071717960329.post-31409514101371416252012-06-01T07:22:00.000-07:002012-06-01T10:57:45.132-07:00Let There Be Music<br />
I needed to be able to play MP3 files as part of a larger project I'm working on. I did a quick search on the Internet for embeddable MP3 player chips and circuits, but everything seemed a bit too expensive or too much work. It was around then I saw <a href="http://hackaday.com/2012/01/16/3-adds-sweet-tunes-to-your-project/" target="_blank">Hack a Day's</a> post pointing me to Gadget Gangster's Instructables article <a href="http://www.instructables.com/id/Adding-MP3-to-your-project-for-300/" target="_blank">Adding MP3 to your project for $3.00</a>. Being the cheapskate that I am, $3 sounds great to me!<br />
<br />
A quick trip to <a href="http://www.ebay.com/sch/i.html?_sop=15&_sacat=0&_nkw=mini+clip+mp3+player&rt=nc&LH_BIN=1" target="_blank">eBay</a> and I had two of these “mini-clip” players on the way. I figured I should get an extra just in case I damage one while fooling around. Before I began hacking the player, I tested it out to make sure it was operational and get an idea of how it behaves. One of the things I discovered is that the USB interface is pretty flaky (at least when connected to a Linux system), so it was much easier and faster to transfer files onto it by writing directly to the MicroSD card using a card reader.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zhtvVWkHkjsGyWj4V2EiucKLTAbdyMhJNxBfXX_heDVgsp5wqu7ODt43s-trye07r6GMBtxayCfkPrAXO8ze24o8djVBEV-FQCvr9rZEE0Uv37p0K8t82yb2lK5GDd2qGg-nNDYp65I/s1600/img0853.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3zhtvVWkHkjsGyWj4V2EiucKLTAbdyMhJNxBfXX_heDVgsp5wqu7ODt43s-trye07r6GMBtxayCfkPrAXO8ze24o8djVBEV-FQCvr9rZEE0Uv37p0K8t82yb2lK5GDd2qGg-nNDYp65I/s640/img0853.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Player liberated from its case</td></tr>
</tbody></table>
<br />
I cracked one open and took a look to see what it would take to hook into it. One of the things I wanted to do is to be able to move this from prototype to finished product, or between projects. The Instructables article showed discrete wires soldered to the board, which I could have brought out to some kind of connector. After a bit of thought, I realized I could use a small 10 pin <a href="http://en.wikipedia.org/wiki/Insulation-displacement_connector" target="_blank">IDC connector</a> and ribbon cable to allow me to plug it into a nice wire-wrappable header. And with the extra pins, I could also supply power, and even pick off the audio!<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfFd36k8dLxxW-HBnEX3fojsAy_nNMIUB409Dlyjk0aghRsC-eICL6X31r3zddqGVreRsep4uFOHqX5kMMm4xknTaFRlq3JpW-zYh7aBHkaiBSvF2m4Zhk8Jsvif5OF-pQ4uebcEUQh6M/s1600/img0859.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfFd36k8dLxxW-HBnEX3fojsAy_nNMIUB409Dlyjk0aghRsC-eICL6X31r3zddqGVreRsep4uFOHqX5kMMm4xknTaFRlq3JpW-zYh7aBHkaiBSvF2m4Zhk8Jsvif5OF-pQ4uebcEUQh6M/s400/img0859.JPG" width="300" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">After some minor surgery</td></tr>
</tbody></table>
<br />
First, I removed the power wires and also carefully removed the surface mount audio connector. Somewhere in my lab I have the parts to build the IDC/ribbon cable assembly, but I found a pre-made one in my parts bin so I just cut it in half and started peeling back a few of the wires.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiisEGKvol9yMpBU950cEe4lgypM_d9DdAnCbyDliBmb6nO54np7SMQY3o0Rue78twQX1VrJxyU92kuSZ6pS1B3JN_Rtcdot_bznTwhpIrvXY6VAslOmZA-FYzdJ94LmINMjIUQ0IbhmhI/s1600/img0860.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiisEGKvol9yMpBU950cEe4lgypM_d9DdAnCbyDliBmb6nO54np7SMQY3o0Rue78twQX1VrJxyU92kuSZ6pS1B3JN_Rtcdot_bznTwhpIrvXY6VAslOmZA-FYzdJ94LmINMjIUQ0IbhmhI/s400/img0860.JPG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">IDC cable ready for action</td></tr>
</tbody></table>
I started by connecting to the power pads (mostly because they were big and easy to get to). This also conveniently allowed me to set the amount of overhang from the connector to the board. I then cut and stripped the remaining three wires for that side and landed them onto the pads where the audio connector used to be. Next, I flipped over the board and cut each of the wires to length and soldered them to the center of each button pad.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi90Da5Xo35edmKRl_WquFDmCw2yH51ijQBfEwXj5gaZ81kYemGB4b5lQVXpxvh3axJDFZs9UcEPQdvtd8k3zkNGtTfiKKiR-_-z_pVIhKwYCCNzPk6sqIi9c1iORNubq9BfCCq_8HYiGo/s1600/img08623.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi90Da5Xo35edmKRl_WquFDmCw2yH51ijQBfEwXj5gaZ81kYemGB4b5lQVXpxvh3axJDFZs9UcEPQdvtd8k3zkNGtTfiKKiR-_-z_pVIhKwYCCNzPk6sqIi9c1iORNubq9BfCCq_8HYiGo/s640/img08623.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Wires landed on board</td></tr>
</tbody></table>
<br />
<div style="text-align: left;">
</div>
<div style="text-align: right;">
</div>
Now with all the wires hooked up, it's time to test it out and see if I fried anything. I wired up a 2x10 header on my main project (more about that in a future post) and wrote some quick code to “push” the buttons.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwTPUQcDdTH1TIr2JXoeqfxAT6vnorrkATSPokiT-xrI6rGsmBHahsYYiffgI0xhOoXZTOZB746bEx88CwxZADRB3x8bHKeP4ViVWjJMFDtfN2AEnjIw6w4ajd6G2KZBNs342l8W16lAc/s1600/img0865.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwTPUQcDdTH1TIr2JXoeqfxAT6vnorrkATSPokiT-xrI6rGsmBHahsYYiffgI0xhOoXZTOZB746bEx88CwxZADRB3x8bHKeP4ViVWjJMFDtfN2AEnjIw6w4ajd6G2KZBNs342l8W16lAc/s640/img0865.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">At home in the new project</td></tr>
</tbody></table>
<br />
I'm using a PIC18F4550 in this project, and using my favorite language – assembly. I love the challenge of hand-tuning code to make it as small and fast as possible, and that's not so easy with the PIC18F's! Anyway, I wanted to drive the switch outputs <a href="http://en.wikipedia.org/wiki/Open_collector" target="_blank">open collector</a> style, so for the switch outputs I initialize the ports by setting the switch TRIS bits and clearing the LAT output bits. Then when I want to “press” a switch, I clear the the corresponding TRIS bit which drives the output low, and set a tick countdown timer. When that timer expires about 200ms later, I set all the TRIS bits again to “float” the outputs and release all the switches.<br />
<br />
After checking to make sure the software was doing as I expected, I connected the MP3 player to the main project, powered it up, and out came music! I then tested each of the switch functions, and the player responded as expected, pausing, playing, skipping forward and back, etc. To my surprise, everything worked as expected. The player has been working without any hiccups for several months, despite powering it with 5v instead of it's expected 3.7v battery, and shorting the switch inputs to ground instead of the other contact (although I expect that is the way it is wired anyway).<br />
<br />
I would like to thank <a href="http://gadgetgangster.com/" target="_blank">Gadget Gangster</a> for sharing his cool tip to re-purpose cheap MP3 players for use in embedded projects, and <a href="http://hackaday.com/" target="_blank">Hack a Day</a> for bringing it to my attention.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-22419359428202496582011-08-27T06:28:00.000-07:002011-08-27T06:49:35.828-07:00Hacking WebRunner to work with Firefox 6.0I have come to depend on <a href="http://dev.salsitasoft.com/site/projects/" target="_blank">Salsita Software's WebRunner</a> extension for Firefox that let's me create “applications” out of web sites. It comes in especially handy when I want to be logged in with multiple identities on the same web site, as well has keeping an always open window on my <a href="http://www.zoneminder.com/" target="_blank">Zoneminder</a> cameras.
<br />
<br />When Firefox 6.0 was pushed out in Ubuntu, I was quite dismayed to find that when it checked add-ons and extensions for compatibility, WebRunner was not compatible, and furthermore, an updated version was not available. I waited for around two weeks for <a href="http://www.salsitasoft.com/" target="_blank">Salsita</a> to update their software, but so far there's been nothing. So I dug around in the .xpi file and came up with this hack to make the current version work with Firefox 6. These instructions are for Ubuntu/Linux (since that is all I have running now), but the changes should be very similar for Windows as well.
<br />
<br />First download (but don't install/run) the latest .xpi file from <a href="http://dev.salsitasoft.com/site/download/#webrunner" target="_blank">here</a>. Then open the file with an archive manager (<a href="https://developer.mozilla.org/en/XPI" target="_blank">.xpi</a> files are really just jar/zip files) and edit the file <tt>install.rdf</tt>, changing the value of <tt>/RDF/Description/version</tt> from <tt>5.0</tt> to <tt>5.1</tt>, and the value of <tt>/RDF/targetApplication/maxVersion</tt> from <tt>5.*</tt> to <tt>6.*</tt>. Next, edit the file <tt>stub/application.ini</tt>, changing the value for <tt>MaxVersion</tt> from <tt>5.0.*</tt> to <tt>6.0.*</tt>. You may want to rename the .xpi file at this point to make it easier to keep track of it.
<br />
<br />Now update to Firefox 6.0 (if you haven't done so already) and remove the old WebRunner 5.0 extension, in Tools|Add-ons on the Extensions tab. Close that dialog, and go to File|Open File... in Firefox and select your modified .xpi file. It should install without complaint, indicating it is version 5.1 (<span style="font-style:italic;">hopefully Salsita will version their next release higher than this</span>).
<br />
<br />At this point, you can either re-create your web application shortcuts, or hack the existing ones to work with the updated extension. To fix the current shortcuts and applications, modify the command for the shortcuts to point to firefox-6.0 instead of firefox-5.0. Then for each application in your <tt>~/.webapps</tt> directory, edit the <tt>appname@webrunner/stub/application.ini</tt> file and change <tt>MaxVersion</tt> from <tt>5.0.*</tt> to <tt>6.0.*</tt> and change <tt>GRE_HOME</tt> to <tt>/usr/lib/firefox-6.0</tt>. Now try to launch your web application shortcuts and you should be good-to-go!
<br />
<br />As with most hacks, I make no guarantees that this won't in some way hose your Firefox installation or your entire computer, so attempt this at your own risk! On the other hand, if you are like me and depend on the excellent WebRunner extension, this hack is a quick way to get it back in Firefox 6. Make sure to leave comments if you have tried this under Windows and get it to work.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com4tag:blogger.com,1999:blog-3441881071717960329.post-21872873039196480752010-09-18T07:23:00.000-07:002010-09-18T07:43:22.812-07:00Dependency Injection Using Nested ClassesIn my day job (lately it seems to be a 24 hour day) I do most of my work in C#, and all our new projects are implemented using <a href="http://en.wikipedia.org/wiki/Test_driven_development" target="_blank">Test Driven Development</a>. Like most people doing TDD, we need to inject <a href="http://martinfowler.com/articles/mocksArentStubs.html" target="_blank">mock/stub/dummy</a> objects into our objects under test. The traditional way to accomplish this is either via <a href="http://martinfowler.com/articles/injection.html" target="_blank">Constructor Injection or Setter Injection</a>.<br /><br />I have never been a fan of using setters to inject test objects, because it clutters the code with properties and methods that are only used for testing and are never used by production code. At first, I relied on constructor injection, but would sometimes run into cases where I was passing in half a dozen or more objects into the constructor. Many of these objects were simply helper classes that bundled up some functionality needed by the object under test only, and would never normally be used outside of that class.<br /><br />Over the last year we have evolved another way of injecting mock objects into our test objects – Nested Class Injection (or as we call it, “TestHook Injection”). In C#, a nested class has access to it's containing class's private members, so we can use methods on the nested class to reach into the private details of the outer class. Here is a simple example:<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> public class ObjectUnderTest {<br /><br /> private IHelperObject _helper;<br /><br /> public ObjectUnderTest() {<br /> _helper = new ProductionHelper();<br /> }<br /><br /> public bool MethodToTest(int testNumber) {<br /> return _helper.HelperMethod(testNumber);<br /> }<br /><br /> public abstract class TestHook {<br /><br /> public static void InjectObjectHelper(ObjectUnderTest objectUnderTest, IHelperObject helper ) {<br /> objectUnderTest._helper = helper;<br /> }<br /><br /> }<br /> }<br /><br /></code></pre><br />Now all the test related code is contained within the abstract TestHook class. This class acts like the diagnostic connector on your car, allowing access to internal data and manufacturer's info without exposing it to the user. In fact, you can even use conditional compilation to exclude the TestHook class in the release build to remove the “connector” if code size or security is an issue.<br /><br />Now when you are ready to test your objects, you can do something like:<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> [Test]<br /> public void Test_MethodToTest() {<br /> ObjectUnderTest objectUnderTest = new ObjectUnderTest();<br /><br /> IHelperObject mockHelperObject = new MockHelperObject();<br /> ObjectUnderTest.TestHook.InjectObjectHelper(objectUnderTest, mockHelperObject);<br /><br /> objectUnderTest.MethodToTest(12);<br /><br /> // Test expectations here...<br /> }<br /><br /></code></pre><br />Note that I do not normally create my own mocks as shown above, I typically use <a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a> to create mock objects, and <a href="http://ninject.org/" target="_blank">Ninject</a> as my <a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank">IoC container</a>. The contrived examples above are just to show the basic technique of using a nested class to cleanly access the internals of an object for testing purposes.<br /><br />Now injecting objects like this is really only useful when those objects are only going to be used internally by the class under test. If you need to pass in an instance of an object that is shared between multiple objects, traditional constructor or setter injection is fine, since that is actually part of the object's contract with the world.<br /><br />We have been using this technique for several months now, and it has resulted in cleaner production code, and more streamlined testing. Our test setup methods are simpler now, because we only need to inject mocks in the tests that need them instead of in the common test setup method.<br /><br />I figured I should write this up since I have found the technique very useful, and a quick Google search didn't turn up anything useful. I expect this can be used in any language that supports nested classes where the nested class has access to the outer class's private member variables. Let me know in the comments if you find this technique helpful, or have any improvements. Thanks for stopping by!teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-80932783781975078632010-05-16T06:38:00.000-07:002010-05-16T07:31:15.304-07:00Me DayAs a special treat for myself, I recently escaped from the Teknynja Cave to visit <a href="http://www.jpl.nasa.gov/events/open-house.cfm" target="”_blank”">JPL's 2010 Open House</a>. This was my first time visiting Jet Propulsion Laboratory or the open house event, and it was even better than I expected. As a science and space enthusiast, there where plenty of things to see. What I didn't expect was the festival atmosphere and all the activities and displays for kids and families. There was plenty of booths selling kettle corn, hamburgers & hot dogs, frozen lemonade and other treats, and the smells were like that of any “normal” festival.<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinviCvRjOskV1g4Tpo8IlM5g0WwfkdGB_uN3_0uX22Aq_W_yNv9Hn52ddyeg5wTqpX9F1xJ0rer8H0gpfgs2pIBytHe9Em4f0uZVEfByqw4ofQ-DfLV9rMMmvSAgXdB_jzIL3NvCdAhIA/s1600/sfof.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinviCvRjOskV1g4Tpo8IlM5g0WwfkdGB_uN3_0uX22Aq_W_yNv9Hn52ddyeg5wTqpX9F1xJ0rer8H0gpfgs2pIBytHe9Em4f0uZVEfByqw4ofQ-DfLV9rMMmvSAgXdB_jzIL3NvCdAhIA/s400/sfof.jpg" alt="" id="BLOGGER_PHOTO_ID_5471865130392458418" border="0" /></a><br />My first stop of the day was the <a href="http://www.nps.gov/history/nr/travel/aviation/ops.htm" target="”_blank”">Space Flight Operations Facility</a>, the “Mission Control” room, where spacecraft like the Viking, Pioneer, Voyager and the Mars Rovers have been monitored and controlled. It was exciting to see this room with so much history (and to be in the presence of so many computer monitors).<br /><br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsabj0SacEutGTviANL3Fiii2gqIJU2MQ8ZUnG_YUUr5upbZ36dYMQhzqvf2tfFeH1LnNMrva5G7c51bnztoRYne4c3MKALHnG8mp56Dhb6c71XP84Lx9l67NHUWeJRlkmuKVqFn6fVeY/s1600/ses.jpg"><img style="float: left; margin: 0pt 10px 10px 0pt; cursor: pointer; width: 240px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsabj0SacEutGTviANL3Fiii2gqIJU2MQ8ZUnG_YUUr5upbZ36dYMQhzqvf2tfFeH1LnNMrva5G7c51bnztoRYne4c3MKALHnG8mp56Dhb6c71XP84Lx9l67NHUWeJRlkmuKVqFn6fVeY/s320/ses.jpg" alt="" id="BLOGGER_PHOTO_ID_5471865536423300306" border="0" /><br /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN5S_QEPOOhe0YHWPD0-m619hLeeLgo5AkQoTTLAOnqxuXziJIpzHOeuboIEsxDvn0Mkr2YzAwA5LIJk03YWn8uiYTW9GUDbT3lALEc7vYQpGQG5V1GM-jLak_guLjmoHe-y3RrirqD2o/s1600/ses_ctlrm.jpg"><img style="display: right; margin: 0pt 0pt 10px 10px; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN5S_QEPOOhe0YHWPD0-m619hLeeLgo5AkQoTTLAOnqxuXziJIpzHOeuboIEsxDvn0Mkr2YzAwA5LIJk03YWn8uiYTW9GUDbT3lALEc7vYQpGQG5V1GM-jLak_guLjmoHe-y3RrirqD2o/s320/ses_ctlrm.jpg" alt="" id="BLOGGER_PHOTO_ID_5471865662474730850" border="0" /></a><br /><br />Next up was a short shuttle bus trip to the 25 Foot Space Simulator facility, a giant environmental chamber that simulates the conditions found in space or on other planets. Spacecraft are placed inside the simulator and subjected to the vacuum and heat of space. You can walk around inside the huge chamber, and I also enjoyed checking out the control room for the simulator.<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwc2th0y7WJyMEImeDr7idmwA8ia6qk7irrxkrHabf3N0x96dq9Zzz0K7yHWYFAHq7yKpsBFoVI8hjan0It8ifLYOTKHd5X4YHOo-vO9GX3f-kA0TK1l7J3jL2PcZd-eS2q7dGpXRFcXc/s1600/asmfclty2.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwc2th0y7WJyMEImeDr7idmwA8ia6qk7irrxkrHabf3N0x96dq9Zzz0K7yHWYFAHq7yKpsBFoVI8hjan0It8ifLYOTKHd5X4YHOo-vO9GX3f-kA0TK1l7J3jL2PcZd-eS2q7dGpXRFcXc/s400/asmfclty2.jpg" alt="" id="BLOGGER_PHOTO_ID_5471866296852989074" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUjhoKFcr9E83q886X_BzqD4i9azBUhacQ8DIe7m4zRdFWf3vxlzQQUMtHoBuAj_e9VCrLfIoc4T_iGrPDScW_P7JnkDHtqdUR3rl7hGF5XvNJWJddEqJncuiYxJN5TTIvleZFiKcv4Jg/s1600/asmfclty1.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 171px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUjhoKFcr9E83q886X_BzqD4i9azBUhacQ8DIe7m4zRdFWf3vxlzQQUMtHoBuAj_e9VCrLfIoc4T_iGrPDScW_P7JnkDHtqdUR3rl7hGF5XvNJWJddEqJncuiYxJN5TTIvleZFiKcv4Jg/s400/asmfclty1.jpg" alt="" id="BLOGGER_PHOTO_ID_5471866453337388354" border="0" /></a><br /><br />One of the highlights of my trip was visiting the Spacecraft Assembly Facility, a enormous clean room where JPL's probes and landers are built. It was especially exciting for me to see the <a href="http://marsprogram.jpl.nasa.gov/msl/" target="”_blank”">Mars Science Laboratory</a> (still in several pieces), which is scheduled to arrive on Mars in 2012.<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFx1R30OOoIdhuvbAUriP3hsyAxruYro1IEBYlVVGaLR3i_9KP-Ck2pdL8FkyxJ_bKRvpzfKwGxsf70U7PSM03kM7Po2tisMxPxTcKrGa-meMqBkZ7NUHEbxD9w5DBDv0VSMKwwvjQ_5E/s1600/wfpc.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 245px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFx1R30OOoIdhuvbAUriP3hsyAxruYro1IEBYlVVGaLR3i_9KP-Ck2pdL8FkyxJ_bKRvpzfKwGxsf70U7PSM03kM7Po2tisMxPxTcKrGa-meMqBkZ7NUHEbxD9w5DBDv0VSMKwwvjQ_5E/s400/wfpc.jpg" alt="" id="BLOGGER_PHOTO_ID_5471867139327277586" border="0" /></a><br />The big draw for me though, was the Hubble <a href="http://en.wikipedia.org/wiki/Wide_Field_and_Planetary_Camera_2" target="”_blank”">Wide Field Planetary Camera 2</a> exhibit, which displays the actual camera that flew on the Hubble telescope from 2002 until 2009. Being this close to actual space hardware was an amazing experience! It is difficult to really see it in this photo, as it is enclosed in a protective nitrogen gas environment. This exhibit is the centerpiece of the new museum on the JPL campus, that contains dozens of models of probes, rovers, and landers.<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvHFEpbFhbD9AtpktgICy7mAgUmvRjo4SbplcRhOiw8OquZRzqx9QWCM09SmHdHd-Jb_p-9xIIhcYJxGp0-bVZGzxTZEl0Gaxhucy9_0ZpQe3mX8hUCnWexaC7aaHOOT075dR7dFIeqvQ/s1600/fabfclty.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvHFEpbFhbD9AtpktgICy7mAgUmvRjo4SbplcRhOiw8OquZRzqx9QWCM09SmHdHd-Jb_p-9xIIhcYJxGp0-bVZGzxTZEl0Gaxhucy9_0ZpQe3mX8hUCnWexaC7aaHOOT075dR7dFIeqvQ/s400/fabfclty.jpg" alt="" id="BLOGGER_PHOTO_ID_5471867472727843106" border="0" /></a><br />At this point in my visit, the lines were starting to get very long, but I didn't mind. My next stop was the Spacecraft Fabrication Facility, where the components for spacecraft are machined and manufactured. The amount of manufacturing and machining technology in this building is overwhelming, and the tables showing example parts was very impressive.<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvxs1pIIYYSRQDYsmyW-k_0C0UuJQDm6vahGtaockane8IbNj9g_tCf1u3VO2hjpaYacopiF1hDFDkyknQYcYhkGvys_C-wcEwwDL82G1spkTlNQUT-VpDep_vxSlWjUNm2IJha3l8U9U/s1600/dreamlab.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvxs1pIIYYSRQDYsmyW-k_0C0UuJQDm6vahGtaockane8IbNj9g_tCf1u3VO2hjpaYacopiF1hDFDkyknQYcYhkGvys_C-wcEwwDL82G1spkTlNQUT-VpDep_vxSlWjUNm2IJha3l8U9U/s400/dreamlab.jpg" alt="" id="BLOGGER_PHOTO_ID_5471868156007443154" border="0" /></a><br />I finally ended up at the Micro Devices Laboratory, where they do everything from create nano-sized machines to electronic chip fabrication. There was plenty to see there, but this room caught my eye - this would be my dream office, with wires and electronic equipment everywhere. Maybe someday...<br /><hr /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc_K5aDrqon-xKxyI6j-tU9UJi8A9QZwIGJlHRjCVsOTgwZrCnpr0glRIrTjF656C_xFWll46Xa3fuWYldhhfPU2cviRJHnKvlNOOUUB-T0AX-CNyXv3gAvRKuPh7K04EZITqEPZY9tGM/s1600/rovers.jpg"><img style="float: left; margin: 0pt 10px 10px 0pt; cursor: pointer; width: 150px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc_K5aDrqon-xKxyI6j-tU9UJi8A9QZwIGJlHRjCVsOTgwZrCnpr0glRIrTjF656C_xFWll46Xa3fuWYldhhfPU2cviRJHnKvlNOOUUB-T0AX-CNyXv3gAvRKuPh7K04EZITqEPZY9tGM/s200/rovers.jpg" alt="" id="BLOGGER_PHOTO_ID_5471868387897258962" border="0" /></a><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPOlFADewbbf9ujD095XgsycNI9B2HyioQEXl_qAM1nuba09FOJPd8gsX77Nawze6SCoe7c55KkSwnColO0Jfh0b8bhlKEdv12zbow1o9eVLy36SwFVpVZH19qx2Nt5IxL87Ji6RB3_zA/s1600/athlete.jpg"><img style="display: right; margin: 0pt 0pt 10px 10px; cursor: pointer; width: 200px; height: 150px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPOlFADewbbf9ujD095XgsycNI9B2HyioQEXl_qAM1nuba09FOJPd8gsX77Nawze6SCoe7c55KkSwnColO0Jfh0b8bhlKEdv12zbow1o9eVLy36SwFVpVZH19qx2Nt5IxL87Ji6RB3_zA/s200/athlete.jpg" alt="" id="BLOGGER_PHOTO_ID_5471868529664721970" border="0" /></a><br /><hr/><br />I wrapped up my trip taking in the architecture and the festival scene before hitting the “gift shop” to pick up a tee shirt and some swag for the kids. I really only hit about half the activities at the open house, but saw what I came to see and more. I'll have to go again, and next time I'll probably bring the young'ins along as well.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-79114228252028998132010-03-07T07:13:00.000-08:002010-03-07T07:31:06.975-08:00std::string and sprintfAmongst the many projects I am currently juggling, one of them involves developing some C++ code for an embedded Linux project. I've just hit an instance where I'd like to be able to use “printf” style formatting using std::string instances, but it can be pretty clumsy – I need to allocate buffer space for sprintf, invoke the function, and package up the result into another string.<br /><br />I did a quick search on the Internet and found many others looking for the same thing: “Is there a way I can use sprintf in c++ using std:strings?” And invariably the answers were either <ul><br /> <li>“No”</li><br /> <li>“Use std::ostringstream and c++'s built-in manipulators”</li><br /> <li>“Use <a href="http://www.boost.org/doc/libs/1_42_0/libs/format/doc/format.html" target="_blank">boost::format</a>”</li><br /></ul>And they are all right!<br /><br />It turns out that you can't safely use the *printf style variable argument lists with C++, as only POD (Plain Old Data) types can be passed in the list. Attempting to pass most other types will result in a segmentation fault at run time. The official C++ way is to use ostringstream and the usual stream manipulators to format parameters, but for me, that make's writing tests more difficult because I need to “build” the expected streams exactly the same way in my test code. The final method could work for me, except that this is an embedded project and I am trying to keep the number of libraries referenced to a minimum, since I need to build and include them on my target Linux system.<br /><br />So my solution was to accept the limitations of the printf function and write a wrapper function that hides the buffer setup and string creation:<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>#include <string><br />#include <stdarg.h><br />#include <stdio.h><br /><br />string FormatString(const string& format, ...) {<br /> char buffer[1024];<br /><br /> va_list arglist;<br /> va_start(arglist, format);<br /> int length = vsnprintf(buffer, sizeof(buffer), format.c_str(), arglist);<br /> va_end(arglist);<br /><br /> return string(buffer, length);<br />}<br /><br /></code></pre><br /><br />I've tucked this away in a nested namespace so I can invoke it easily when needed. Now when I need formatted text I can just supply a c string or std::string format and my parameters, and get back a nice std::string instance in return. But there's a catch! I can't pass in a std::string as a parameter because the old-school c variable argument list can't handle objects. If I try to do that, I will get a “<tt>warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime</tt>” warning and a segmentation fault at runtime. The work around (at least for std::string objects) is to invoke the <tt>c_str()</tt> method on the string parameter instance. So for example<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> string argument = "a string instance";<br /> string result = FormatString("I can format a %s parameter!", argument.c_str());<br /></code></pre><br /><br />allows me to supply std::string arguments as well. The <tt>c_str()</tt> function returns a pointer to a temporary buffer containing a c style string version of the string object's value.<br /><br />So now I have my template style formatting and I can move on with my project. This project is my first foray into any substantial C++ programming, so if you seen any glaring problems or know a better solution, or if this little tip helped you too, please let me know by leaving a comment.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com2tag:blogger.com,1999:blog-3441881071717960329.post-86520607343104290632009-10-06T04:09:00.000-07:002009-10-06T04:36:53.271-07:00MonoDevelop Custom Color SchemesI have been playing with <a href="http://monodevelop.com/">MonoDevelop</a> 2.0 on Ubuntu on and off for a while now, but one of the things I find most annoying (other than not having <a href="http://www.jetbrains.com/resharper/index.html">ReSharper</a>) is there is no easy way to modify the colors used for syntax highlighting. Sure, it has several pre-defined schemes you can choose from (Using Edit | Prefrences > Text Editor > Syntax Highlighting), but changing individual syntax element colors using the GUI is not possible.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLMBKpacX-GllAc8QFL4PFtl7NJRORzHaAPrWD75ehZsGnOcRQP2ZcdIBlw2s9V0C-Rl-ZEtim9Gt7-Z8cPJO7Gpbot7E34nXgtKFtv8sbWbvPTpH97rcYp_pT3vyZHbajk227OL8_RZw/s1600-h/MonoDevelop-SyntaxHighlighting.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLMBKpacX-GllAc8QFL4PFtl7NJRORzHaAPrWD75ehZsGnOcRQP2ZcdIBlw2s9V0C-Rl-ZEtim9Gt7-Z8cPJO7Gpbot7E34nXgtKFtv8sbWbvPTpH97rcYp_pT3vyZHbajk227OL8_RZw/s400/MonoDevelop-SyntaxHighlighting.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5389446784648814690" /></a><br />The reason I find this issue annoying is that I like to have comments and strings really stand out – in our shop we avoid comments as much as possible, and string constants are kept to a minimum, so I like to be able to see them easily in the code. A few years ago, I started using “highlighter” background colors for comments and strings, and have become quite attached to them ever since.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwMOHJ1JTDfN2NJyQVEJaDoWch_KPo_tMADKtymcBpl-Nw-UajIvsqRvl_utr6zIwQx3GKHUnXNFx7SL434mZh9DpuvZTccNtIW9VZws4Bexj5U0vLt5OfoyDIyb9Sdrkv7AIfdt_3VCU/s1600-h/MonoDevelop-Highlighting.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 175px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwMOHJ1JTDfN2NJyQVEJaDoWch_KPo_tMADKtymcBpl-Nw-UajIvsqRvl_utr6zIwQx3GKHUnXNFx7SL434mZh9DpuvZTccNtIW9VZws4Bexj5U0vLt5OfoyDIyb9Sdrkv7AIfdt_3VCU/s400/MonoDevelop-Highlighting.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5389446981935477042" /></a><br />After many attempts to find a solution on the web, I finally found all the pieces I needed to make it happen. The basic problem is that although MonoDevelop allows you to add new color schemes, the format of the scheme file is not well documented, and there are a few tricks you need to know to make it work correctly. The existing schemes are embedded resources and not stand alone files, so they can't be easily viewed for reference. Finally, I discovered this <a href="http://ubuntuforums.org/showthread.php?t=349477">Ubuntu Forum thread</a> that helped me find the solution. The first piece of the puzzle was discovering the <a href="http://anonsvn.mono-project.com/viewvc/branches/monodevelop/main/2.0/src/addins/Mono.Texteditor/Styles/">color scheme XML source files</a> in MonoDevelop's SVN tree. Now I had some samples to go by. Another useful tidbit from that thread was that the file name must end in "Style.xml" in order to work correctly. I did not actually verify that this was required, but I did it just to be safe. The rest came from a <a href="http://monodevelop.com/Developers/Articles/Syntax_Mode_Definition">MonoDevelop Developer's Article</a> page I stumbled across shortly thereafter. One of the important things mentioned on that page is that you need to put the color scheme XML file in the <code>~/.config/syntaxmodes</code> directory (although in my Ubuntu installation it is actually <code>~/.config/MonoDevelop/syntaxmodes</code>). Now I had everything I needed to start tweaking colors!<br /><br />The first thing I did was download the VisualStudioStyle.xml file and renamed it to TeknynjaStyle.xml. Next I edited the file to change the <code>name</code> and <code>_description</code> attributes of the <code>EditorStyle</code> tag so they would not clash with the existing styles in the GUI. Finally, using the information from the MonoDevelop article and the existing examples, I modified the colors for comments and strings to get the highlighting I was looking for:<br /><br /><pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"><code> <Style name="comment" color="black" bgColor="#ffff80"/><br /> <Style name="comment.doc" color="black" bgColor="#ff8040"/><br /> <Style name="comment.tag.doc" color="black" bgColor="#ff8040"/><br /><br /> <Style name="text.preprocessor" color="purple"/><br /> <Style name="text.markup" color="skyblue"/><br /> <br /> <Style name="constant" color="black"/><br /> <Style name="constant.language" color="keyword-blue"/><br /><br /> <Style name="string" color="black" bgColor="#80ff80"/><br /> <Style name="string.single" color="black" bgColor="#80ff80"/><br /> <Style name="string.double" color="black" bgColor="#80ff80"/><br /> <Style name="string.other" color="black" bgColor="#80ff80"/><br /> <br /> <Style name="keyword" color="keyword-blue"><br /> <Style name="type" color="#004080"/><br /> </Style><br /></code></pre><br />I found the "bgColor" attribute by looking in one of the other color scheme files. Then I copied my customized color scheme file to ~/.config/MonoDevelop/syntaxmodes, restarted MonoDevelop, and selected my color scheme. I was able to tweak the colors by editing the XML file and restarting MonoDevelop until I achieved the scheme I was looking for. Finally I had the highlighting I was used to in Visual Studio, and along with modifying some of my commonly used key bindings, I was able to make MonoDevelop feel a little more like "home".teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com4tag:blogger.com,1999:blog-3441881071717960329.post-80814850998812973082009-06-03T14:08:00.001-07:002009-06-03T14:16:21.100-07:00To Protect and Surf (dnsmasq and Whitelists)Contrary to popular rumor, I am still alive and very busy – from about October of last year until last month I have been buried at work (a good thing in this economy!). Maybe now that I can see a little daylight, I can try to keep this blog updated a little more frequently. Enough with the excuses and on with the post.<br /><br />The only person in this house that likes to spend more time on the computer than me is my 4 year old son. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGAnA0Vglzd8BYSf4WbYvGKO5Kcmh2p947Kqr3lwJbwPDJajLmu3CPEgoqP-ape12KJqtiRwF0rcX1KvvPIYf7dlpnvqDzOULX55qUqZi-OWSMiha7cyYEbdPczxlx_5fZDSclhvMtseM/s1600-h/MJ_Tucker.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGAnA0Vglzd8BYSf4WbYvGKO5Kcmh2p947Kqr3lwJbwPDJajLmu3CPEgoqP-ape12KJqtiRwF0rcX1KvvPIYf7dlpnvqDzOULX55qUqZi-OWSMiha7cyYEbdPczxlx_5fZDSclhvMtseM/s320/MJ_Tucker.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5343211448548164930" /></a> Most of the time he is content to play an old copy of <a href=http://en.wikipedia.org/wiki/Monster_Truck_Madness_2 target=”_blank”>Monster Truck Madness 2</a> that I picked up years ago, but he also likes to spend time at <a href=http://www.dan-dare.org/FreeFun/ target=”_blank”>Dan-Dare.org</a>, <a href=http://atv.disney.go.com/playhouse/index.html target=”_blank”>Playhouse Disney</a>, <a href=http://pbskids.org/ target=”_blank”>PBS Kids</a>, and several other sites. The problem (other than trying to limit his time on the computer) is that he also likes to explore. When he gets bored just playing the games, he's off checking out what each menu item and dialog box does. He has explored all the configuration options in the monster truck game, and he is always playing with the volume control applet – I've spent plenty of time trying to undo his changes on the <a href=http://www.teknynja.com/2008/04/vintage-tv-mod-part-i.html target=”_blank”>kid's computer</a>. Lately, he has also taken to checking out the various links on the websites he visits. A couple of times he has run in to inform us that we can get a free monster truck game, and when we go check on him he has wandered off to some obscure website. Well, it happened again today, and although I've always known I would have to take action, today was the day to do something about it.<br /><br />Being the cheap bastard that I am, I needed a free solution that would keep him (or my 7 year old daughter) from visiting places on the web that I would rather not have them be for now. I decided that what I need for now is a DNS forwarder with a whitelist, so that only the sites on the list can be accessed. Although the following solution is fine for small kids, anyone with an 8088 for a brain can figure out how to get around this. Even so, it should work for us for the next few years.<br /><br />A little surfing pointed me to <a href=http://thekelleys.org.uk/dnsmasq/doc.html target=”_blank”>dnsmasq</a>, a very popular dns forwarding server. A little more research indicated that using it to whitelist domains was not easy – there is no built-in way to do it. I found someone who listed a source patch to make it happen, but I didn't want to go to that extreme if I could avoid it. Despite this, I went ahead and installed it on my file server (running Ubuntu, of course) using <code>sudo apt-get install dnsmasq</code>. Looking at all the options in the man page and in the /etc/dnsmasq.conf file was overwhelming at first, but it didn't take too long to figure things out. One of the things I discovered was that you can assign specific outside DNS servers for specific domains. I realized that if I blocked off any other way for it to resolve domain names except for this feature, I could use it like a whitelist! A little experimenting proved that it did indeed work. Here is the dnsmask.conf that I am using right now:<br /><code><br />domain-needed<br />bogus-priv<br />log-queries<br />log-facility=/var/log/dnsmasq.log<br />no-resolv<br />interface=eth0<br /><br /># Add other name servers here, with domain specs if they are for<br /># non-public domains.<br />#server=/localnet/192.168.0.1<br />server=/google.com/192.168.0.1<br />server=/dan-dare.org/192.168.0.1<br />server=/dan-dare.net/192.168.0.1<br />server=/pbskids.org/192.168.0.1<br />server=/playhousedisney.com/192.168.0.1<br />server=/disney.go.com/192.168.0.1<br />server=/starfall.com/192.168.0.1<br /></code><br /><br />The first few lines do the actual configuration of dnsmasq, domain-needed & bogus-priv block Windows machines from passing noise traffic, log-queries & log-facility tell dnsmasq to log all DNS requests to the /var/log/dnsmasq.log file (useful for determining the domains required by websites, but this can be turned off to save space), no-resolv tells it to ignore the resolv.conf file which usually lists the outside DNS servers to use, and finally interface tells the service which network interface to bind to.<br /><br />The rest of the “server” lines implement the whitelist, telling dnsmasq to look for the specified domain's IP address using the specified DNS server. In this case, I simply pointed to the DNS server in my local network's router (192.168.0.1). Any other domains are simply returned as being invalid. To populate this list, I simply attempted to browse to the sites my children visit, and then looked in the /var/log/dnsmasq.log file to see what domains were being requested, then entered them into the dnsmasq.conf file. After each update to the configuration file, I needed to <code>sudo /etc/init.d/dnsmasq restart</code> to get the service to re-read the file.<br /><br />The final step was to change the DNS server address on the kid's computer to point to the file server's IP address, and that was it – now anytime they “accidentally” try to access a domain not in the list, they get a message saying the domain was not found. Of course any computer-savvy person could simply set the DNS server to something else (like <a href=http://www.opendns.com/ target=”_blank”>OpenDNS</a>!), but it will probably be a few years before my kids figure that out. If they want to visit someplace new, I have to intervene (which is what I want). In a few more years, I will have to be more creative to keep ahead of the kids and to keep my workload down updating the list – but for now this works for me.<br /><br />So hopefully, if there are other people like me searching for a way to add whitelisting to their dnsmasq forwarders, maybe this post will be a starting point. If you have any questions, go ahead and leave me a comment or send me an email, I'll do my best to help. And maybe if things slow down a little there will be more frequent posting around here as well.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com7tag:blogger.com,1999:blog-3441881071717960329.post-57288930803709228022008-09-28T07:10:00.000-07:002008-09-28T07:33:52.934-07:00Ubuntu Photo Frame<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6UZcnVzdxw3AUJnvfWrpqns5CXDKGZxCXaWDC-Ow2lzTEVX74fAchEuHtZSEar-qTw2QsnxRcxf7qtlc7UV_sXP576jTzuXveBXakK5hVuvGTvQohXThJu4kHCO5TXxXsBUZ-_9qpeeI/s1600-h/Teknynja-PhotoFrame.png"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6UZcnVzdxw3AUJnvfWrpqns5CXDKGZxCXaWDC-Ow2lzTEVX74fAchEuHtZSEar-qTw2QsnxRcxf7qtlc7UV_sXP576jTzuXveBXakK5hVuvGTvQohXThJu4kHCO5TXxXsBUZ-_9qpeeI/s320/Teknynja-PhotoFrame.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5251075019965103730" /></a><br />About two years ago I converted an old laptop into a photo frame for the living room. There are plenty of examples of how to do this floating around on the web these days, so I am not going to cover that here. What I am going to talk about are the software aspects of this project, and my recent upgrade of my photo frame.<br /><br />The frame had been working fine for almost two years, but a few months ago I upgraded my WiFi network at the house to WPA (finally), but that meant that I could no longer transfer files to the frame because the WiFi card I was using in it only supported WEP. Shortly after that, the frame started acting strangely, turning itself off about once a day, then finally not booting at all with the infamous “missing file” messages you get when Windows can't read the hard drive correctly.<br /><br />The original software setup for this project was Windows 2000 with a small .NET application I wrote to scan a directory and display pictures from it. When it was time to display the next photo, the program would scan the directory and pick a new picture at random to display. The laptop hardware did not have enough “horsepower” to handle any kind of transitions or fades between photos, so the program just displayed the next photo on the screen without any transitions.<br /><br />I brought the frame back to my cave, where I confirmed that the hard drive had indeed given out. I ordered a SYBA SY-IDE2CF-NB25 Ultra IDE to Compact Flash Adapter from <a href=http://www.starsurplus.com/ target=”_blank”>StarSurplus</a>, and with a 4GB Compact Flash card I had laying around, I now had a solid state hard drive for the frame. I also ordered a <a href=http://www.newegg.com/Product/Product.aspx?Item=N82E16833315047 target=”_blank”>EDIMAX EW-7108PCg 802.11g/b Wireless LAN PC Card</a> from NewEgg to allow WiFi access to the frame again. I selected this card because it is well supported under Linux and it is very inexpensive. Now that I had all the hardware ready, time to re-install the software.<br /><br />I wanted to use Ubuntu for this project, because I am familiar with it, and this would give me an opportunity to learn about doing a very minimal installation. My goal was to use as little space on the flash drive as possible for the OS and supporting programs to leave room for photos. After a few practice runs setting up the system and trying different programs, I came up with the following recipe.<br /><br />First, I installed Ubuntu Server, with the OpenSSH and Samba options. The server edition of Ubuntu doesn't install any kind of GUI (just a command prompt) and none of the heavy applications like OpenOffice, Evolution, etc. Then I got the Wifi card working (it wasn't detected during setup) and performed an upgrade to make sure I had the latest security patches. I setup Samba to allow access to the folder containing the pictures to be displayed. Next I apt-get installed xorg, dnotify, and feh. <a href=http://freshmeat.net/projects/feh/ target="_blank">feh</a> is a small, lightweight image display program for X. While playing around with different configurations, I discovered that even under Ubuntu, this laptop just didn't have what it takes to display transitions between photos, and so feh fit the bill almost perfectly.<br /><br />I tweaked the xorg.conf file to prevent it from blanking the screen (I think it defaults to blank after 10 minutes), copied some photos to the frame, and fired off feh using xinit. And my photo slide show started up! The only problem with feh is that it only reads the files in the directory when it starts up, so if I add pictures to the directory later, I would have to restart the program in order for them to be shown. So I created the following script using <a href=http://manpages.ubuntu.com/manpages/hardy/man1/dnotify.html target="_blank">dnotify</a> to restart the program whenever any files in the folder have changed.<br /><pre><br />#!/bin/bash<br />export HOME=/home/teknynja<br />while true; do<br /> killall -q feh<br /> sleep 1<br /> xinit /usr/bin/feh -rzFZD180 --hide-pointer /home/teknynja/Pictures &<br /> dnotify -MCDRro /home/teknynja/Pictures<br />done<br /></pre><br />I made the script executable, and added a line to invoke the script from inside /etc/rc.local so that it would run when the system started up. After a couple of days of testing in the cave, I put everything back together and it is now back in the living room, displaying our family photos once again. It also has the added bonus of being completely silent, due to the solid state hard drive. The total space budget on the flash drive was 645MB for the OS and supporting programs, leaving around 3GB for photos, which is more than enough for now.<br /><br />Once again I warn the readers that I still have a lot to learn about Linux, so any constructive comments are appreciated. If you have any questions or would like more details about this project, feel free to leave a comment and I will try to help you if I can.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com1tag:blogger.com,1999:blog-3441881071717960329.post-63909327363505057442008-09-08T05:43:00.000-07:002008-09-08T05:47:11.260-07:00Obscure Ubuntu Tip: CRON User account has expiredNo, I haven't forgotten that I have a blog. I've just been keeping busy with a lot going on at work, and a backlog of “projects” at home after finishing up the <a href=http://www.teknynja.com/2008/06/kitchen-mod-update.html target=”_blank”>kitchen project</a>. Some of those projects have involved getting down-and-dirty with Ubuntu, and I thought I would share a quick tip I discovered yesterday.<br /><br />I was looking through the system log (/var/log/syslog) on one of my servers and I noticed it was full of “CRON[xxxx]: User account has expired” messages. A little searching on the web pointed to the fact that the root account had been locked. While setting up this server, I had followed some instructions I found on the web that required me to unlock the root account, then re-lock it when I was done with the <pre>sudo passwd -l root</pre> command. Locking an account this way also causes the password to be expired, one of the results of which is the above mentioned log entries. Most of the solutions I found on the web involved either unlocking the root again and giving it a long, random password, or manually editing the password files. I think I've found the correct way to fix this though, by using the <pre>sudo chage -E-1 root</pre> command, which sets the root's password to never expire. (Note that the -1 is negative one, not dash L). After using the above command, the system log showed normal CRON log entries, and the root account remained locked.<br /><br />I hope someone else will find this information to be of use. That's it for my very obscure Ubuntu tip. Join me again soon for another exciting post. I actually have a good sized list of topics to cover on the blog, so hopefully things will settle down and you will hear more from me soon. Thanks for stopping by!teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com16tag:blogger.com,1999:blog-3441881071717960329.post-16746640250126528612008-06-29T08:39:00.000-07:002008-06-29T10:07:15.476-07:00Picture Perfect<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOu2NUDWaA2e8xIqMWLcNGH-ZCSRZUQacFuq-4Tj8xNeJG4Op9LFUDJwjF3ZPIAL3u2hYGSbpNiZlKkyyOt0yjQOUbxJNsU1b9TLnlM6B7VV1SkKEtKmRnnhUgU342bM4gETMjB8fG6KA/s1600-h/canonsd870is.jpg"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOu2NUDWaA2e8xIqMWLcNGH-ZCSRZUQacFuq-4Tj8xNeJG4Op9LFUDJwjF3ZPIAL3u2hYGSbpNiZlKkyyOt0yjQOUbxJNsU1b9TLnlM6B7VV1SkKEtKmRnnhUgU342bM4gETMjB8fG6KA/s320/canonsd870is.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5217329102130951362" /></a><br />This past Father's Day I received a shocking but pleasant surprise – a shiny new <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2FCanon-PowerShot-SD870IS-Digital-Stabilized%2Fdp%2FB000V1XICU%3Fie%3DUTF8%26s%3Delectronics%26qid%3D1214753795%26sr%3D8-2&tag=teknynja-20&linkCode=ur2&camp=1789&creative=9325" target="_blank">Canon SD870IS ELPH</a><img src="http://www.assoc-amazon.com/e/ir?t=teknynja-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> point and shoot camera! The shocking part was due to the fact that my wife never buys technology for me, because I am so picky about my gadgets. The pleasant part is because I've been looking to replace our old SD200 that we've had for years. We both loved that camera because of it's small size, ease of use, and fast response time (when you have two fast-moving little ones, it helps to have a camera that can capture an photo right when you press the shutter release). We've also shot hours of video with the SD200, because even though we have a nice Sony camcorder, we never feel like lugging it around with us. The video quality is more than acceptable and it allows us to capture moments we would never have been able to with something larger. The SD200's 3.2 mega-pixel sensor worked fine for the kinds of shots we take.<br /><br />So enter the SD870IS. The coolest feature about this camera is the “IS” at the end – Image Stabilization. For normal shooting it helps eliminate blur and even works on the large, bright 3” screen. (I was always jealous of other camera's big screens when all I had was the SD200's 2.5” screen). But the stabilization really comes in handy for shooting video. With such a small device, shaking is always a problem on video. The old camera's video always had a lot of shake and could be annoying to watch sometimes, but this new camera shoots nice, steady video that is wonderful to watch! And for photos, the 8 mega-pixel sensor allows us do more with printing and cropping than we could ever do before.<br /><br />Over the years since the SD200 was introduced, Canon has added tons of cool little features to the software, too numerous to mention here, but several new shooting modes, and auto adjusting the image orientation while reviewing images are a couple of them that I really appreciate. The SD870IS still has some of the same issues as it's older cousin, most notably it's mediocre low light performance But overall, I am excited to have this cool new toy to play with, and I'm no longer lusting over the other cameras I see when we take the kids to Disneyland! Thanks Honey!teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-14329674355321310752008-06-17T12:30:00.000-07:002008-06-20T13:33:36.095-07:00Video Sedation<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4Aa-Q9hS1X9wo9ABKSH8MNOslB-D-G0SEoh9C012X0bvsyh-YTMzI9glBM8Q5iR4d9SPPmdstfPjYszBrPJaGtiSfsC_RhCx0sEZFtoO0EMChNhiv4lKm5e3Zn6G2f6LbORIvieUNTk/s1600-h/sansa250.jpg" target="_blank"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4Aa-Q9hS1X9wo9ABKSH8MNOslB-D-G0SEoh9C012X0bvsyh-YTMzI9glBM8Q5iR4d9SPPmdstfPjYszBrPJaGtiSfsC_RhCx0sEZFtoO0EMChNhiv4lKm5e3Zn6G2f6LbORIvieUNTk/s200/sansa250.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5212937869748919938" /></a><br />During one of <a href=http://www.woot.com/ target=”_blank”>Woot</a>'s last “Woot-Offs”, I picked up a couple of Sansa E250 media players for the kids to watch videos on when we need them to be calm and quite (like during visits to Ikea). They each already have a <a href=http://www.amazon.com/gp/search?ie=UTF8&keywords=sansa%20shaker&tag=teknynja-20&index=blended&linkCode=ur2&camp=1789&creative=9325 target="_blank">Sansa Shaker</a><img src="http://www.assoc-amazon.com/e/ir?t=teknynja-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> loaded with their favorite songs (Tucker seems very fond of his blue “radio”), but video is a much more effective way to keep them “sedated”. In the past, I used my <a href=http://en.wikipedia.org/wiki/HTC_Wizard target="_blank">T-Mobile MDA</a> with several hours of their favorite movies loaded on it to keep them occupied – but they both had to share the screen and I didn't like the idea of them fondling my phone and possibly dropping or otherwise injuring it.<br /><br />For $30 bucks each during the woot-off, I figured I couldn't go wrong, so I ordered two of them. I quickly discovered that the built-in firmware for these players could only handle video encoded using Apple Quicktime DLLs that I have so far managed to keep off my system. Plus, the compression of the supported format was so bad that I could have only put a few minutes of video in the limited 2Gb of memory the devices contain.<br /><br><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href=http://www.rockbox.org/ target="_blank"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9FPfMNlRz2NASUVeKOYBukGL2YJQLPoyGg4UBjQVWgPzpZ_iL9Clxn6e8_2ugV8z4RzRqyOEAAcR0IFlJnMnf8Xa-RavZLEbUb14_ySlmehYKJVXxeRBTIy5Cl93wt10ZUZPhRciI4kE/s200/rockbox.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5212938529420553778" /></a><br><br />Here's were <a href=http://www.rockbox.org/ target=”_blank>Rockbox</a> saves the day. Before I pressed the shiny “I Want One” button on Woot, I did a little research and discovered this project and found it supports the players I was about to purchase. I went ahead an placed my order for two, then within hours of their arrival, I had the Rockbox firmware installed on them. I played with the software, tweaking the many settings and options the firmware provides.<br /><br />Finally it was time to put some videos on the devices. It took a while to figure out the optimal encoding options for these devices, but after playing around for a few hours I arrived at the following settings:<br><br /><table border="1"><br /> <tr><br /> <td>Video Encoding Format</td><br /> <td>MPEG2 (RockBox only supports this for now)</td><br /> </tr><br /> <tr><br /> <td>Video Resolution</td><br /> <td>224x176</td><br /> </tr><br /> <tr><br /> <td>Video Bitrate</td><br /> <td>192 kbps</td><br /> </tr><br /> <tr><br /> <td>Video Frame Rate</td><br /> <td>25 fps</td><br /> </tr><br /> <tr><br /> <td>Audio Encoding Format</td><br /> <td>MPEG-1 Layer 2</td><br /> </tr><br /> <tr><br /> <td>Audio Samping Rate</td><br /> <td>44100 Hz (other samping rates break mpeg 2 compatibility)</td><br /> </tr><br /> <tr><br /> <td>Audio Bitrate</td><br /> <td>64 kb/s, Monophonic</td><br /> </tr><br /></table><br /><br />Although this results in some serious visual artifacts, this is perfectly fine for the kids to watch (they haven't complained yet!). These settings allow me to cram several hours of video onto the players. The only thing I haven't figured out yet is how long the batteries last during video playback – the longest stretch of time the kids have watched the devices is about 90 minutes during a drive back from Grandma's House.<br /><br />I figured I should share this little tip in case anyone else needs to administer some “video sedation” of their own while out in the world. As always, any tips and suggestions are always appreciated in the comments.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com1tag:blogger.com,1999:blog-3441881071717960329.post-80697311231600496362008-06-17T11:39:00.000-07:002008-06-18T05:36:06.201-07:00Kitchen Mod Update<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpZWVVfnRZr5Xy6F1KsuDyBMabsML6LFpb-3OUSo4ufRkSdjKpgdbJjmbpS59q2fdAhOe_UOd73H14AFNdk9P6F3r8gd6mK3v3NPug0erBCnuAS5mHD4buzWfQUtc4xlLjCDSqYG4IYhI/s1600-h/kitchen0617.jpg" target="_blank"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpZWVVfnRZr5Xy6F1KsuDyBMabsML6LFpb-3OUSo4ufRkSdjKpgdbJjmbpS59q2fdAhOe_UOd73H14AFNdk9P6F3r8gd6mK3v3NPug0erBCnuAS5mHD4buzWfQUtc4xlLjCDSqYG4IYhI/s320/kitchen0617.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5212922322657122370" /></a><br />Sorry I haven't been posting in a while, but once I got started on the kitchen, every free moment after work was devoted to it. I finally finished all the tough stuff last week, all that's left to do is convert a can light in the ceiling to a hanging lamp that Kelly picked out at Ikea (where else?) The granite people came out last week and attached the sub-tops and made templates, but we are still waiting for them to contact us so we can choose the layout. But even with just the sub-tops (read plywood), life with an island in the kitchen is much better. You can see more details on our kitchen project on <a href=http://www.ikeafans.com/blogs/shire/ target=”_blank”>Kelly's blog at IkeaFans</a>. It isn't up to date with the latest pics yet, but you can get an idea of what I've been up to the last few weeks.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-20045952559974977822008-05-02T22:39:00.000-07:002008-05-02T23:14:34.287-07:00Vintage TV Mod, Part III<a href=http://www.teknynja.com/2008/04/vintage-tv-mod-part-ii.html>Last time</a>, I mounted the LCD display to the front panel and got a pretty good looking test out of it. Now it's time to put the computer electronics and knobs on this thing. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_15_driveMounts.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_15_driveMounts.jpg" border="0" alt="" /></a>First up, I built up a bracket to hold the hard disc and CD-ROM drive. This arrangement turned out to be nice and stable, and allowed me to use a vibration dampening 3.5” to 5.25” drive adapter kit to help keep the hard drive quite. I then mounted the drive cage, mother board, and power supply to a piece of 1/4” MDF that I had pre-cut to fit inside the cabinet where the old chassis used to be, making sure to leave room for the LCD monitor. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_16_subpanelLayout.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_16_subpanelLayout.jpg" border="0" alt="" /></a> I used a large, quite <a href=http://www.zalman.co.kr/eng/main.asp>Zalman</a> CPU fan to keep noise to a minimum. Once everything was mounted to the sub-panel, I placed it inside the cabinet and screwed it down. Next, I built a small shelf for the bottom half of the cabinet where the speakers would sit. A couple of lengths of aluminum L channel span the width of the cabinet, and a small piece of MDF forms the shelf. I purchased a cheap 2.1 Logitech speaker system, and screwed the speakers to the shelf, facing out through the old speaker grill. I put a piece of black electrical tape over the power lamp to keep it from showing through the grill cloth.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_17_speakerMount.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_17_speakerMount.jpg" border="0" alt="" /></a><br />Next, I purchase some potentiometers from the ultra cool surplus store <a href=http://www.goldmine-elec.com/>Electroncs Goldmine</a>, three with a momentary push switch feature, and one dual potentiometer to be used as the volume control. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_19_controlParts.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_19_controlParts.jpg" border="0" alt="" /></a> Two of the potentiometers were just dummys to hold the knobs, although they could be used for something in the future. The remaining switch-pot was wired up to the power switch connections on the mother board, so I could turn the computer on and off by simply pressing the knob. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_22_volumeWiring.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_22_volumeWiring.jpg" border="0" alt="" /></a> The dual potentiometer was wired up as an attenuator with a standard stereo 3.5mm plug on one side, and a 3.5mm stereo jack on the other side. The plug then connected to the line out on the mother board, and the speakers plugged into the plug on the other end. Now I have a nice physical volume control, just like the original set! <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_20_knobHack.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_20_knobHack.jpg" border="0" alt="" /></a> I had to grind off the back of the volume knob to get it to fit onto the short shaft of the audio pot, but the other shafts fit perfectly into the original knobs that came with the tv. <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_23_powerVolumeWiring.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_23_powerVolumeWiring.jpg" border="0" alt="" /></a> I used short pieces of aluminum L channel to mount the pots to the front panel, then adjusted the depth of the shafts using the nuts to get the knobs just the right distance from the front panel.<br />Once I had all the mechanical aspects taken care of, I mounted a power strip to the under side of the chassis shelf and plugged everything into that, so I would only have one cord leaving the cabinet. A WI-FI card was used for the network connection, and a wireless keyboard and mouse was added, so that only only the power cord came out of the back of the TV. As a final touch, I mounted an amber LED at the bottom of the cabinet where the old power lamp used to be, and drove it off the Power LED connection on the motherboard. I tracked down old <a href=http://en.wikipedia.org/wiki/Indian_Head_test_card>Indian Head test pattern</a> for the desktop wallpaper, and it was done. The kids have watched countless movies and hours of TV on the set via the <a href=http://www.slingmedia.com/>SlingBox</a>, and an old, broken TV was given a new life.<br/><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_26_afterFront.jpg"><img style="float:center; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_26_afterFront.jpg" border="0" alt="" /></a><br/>I hope this project inspires others to take the plunge and put computers in other unexpected places. If you do, post a comment or send me an email to let me know about it.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com3tag:blogger.com,1999:blog-3441881071717960329.post-35537339878875783152008-04-26T04:59:00.000-07:002008-05-02T23:13:26.602-07:00Ubuntu 8.04 Hardy Heron Synergy Client SetupIn the Teknynja cave I have a MS Windows XP box with two monitors (my main development system) and a Ubuntu box with one monitor (my Internet offload system). I use <a href=http://synergy2.sourceforge.net/>Synergy</a> to control the Ubuntu system using XP's mouse and keyboard. Since the Ubuntu box doesn't have a keyboard or mouse connected to it, a little hacking is required to get the Synergy client running before the login screen. I've been doing this with my Ubuntu 7.04 system for a while, and now that I am setting up a <a href=http://www.teknynja.com/2008/04/waiting-for-heron.html>replacement Ubuntu 8.04</a> system, I thought I would document the Synergy client setup for future reference. It should be noted that I installed Ubuntu Hardy Heron from the Alternate CD, but that should not make a difference for this procedure. I also assume that you already have the Synergy keyboard/mouse server configured and running somewhere on your network.<br /><br />First, install Synergy on the Ubuntu system using:<br /><code><br />sudo apt-get install synergy<br /></code><br />Then edit the gdm initialization file:<br /><code><br />sudo nano /etc/gdm/Init/Default<br /></code><br />and add the following lines just before the “sysresources=/etc/X11/Xresources” line<br /><code><br />/usr/bin/killall synergyc<br />sleep 1<br />/usr/bin/synergyc xxx.xxx.xxx.xxx<br /></code><br />where xxx.xxx.xxx.xxx is the IP address of your server machine.<br /><br />Now edit the gdm pre-session file:<br /><code><br />sudo nano /etc/gdm/PreSession/Default<br /></code><br />and and the following line just before the “XSETROOT='gdmwhich xsetroot'” line<br /><code><br />/usr/bin/synergyc xxx.xxx.xxx.xxx<br /></code><br />Make sure the Synergy server is configured and running on your keyboard/mouse system, and reboot the Ubuntu system. You should now be able to move the mouse over to the Ubuntu screen and login normally.<br /><br/><br />Note that I still consider myself a Ubuntu/Linux noob, and so any improvements/comments/suggestions you have about this post are greatly appreciated. Ymmv. Most of the help I needed setting up this configuration came from the <a href=https://help.ubuntu.com/community/SynergyHowto>Ubuntu Synergy How To</a> page.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com6tag:blogger.com,1999:blog-3441881071717960329.post-68703644779273936562008-04-25T12:08:00.000-07:002009-01-13T06:21:18.008-08:00Vintage TV Mod, Part IIIn our <a href=http://www.teknynja.com/2008/04/vintage-tv-mod-part-i.html>last installment</a>, I gutted the old television cabinet and prepared it for the updated electronics. This time, I'll cover the real heart of this mod, the LCD display.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_09_facePrep.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 240px;" src="http://www.mykrotek.com/teknynja/otv/otv_09_facePrep.jpg" border="0" alt="" /></a>I removed the old CRT bezel from the front panel of the TV, because even though it would have looked cool to have an old-fashioned round screen, it would have covered some of the essential parts of the display, like the menus and title bar controls. I had an old 15” LCD monitor sitting out in the garage after I updated to a wide screen monitor on my workstation, so I grabbed it and checked to make sure that it would remember its power state when the AC was removed – I didn't want to have to be constantly pressing a button to turn the monitor on.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_10_lcdPrep.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 240px;" src="http://www.mykrotek.com/teknynja/otv/otv_10_lcdPrep.jpg" border="0" alt="" /></a>After verifying that that the power worked as needed, I disassembled the monitor case and removed the screen and electronics. I then used some standoffs to mount the control buttons on the back of the monitor, so I would be able to access them from inside the case once it was mounted in the cabinet.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_11_lcdButtons.jpg"><img style="float:left; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 240px;" src="http://www.mykrotek.com/teknynja/otv/otv_11_lcdButtons.jpg" border="0" alt="" /></a>The actual display panel was a little bit smaller than the glass opening at the front of the TV, so I found a simple black picture frame to act as a bezel and mounted it to the front panel. I was then able to use the original mounting tabs on the LCD panel to attach it to the picture frame.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_12_lcdTestFit.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 240px;" src="http://www.mykrotek.com/teknynja/otv/otv_12_lcdTestFit.jpg" border="0" alt="" /></a>You could still see a little of the metal frame of the LCD panel inside the frame, but it didn't look too bad, and I'd rather be able to see all the pixels on the screen anyway.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_13_lcdMount.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 240px;" src="http://www.mykrotek.com/teknynja/otv/otv_13_lcdMount.jpg" border="0" alt="" /></a>After getting everything mounted and placed back into the cabinet, I connected it up to power and a PC to see what the display would look like. Of course, I had to try out an old black and white movie on the newly mounted screen – the effect was rather convincing! Next time, on “This Old TV”, I'll show how I put the knobs back on and made them functional, as well as the replacement speakers for the set.<br/><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mykrotek.com/teknynja/otv/otv_14_lcdTest.jpg"><img style="float:center; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 320px;" src="http://www.mykrotek.com/teknynja/otv/otv_14_lcdTest.jpg" border="0" alt="" /></a>teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-91753525484680326412008-04-20T10:23:00.000-07:002008-05-02T23:16:23.338-07:00“Time” to GeekOne of my wife's friends traveled to England a few weeks ago, and brought back a special item that I requested. Just in case my status as a geek was in question, this item should eliminate any doubts. The item is my newly acquired Doctor Who 2008 Calendar.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyC_z-thf6iaS_bs86YPIXD7KzALSUMUIgb8L1XCILrKHzpym_iVnijjPDJvUlxKqtLJcZnLNkpi-M0R9gLkfLx0GNwGZ-Ym4hI9kDN7H8cApqRYT7vk3y93RJIK2CCOW42Bcc15TtOgU/s1600-h/drwhocal2008.jpg"><img style="float:right; margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyC_z-thf6iaS_bs86YPIXD7KzALSUMUIgb8L1XCILrKHzpym_iVnijjPDJvUlxKqtLJcZnLNkpi-M0R9gLkfLx0GNwGZ-Ym4hI9kDN7H8cApqRYT7vk3y93RJIK2CCOW42Bcc15TtOgU/s320/drwhocal2008.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5191380070011071986" /></a>I know, the year is already a third over, but I've been eying this calendar since before Christmas. The only reputable place I could find to order it online was Amazon UK, but the shipping was just too much. So when my wife's friend asked if there was anything I wanted when she went to England, I didn't hesitate. I have been a fan of the show since I was a young boy, watching episodes on Saturday mornings on the local PBS station, sometimes with my dad.<br>They say you imprint with your first doctor, which for me was Jon Pertwee, but my favorite doctor is actually Tom Baker, with his arrogant, Sherlock Holmes style. There is plenty on the web written about <a href=http://en.wikipedia.org/wiki/Doctor_Who>Doctor Who</a> and all the doctors, so I won't try to cover that ground again here. The original series ended in 1989, but a new series started up again in 2005, and I still look forward to each episode. I am also a big fan of the spin-off series <a href=http://en.wikipedia.org/wiki/Torchwood>Torchwood</a>, which is a great show in it's own right. Torchwood is a bit too adult for my little girl, but another Doctor Who spin-off, <a href=http://en.wikipedia.org/wiki/Sarah_Jane_Adventures>The Sarah Jane Adventures</a> is aimed at the younger set and usually keeps my daughter on the edge of the couch. And in case the whole Doctor Who thing doesn't cement my geek status, ask me to talk about <a href=http://en.wikipedia.org/wiki/Red_Dwarf_%28TV_series%29>Red Dwarf </a>or <a href=http://en.wikipedia.org/wiki/Blake%27s_7>Blake's Seven</a> some day.teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com0tag:blogger.com,1999:blog-3441881071717960329.post-45783438016545866122008-04-19T04:15:00.001-07:002008-05-02T23:17:46.573-07:00Vintage TV Mod, Part I<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_01_beforeFront.jpg"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_01_beforeFront.jpg" border="0" alt="" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_02_beforeBack.jpg"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_02_beforeBack.jpg" border="0" alt="" /></a>I've had this old 1943 RCA/Victor television set kicking around for many years now. When I first got it, you could actually watch tv on it, but after a year or so, it stopped working (probably desperately in need of a complete capacitor replacement). For years I was gonna do that as a project, but never got around to it. The set was used mainly as something to set knick knacks on for a long time until I finally had an idea – I would turn it into a meda pc for the kids. In the long run, it would probably be less work than fixing the old TV, and via my <a href=http://www.slingmedia.com/go/slingbox.html>Slingbox</a>, we would still be able to watch TV on it!<br /><br><br />First, I needed to gut the cabinet to make room for the new components.<br><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_03_beforeGuts.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_03_beforeGuts.jpg" border="0" alt="" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_04_gutsRemoved.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_04_gutsRemoved.jpg" border="0" alt="" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_05_pictureTube.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;height: 200px;" src="http://mykrotek.com/teknynja/otv/otv_05_pictureTube.jpg" border="0" alt="" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_06_emptyCabinet.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_06_emptyCabinet.jpg" border="0" alt="" /></a><br>These old TV's were built to be serviced, so getting the chassis out was simple, although I used a little extra caution around the old picture tube. I didn't want it imploding all over me, and I might be able to sell it on eBay some day.<br><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_07_faceRemoved.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_07_faceRemoved.jpg" border="0" alt="" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://mykrotek.com/teknynja/otv/otv_08_cabinetRepair.jpg"><img style="margin:10px 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px;" src="http://mykrotek.com/teknynja/otv/otv_08_cabinetRepair.jpg" border="0" alt="" /></a><br>Once gutted, I removed the front bezel and did a little repair to the side panel of the cabinet, which had come loose at some point. I guess I could have attempted to restore the case since it is so scratched up, but since this was going to be used by the kids (and because I am very lazy), I decided to leave it in it's “vintage” condition. In my next post, I'll cover getting the new LCD installed in the set. Stay tuned!teknynjahttp://www.blogger.com/profile/04303366246283189216noreply@blogger.com3