Category: Fonera

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 that I can use to remotely control the relays of my hacked fonera.

#!/usr/bin/expect -f

set ip
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 : relay \[1\]\n"

# 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"

# ----

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 ./ 1 1.
To switch it off, I type ./ 1 0.
Expect does all the magic like entering the password and ”typing” the right commands.

Fonera relay control

In my previous post I’ve described how to access the serial port of a Fonera 2100 by using a Raspberry Pi with minicom. Being able to access the serial port makes it very easy to flash DD-WRT on the Fonera because according to these instructions we can skip to Step 6.

Following these instructions I’ve flashed my Fonera with DD-WRT v24 (05/20/08) std – build 9517M.

Then, I have put my DD-WRT-Fonera in Client Bridge mode following these instructions. I’ve also enabled SSH, so I can login over the network.

The interesting part is that the fonera has some free GPIO pins, that can be controlled by software. For example:

set GPIO3 to output : echo 1 > /proc/gpio/3_dir
GPIO3 = on (3.3V)   : echo 1 > /proc/gpio/3_out
GPIO3 = off         : echo 0 > /proc/gpio/3_out  

set GPIO4 to output : echo 1 > /proc/gpio/4_dir
GPIO3 = on (3.3V)   : echo 1 > /proc/gpio/4_out
GPIO3 = off         : echo 0 > /proc/gpio/4_out  

set GPIO1 to output : echo 1 > /proc/gpio/1_dir
GPIO3 = on (3.3V)   : echo 1 > /proc/gpio/1_out
GPIO3 = off         : echo 0 > /proc/gpio/1_out  

set GPIO7 to output : echo 1 > /proc/gpio/7_dir
GPIO3 = on (3.3V)   : echo 1 > /proc/gpio/7_out
GPIO3 = off         : echo 0 > /proc/gpio/7_out

To finish this story, I’ve ordered a 4-Channel Relay board at and connected it to the Fonera.

Although the voltage output of the Fonera GPIO’s is 3.3V this works very well.

Use a Raspberry Pi to hack la Fonera 2100

Now that I have a great pfSense box with Wi-Fi, I don’t need my Fonera 2100 anymore. So, why not try to do something interesting with it? 😉

At you can read how to access the serial console on the Fonera.

The serial port of the fonera uses 3.3V instead of the normal RS-232 voltage levels. Because of that, you need some level converters to connect the Fonera to a normal serial port.

But, the Raspberry Pi also has a serial port which operates at 3.3V. This means that you can connect the serial port of a Raspberry Pi and la Fonera without the need of a level shifter.



With a serial communication program like minicom it is now possible to access the Fonera.

starting minicom -b 9600 -D /dev/ttyAMA0

minicom : fonera booting