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).
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 boot /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).
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).
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
#!/bin/ash # # microbit.sh - 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" done
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)