<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luc Stepniewski&#039;s Blog &#187; hardware</title>
	<atom:link href="http://www.gradstein.info/category/hardware/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gradstein.info</link>
	<description></description>
	<lastBuildDate>Thu, 29 Dec 2011 22:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.gradstein.info/?pushpress=hub'/>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to automatically run a script after inserting a USB device on Ubuntu?</title>
		<link>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/</link>
		<comments>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 21:32:01 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[hardware]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[hotplug]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[run]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[udev]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=35</guid>
		<description><![CDATA[Here&#8217;s the setup: you have a computer which has a SD port (small memory cards, mostly used in cameras, phones, etc.). You want to get all of your photos from that card automatically as soon as you insert your card (may be a USB key as well), that is, run a script which will search [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the setup: you have a computer which has a SD port (small memory cards, mostly used in cameras, phones, etc.). You want to get all of your photos from that card automatically as soon as you insert your card (may be a USB key as well), that is, run a script which will search for all of your photos, and copy them to a local directory.</p>
<p><span id="more-35"></span></p>
<p>I know, some programs already do this, but they require Xwindow and some <a href="http://f-spot.org/Main_Page" class="liexternal">ugly Gnome</a>/KDE app. What we&#8217;re doing here is a minimal setup, using the least memory.</p>
<p>Normally, on a normal Unix system you would use the included device detection mechanism, which is <a href="http://linux-hotplug.sourceforge.net/" title="Linux Hotplug project" class="liexternal">hotplug</a>. But on Ubuntu (at least <em>Gutsy</em> and <em>Hardy</em>), the de-facto/required way is by using <strong>udev</strong>, which is an event based system, using rules to fire new events/mount/symlink or run programs according to some patterns defined as &#8220;rules&#8221;.</p>
<p>So, the first thing to do is to identify your device according to USB events. udevinfo is your friend. So, after looking at the output of dmesg, you&#8217;ll see your USB device is available on some sd* device.</p>
<p>So run:<br />
<code> udevinfo -a -p  /sys/block/sda<br />
(replace sda with you device)</code></p>
<p>You will get a list of &#8220;blocks&#8221; representing each layer of drivers. For example:<br />
<code><br />
root@sleek:/etc/udev/rules.d# udevinfo -a -p /sys/block/sda/</p>
<p>looking at device '/block/sda':<br />
KERNEL=="sda"<br />
SUBSYSTEM=="block"<br />
DRIVER==""<br />
ATTR{stat}=="  229567    [...] 456048  3697068"<br />
ATTR{size}=="488397168"<br />
ATTR{removable}=="0"<br />
ATTR{range}=="16"<br />
ATTR{dev}=="8:0"</p>
<p>looking at parent device '/devices/pci0000:00/00[...]:<br />
KERNELS=="2:0:0:0"<br />
SUBSYSTEMS=="scsi"<br />
DRIVERS=="sd"<br />
ATTRS{ioerr_cnt}=="0x0"<br />
ATTRS{iodone_cnt}=="0xcc26b"<br />
ATTRS{iorequest_cnt}=="0xcc26c"<br />
ATTRS{iocounterbits}=="32"<br />
ATTRS{timeout}=="30"<br />
ATTRS{state}=="running"<br />
ATTRS{rev}=="3.AA"<br />
ATTRS{model}=="ST3250310AS     "<br />
ATTRS{vendor}=="ATA     "</code></p>
<p>These are in fact attributes that you can use in your rule to filter the devices. So for example,<br />
to run a shell script when a SCSI device is detected which has a size of 1GB, I&#8217;ll use the following line:</p>
<p><code>KERNEL=="sd?1", ATTRS{size}=="1999872", RUN+="/usr/local/bin/recup_usb.sh"</code></p>
<p>This line is to be put in a new file in /etc/udev/rules.d, named something like 91-backuptousbdrivetrigger.rules. It&#8217;s better to put the file at the end of the rules (the &#8220;91&#8243;), as not to disturb other module loadings.</p>
<p>The content of the recup_usb.sh file can be:<br />
<code><br />
#!/bin/bash</p>
<p>if [ "${ACTION}" = "add" ]; then<br />
   rm -rf /tmp/x<br />
   mkdir /tmp/x<br />
   mount -t vfat /dev/sdc1 /tmp/x<br />
   find /tmp/x -name "*jpg" -exec /usr/bin/rsync -avz {}  \<br />
              /home/foobar/Pictures/Incoming/`date +%Y-%m-%d`/ \;<br />
   umount /tmp/x<br />
fi</code></p>
<p><em>(yes, I know this code is dirty, I should have used mktemp, but you get the point&#8230;)</em><br />
Don&#8217;t forget to chmod +x the shell script and reload the configuration with:</p>
<p><code>udevcontrol reload_rules</code></p>
<p>For more detailed information about writing udev rules, take a look at the<a href="http://reactivated.net/writing_udev_rules.html" class="liexternal"> official documentation</a>, or <a href="http://tlug.dnho.net/?q=smeserver_udev_automated_backups" class="liexternal">another&#8217;s detailed information</a> about doing the same thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/hardware/how-to-automatically-run-a-script-after-inserting-a-usb-device-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HOWTO Installation of OpenWRT on a WGT634U usb router Part 2</title>
		<link>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router-part-2/</link>
		<comments>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router-part-2/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 08:05:51 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[hardware]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router-part-2/</guid>
		<description><![CDATA[OK, we now have to configure the network. The goal is to be able to connect to our access point, where we&#8217;ll get information to connect to our &#8220;sound server&#8221; (I call it like that because I&#8217;ve still not decided between using mpd+mpc+samba or some more direct access like the use of esd). We&#8217;ll set [...]]]></description>
			<content:encoded><![CDATA[<p>OK, we now have to configure the network. The goal is to be able to connect to our access point, where we&#8217;ll get information to connect to our &#8220;sound server&#8221; (I call it like that because I&#8217;ve still not decided between using mpd+mpc+samba or some more direct access like the use of esd).</p>
<p>We&#8217;ll set the wifi interface as a client for a remote access point. We&#8217;ll keep the WAN interface with a static ip (here, 192.168.1.1)</p>
<p class="alert">Please note, that changing the configuration will make the remote network access as previously used unusable. The only secure access is still through the serial console.</p>
<p>First, edit the file /etc/config/network:</p>
<p><code>config switch eth0<br />
     option vlan0 "0 1 2 3 5*"<br />
     option vlan1 "4 5"<br />
[...] # localhost config here<br />
[...]<br />
config interface wan<br />
   option ifname "eth0.1"<br />
   option proto static<br />
   option ipaddr 192.168.1.1<br />
   option netmask 255.255.255.0<br />
[...]<br />
config interface lan<br />
   option type bridge<br />
   option ifname "eth0.0"<br />
   option proto dhcp<br />
</code></p>
<p>And then the file /etc/config/wireless:</p>
<p><code>config wifi-device wifi0<br />
   option type atheros<br />
   option channel 8<br />
   option disabled 0<br />
[...]<br />
config wifi-iface<br />
   option device wifi0<br />
   option network lan<br />
   option mode sta<br />
   option ssid YOUR_SSID<br />
   option encryption none<br />
   option hidden 0<br />
</code></p>
<p>If your access point has some encryption, like WEP, do this instead of the wifi-iface block:<br />
<code>config wifi-iface<br />
   option device wifi0<br />
   option network lan<br />
   option mode sta<br />
   option ssid YOUR_SSID<br />
   option encryption wep<br />
   option key 1234567899<br />
   option hidden 0<br />
</code></p>
<p>You can take a look at the different available options <a href="http://www.nbd.name/openwrt.html#x1-80001.2.1" class="liexternal">on this documentation</a>. If all is well, you should have an ip address on your br-lan interface (your WHGT634U hub port is bridged with the wifi interface).</p>
<p>Next part will be the most interesting :-) I think I&#8217;ll try all the different methods to implement an automatic player daemon. Direct methods, and indirect methods, using a share fielsystem like CIFS.</p>
<h2>Reference</h2>
<p><a href="http://www.larsen-b.com/Article/258.html" class="liexternal">Jkx@Home&#8217;s</a> article explaining another use of WGT634U</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO Installation of OpenWRT on a WGT634U usb router</title>
		<link>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router/</link>
		<comments>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 15:00:15 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[hardware]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router/</guid>
		<description><![CDATA[Before the 7.06 stable version of OpenWRT there were many problems for making USB audio working on this exceptional router (the only one I know with a USB port). Problems with kernel version 2.4/2.6, problems with alsa, problems with USB not working (usb2), etc. Take a look at the forums, and see all horrible, painful [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/wp-content/uploads/img_0571.jpg" onclick="ps_imagemanager_popup(this.href,'NetGear WGT634U with OpenWRT','600','800');return false" onfocus="this.blur()" class="liimagelink"><img src="/wp-content/uploads/.thumbs/.img_0571.jpg" alt="NetGear WGT634U with OpenWRT" title="NetGear WGT634U with OpenWRT" align="left" width="72" height="96" border="0" /></a>Before the 7.06 stable version of OpenWRT there were many problems for making USB audio working on this exceptional router (the only one I know with a USB port). Problems with kernel version 2.4/2.6, problems with alsa, problems with USB not working (usb2), etc. Take a look at the <a href="http://forum.openwrt.org/search.php?search_id=574741614" class="liexternal">forums</a>, and see all horrible, painful modifications/patches you needed to apply to make it working.<br />
I have to say that the OpenWRT developers/contributors (and the forum members) <strong>did a wonderful job</strong> and <strong>corrected every known problems</strong>. So with this version, the installation is really straightforward!</p>
<p>Please read the following to get all the details.<br />
<span id="more-23"></span></p>
<p class="alert">I take no responsibility if you damage your router.</p>
<p class="information">This installation procedure has been done with <a href="http://openwrt.org/" class="liexternal">OpenWRT</a> <a href="http://downloads.openwrt.org/kamikaze/" class="liexternal">v. 7.06 (stable)</a>.</p>
<p>These requirements are not really requirements, but are the tools/material I used to make it work. So with these, you&#8217;re sure to make it work, like me :-)</p>
<h2>Hardware Requirements</h2>
<ul>
<li>A PC with a serial port</li>
<li>A breadboard</li>
<li>A serial cable that you can unwire</li>
<li>A network cable</li>
<li>A USB sound adapter</li>
</ul>
<h2>Software requirements</h2>
<ul>
<li>A connection to Internet</li>
<li>A Linux OS (I use Gentoo, but any will be OK)</li>
<li>A TFTPd server</li>
<li>A DHCP server</li>
<li>Screen software</li>
</ul>
<h2>Serial updates</h2>
<p><a href="/wp-content/uploads/WGT634U.jpg" onclick="ps_imagemanager_popup(this.href,'WGT634U plugged on a breadboard','800','600');return false" onfocus="this.blur()" class="liimagelink"><img src="/wp-content/uploads/.thumbs/.WGT634U.jpg" alt="WGT634U plugged on a breadboard" title="WGT634U plugged on a breadboard" align="left" width="96" height="72" border="0" /></a> First thing to do is build a serial connexion to the WGT634U to be able to flash it. Read the infos about the serial console <a href="http://wiki.openwrt.org/OpenWrtDocs/Hardware/Netgear/WGT634U" class="liexternal">on this page</a>. I choose to get a normal serial cable, remove one side of the cable and plug it on my breadboard, which is itself linked to the 3 pins on the NetGear.</p>
<p>Install TFTPd, and set it to get its files from <code>/tftproot</code> (for example). Put the OpenWRT binary file for WGT634U in it (get it from  openWRT&#8217;s <a href="http://downloads.openwrt.org/kamikaze/7.06/brcm47xx-2.6/openwrt-wgt634u-2.6-squashfs.bin" class="liexternal">download section</a>).</p>
<p>Run the following command to catch everything from your Linux ttyS0 port:</p>
<p class="code">screen /dev/ttyS0 115200</p>
<p>Put a network cable on the WAN port of your Netgear, and connect it on your network (which should be linked to Internet):</p>
<p align="center"><img src="/wp-content/uploads/img_0570.jpg" alt="Back of the router, network on WAN" title="Back of the router, network on WAN" width="500" height="375" border="0" /></p>
<p><em>Here, the yellow network cable is plugged in the WAN port (right).</em></p>
<p>Unplug and replug the power supply cable, and at the same time press Ctrl-C several times.</p>
<p>You should get a <code>CFE></code> prompt.<br />
Type: </p>
<p class="code">ifconfig eth0 -auto<br />
flash -noheader 192.168.0.44:openwrt-wgt634u-2.6-squashfs.bin flash0.os
</p>
<p>This will ask the DHCP server on the network for an ip address to set on the NetGear WAN interface<br />
(you can verify that the link is OK by pinging your TFTPd server: <code>ping 192.168.0.44</code>) and then upload the OpenWRT image to the NetGear.<br />
When done, type reboot.</p>
<p>Wait a few minute, for the flash to be reinitialized, then hit enter to get a console.<br />
Set a password for root (which will activate the SSH daemon): <code>passwd root</code>.<br />
Edit the file <code>/etc/firewall.user</code> and uncomment the two lines that allow SSH (port 22) connections to the WAN interface:</p>
<p class="code">### Open port to WAN<br />
# &#8212; This allows port 22 to be answered by (dropbear on) the router<br />
 iptables -t nat -A prerouting_wan -p tcp &#8211;dport 22 -j ACCEPT<br />
 iptables        -A input_wan      -p tcp &#8211;dport 22 -j ACCEPT
</p>
<p>Then reboot.<br />
You should now be able to log in remotely without using the serial cable!</p>
<p align="center"><img src="/wp-content/uploads/logon.png" alt="OpenWRT Logon" title="OpenWRT Logon" width="505" height="294" border="0" /></p>
<p>Logon and type:</p>
<p class="code">ipkg update<br />
ipkg install kmod-soundcore<br />
ipkg install kmod-usb-core<br />
ipkg install kmod-usb-ohci<br />
ipkg install kmod-usb-audio
</p>
<p>Verify that everything is OK by looking into the <code>/dev</code> directory. There should be a <code>/dev/control*</code> and a <code>/dev/pcm*</code> file:</p>
<p class="code">root@OpenWrt:~# ls /dev/pcm* /dev/cont*<br />
/dev/controlC0  /dev/pcmC0D0c   /dev/pcmC0D0p
</p>
<p> If yes, cool! Otherwise, take a look at the kernel logs (<code>dmesg</code>) for any problem.<br />
Now, your USB soundcard should be activated. <strong>But that&#8217;s not sufficient to make it work</strong>. You&#8217;ll have to add some symlinks to make alsa work correctly.<br />
First install alsa utilities:</p>
<p class="code">ipkg install alsa-utils<br />
ipkg install alsa-lib
</p>
<p>Then create the symlinks:</p>
<p class="code">mkdir /dev/snd<br />
ln -s /dev/controlC0 /dev/snd/controlC0<br />
ln -s /dev/pcmC0D0c /dev/snd/pcmC0D0c</p>
<p>Now run <code>alsamixer</code>. You should get an ASCII vertical bar that allows you to set the volume:</p>
<p align="center"><img src="/wp-content/uploads/alsamixer.png" alt="alsamixer on openwrt" title="alsamixer on openwrt" width="667" height="443" border="0" /></p>
<p>That&#8217;s all for now. You now have a working WGT63U router which can play sound.</p>
<p class="information">Next part will be about configuring Wifi as a client, and installing mpd (http://www.musicpd.org/ Music Player Daemon) and linking it to a server to allow direct play from a remote server!
</p>
<h2>References</h2>
<ul>
<li><a href="http://forum.openwrt.org/search.php?search_id=574741614" class="liexternal">Search for WGT634U</a> on http://forum.openwrt.org</li>
<li><a href="http://devices.natetrue.com/musicap/" class="liexternal">Nathan True</a>&#8216;s howto for doing the same thing</li>
</ul>
<p>Don&#8217;t forget to visit the <a href="http://www.gradstein.info//hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router-part-2/" class="liinternal">second part</a>! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/hardware/howto-installation-of-openwrt-on-a-wgt634u-usb-router/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using memcached

Served from: www.stepniewski.fr @ 2012-02-06 07:52:21 -->
