Category: GNU/Linux

Voyage Linux on a ALIX 2D13 with USB HD

My normal desktop PC was always on – doing some tasks in the background – but the noisy fan was annoying me. And because I had a spare ALIX 2D13 lying around that was doing nothing but gathering dust, I was wondering if I could switch some tasks from my normal PC to this ALIX 2D13 and only switch my normal PC on when needed.

A CompactFlash (CF) card is used as storage/boot device on the ALIX 2D13, but for the things I had in mind, more storage is needed. For this reason I’ve connected a little USB HD to the USB port of the ALIX 2D13.

alix2d13server

On the software side, I’ve installed voyage linux on the CF card. Voyage Linux is a Debian derived distribution, which is nice because I know how to configure Debian GNU/Linux.

On the USB HD, I’ve created some partitions. Then I’ve added the following to /etc/fstab of the ALIX 2D13:

/dev/sdb1       none            swap    	sw              		0       0
/dev/sdb2	/root		btrfs           defaults,compress,noatime       0       1
/dev/sdb3	/var		btrfs           defaults,compress,noatime       0       2
/dev/sdb4	/home           btrfs   	defaults,compress,noatime       0       3

After setting up certain things like SSH access, fetchmail, postfix, … , I have now a minimal little computer that can do some tasks in the background like fetching and sorting my email and downloading podcasts and so on.

My normal PC is now off most of the time, which is not only good for my ears, but also for my electricity bill 🙂

Mails lost in Cyberspace

A few days ago I noticed that mails send to my sister and brother got lost in cyberspace 🙁

I didn’t get a notice that these mails weren’t delivered. In my log’s everything looks just fine. But the mails never arrived at the computers of my sister and brother. Although, sending mail to my other brother or my own @gmail-address works just fine. Strange ???

The common factor is that my sister and brother are using the same ISP (belgacom @skynet.be). So, it seems that belgacom was blocking my mails for some reason.

After trying several things, I’ve found a solution to send mails @skynet.be without a problem.

To write e-mail I make use of mutt as my E-Mail Client. Mutt delivers the mail to the postfix mail server. Postfix delivers the mail to the mailserver of my ISP. Of course my internet connection is protected with a firewall.

muttpostfixpfsense

When I look at the headers of e-mails send to myself, I see this:

Received: from amd64 (unknown [77.109.119.201])
        by csmtp5.one.com (Postfix) with ESMTPA id 01AFD40133F70;
        Thu,  9 May 2013 15:00:25 +0000 (UTC)
Received: from amd64 ([UNAVAILABLE]. [77.109.119.201])
        by 0.0.0.0:2525 (trex/4.8.64);
        Thu, 09 May 2013 14:59:10 GMT
Received: by amd64 (Postfix, from userid 1000)
        id B50091436E; Thu,  9 May 2013 17:00:25 +0200 (CEST)

The line Received: by amd64 (Postfix, from userid 1000) is added by postfix running at my local PC (amd64) to show that it has received an email of userid 1000.

So, I was thinking, what if I remove that line? Maybe belgacom doesn’t like the fact that I’m running a mailserver at my local machine?

This is what I have done:

  • In /etc/postfix/mail.cf I have uncomment this line header_checks = regexp:/etc/postfix/header_checks.
  • Created the file /etc/postfix/header_checks with the content /^Received: by amd64 .*from userid [0-9]+\)/ IGNORE

With this, the line Received: by amd64 (Postfix, from userid 1000) is removed from the headers:

Received: from amd64 (unknown [77.109.119.201])
	by csmtp7.one.com (Postfix) with ESMTPA id 9CFA8C0006042;
	Fri, 10 May 2013 15:15:09 +0000 (UTC)
Received: from amd64 ([UNAVAILABLE]. [77.109.119.201])
	by 0.0.0.0:2525 (trex/4.8.64);
	Fri, 10 May 2013 15:13:50 GMT

After these changes, I was able to send e-mail to my sister and brother again 🙂

Coïncidence? Or is Belgacom really blocking mails because of that one line?

Raspberry Pi -> Fonera relay control

So, now that I have a Raspberry Pi and a hacked fonera with 4 relays, it’s time to let the Raspberry Pi control the relays of the fonera. This can be done by logging in to the Fonera with ssh and giving some commands.

Of course, having to type these commands everytime you want to switch a relay on or off is cumbersome and useless for automatisation.

Luckily there is an interesting tool available Expect (apt-get install expect).

With expect, I’ve created a small script named gpio.sh that I can use to remotely control the relays of my hacked fonera.

#!/usr/bin/expect -f

set ip		192.168.242.201
set user	root
set passwd 	averysecretpasswd

set gpio	""
set relay  	[lindex $argv 0]
set onoff 	[lindex $argv 1]

# Translate relay to gpio
# -----------------------

if { "$relay" == "1" } {
	set gpio 3
}

if { "$relay" == "2" } {
        set gpio 4
}

if { "$relay" == "3" } {
        set gpio 1
}

if { "$relay" == "4" } {
        set gpio 7
}

# Default is switch relay off
# ---------------------------

if { "$onoff" == "" } {
	set onoff 0
}


# Check if port is valid, if not -> error
# ---------------------------------------

if { "$gpio" == "" } {
        puts "Usage : gpio.sh relay \[1\]\n"
	exit
}

# Put some info on the screen
# ---------------------------

puts "Send $onoff to relay/gpio $relay/$gpio\n"

# Check if $ip is alive, if not -> error
#---------------------------------------

spawn ping -c 1 -W 1 $ip
expect -re "100%"	{
	puts "No connection to $ip"
	exit
}

# DO IT
# ----

set timeout 10
spawn ssh $user@$ip
expect -re "password" 	{send "$passwd\r"}
expect -re "#"		{send "echo 1 > /proc/gpio/$gpio\_dir\r"}
expect -re "#"		{send "echo $onoff > /proc/gpio/$gpio\_out\r"}
expect -re "#"		{send "exit\r"}
close $spawn_id

To switch relay 1 on, I just type ./gpio.sh 1 1.
To switch it off, I type ./gpio.sh 1 0.
Expect does all the magic like entering the password and ”typing” the right commands.

First experiments with PIC18F4550 USB GNU/Linux gpasm (GNU PIC assembler)

Serial and Parallel ports are becoming less and less common on modern PC’s. Especially, the parallel port was very handy to control something with a PC.

Because of this, I’m now experimenting with USB and a Microchip PIC18F4550, using a 4Mhz crystal.

Problem with USB is that writing USB firmware is rather complex. Microchip has published an USB stack which is written in C. But I prefer USB firmware where (1) I can understand how it works and (2) I can create an HEX file by using my Debian GNU/Linux PC.

I’ve found very interesting firmware written in assembler, but trying to assemble it with gpasm gives a lot of errors 🙁

Lucky enough, I found this thread where Ben Dugan has ported lab2.asm to work with gpasm. After a few modifications, it worked perfectly with the PIC18F4550/4Mhz 🙂      Thanks Ben!

You can download my lab2/PIC18F4550/4Mhz/gpasm source here.

I have also modified the original lab4 found at http://pe.ece.olin.edu/ece/projects.html to work with gpasm. You can download this modified lab4 here. You can compile the pc-files of the original lab4 with “gcc -l usb“.

youtube script : update

I have updated my youtube script, because it sometimes keeps downloading movies that I had already seen.

 pts/4  jan ~/youtube_script$ cat youtube
#!/bin/sh
LOG=/home/jan/youtube_script/youtube.log/
LIST=/home/jan/youtube_script/youtube.list
DOWNLOADDIR=/home/jan/youtube_downloads/

for URL in `cat $LIST` 
do 
  echo ----[start]
  echo $URL

  # change DIR to DOWNLOADDIR
  cd $DOWNLOADDIR

  # check URL
  for VIDEO in `lynx -dump "$URL" | grep watch?v | sed 's# ##g' | cut -d"." -f2-`
  do
    echo $VIDEO
    X=`echo $VIDEO | cut -d "=" -f2- | cut -d "&" -f1 `
    X=$LOG$X
    echo $X

    # Only download video when it was not downloaded before
    if [ -e $X ]
    then
      touch $X
      echo Already downloaded --skip
    else
      touch $X
      echo Downloading $X
      timelimit -t 7200 -T 360 clive $VIDEO --format=best
    fi
  done
  echo ----[end]
done

# CLEAN $LOG
find $LOG -mtime +30 -delete
 pts/4  jan ~/youtube_script$

youtube script

I have created a little YouTube script that downloads all the video’s in certain YouTube channels to the hard-disk. This way I can easily watch the movies with my favourite media-player (mplayer controlled with a remote control) full-screen on my TV.

The script is ugly, but it works. I run it every hour in a cron job.

The script:

 pts/4  jan ~/youtube_script$ cat youtube
#!/bin/sh
LOG=/home/jan/youtube_script/youtube.log/
LIST=/home/jan/youtube_script/youtube.list
DOWNLOADDIR=/home/jan/youtube_downloads/

for URL in `cat $LIST` 
do 
  echo ----[start]
  echo $URL

  # change DIR to DOWNLOADDIR
  cd $DOWNLOADDIR

  # check URL
  for VIDEO in `lynx -dump "$URL" | grep watch?v | sed 's# ##g' | cut -d"." -f2-`
  do
    echo $VIDEO
    X=`echo $VIDEO | cut -d "=" -f2-`
    X=$LOG$X
    echo $X

    # Only download video when it was not downloaded before
    if [ -e $X ]
    then
      touch $X
      echo Already downloaded --skip
    else
      touch $X
      echo Downloading $X
      timelimit -t 7200 -T 360 clive $VIDEO --format=best
    fi
  done
  echo ----[end]
done

# CLEAN $LOG
find $LOG -mtime +30 -delete
 pts/4  jan ~/youtube_script$

The channels to check are in the file youtube.list, for example:

 pts/4  jan ~/youtube_script$ cat youtube.list
http://www.youtube.com/user/jan0wagemakers#p/a
http://www.youtube.com/user/RudyWumpscut#p/a
 pts/4  jan ~/youtube_script$ 

And this is what it looks like: Movie YouTube Script in action