Breathe new life into your old home router

USB Drives

To add USB drives, remotely SSH into the router and enter the code from Listing 1. After the USB packages are loaded, reboot the router.

Listing 1

Adding USB Drives Remotely

## update okpg is required to get info on new packages
opkg update
## get packages for USB2/3 and ext4 type devices
opkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb-storage kmod-usb2 kmod-usb3

Under the System menu, you will now see the Mount Points item has been added to the LuCI web interface. This option allows for easy addition and removal of portable USB drives (Figure 4).

Figure 4: The LuCI web interface lets you mount portable USB drives.

Adding USB drives to a router opens up the possibility of a number of interesting projects, such as a SAMBA file/printer server, an FTP server, or a Network File System (NFS).

USB Webcam Project

For a fun router project, you can connect a USB webcam and start a video-streaming service. A number of excellent USB video solutions are available, but you need to ensure that the router's small memory size can accommodate the video package and all its dependencies. A good lightweight USB video option is mjpg-streamer, which can be installed with the code in Listing 2.

Listing 2

Installing mjpg-streamer

## install video streaming software and nano editor
opkg install kmod-video-uvc mjpg-streamer nano
## enable video service
## edit config file, and set "option enable '1'
nano /etc/config/mjpg-streamer

Once you've installed mjpg-streamer, you need to start the video service:

## to start the service:
/etc/init.d/mjpg-streamer start
## to enable the service to start on
/etc/init.d/mjpg-streamer enable

You can access the USB webcam as a web page from the router's IP with the default port of 8080 (Figure 5).

Figure 5: Use port 8080 on your router's IP to view the USB webcam.

USB-Serial Connections

A router doesn't have external General Purpose Input/Output (GPIO) pins like a Raspberry Pi or an Arduino, but USB ports can be used to pass data.

Because there aren't a lot of USB sensors available, a good workaround to this problem is to use an older microcontroller. Low-end modules such as the Arduino Nano, littleBits Arduino Bit, or a BBC micro:bit can be directly connected to sensors, and the data can be passed with the USB-to-Serial interface.

To start the video service, you need to enable USB-to-Serial communications in OpenWRT:

## add USB-Serial packages
opkg install kmod-usb-serial kmod-usb-acm
## add terminal config package
opkg install coreutils-stty

For our project, we used a BBC micro:bit [4], which is very user-friendly for coding: It only took five blocks to send the on-board temperature reading and to show the value on the front panel (Figure 6).

Figure 6: The micro:bit code for USB-to-Serial communications can be completed in five blocks.

The OpenWRT firmware runs a light version of the Bash shell called Ash. The Ash script in Listing 3 connects to the micro:bit USB port and prints out the temperature data.

Listing 3

Reading USB-Serial Data

# - reads microbit temperature
# set terminal speed
stty -F /dev/ttyACM0 115200
# read USB-Serial device (/dev/ttyACM0)
while read -r line < /dev/ttyACM0; do
  echo " Temp: $line DegC"

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More