Pimp your TL-MR3020 mobile router
Buttons and LEDs
By way of the web interface or SSH, you can completely control the TL-MR3020 as a mini-server. However, it is easier to use the existing buttons. The original WPS button is suitable for triggering individual actions, and the slide switch on the side (with its three positions) does the switching between different operating conditions (more about this later).
The LEDs serve as a kind of output device. Three different states are possible: on, off, or flashing. In combination with the buttons, you can build some nice features. From a technical point of view, you need to control the LEDs on files below /sys/class/leds
(e.g., for the WPS LED, this is the /sys/class/leds/tp-link:green:wps
directory). The makers of OpenWrt hide the complexity, and you normally only need to edit the configuration in the /etc/config/system
file (Listing 5, lines 13-35).
Listing 5
Editing /etc/config/system
Typically, OpenWrt couples LED activity with the operating states of individual components, such as the network or USB interface. However, you can adjust the defaults to suit your needs.
Configuring the switch is also easy. You need to configure the event system kernel so that it triggers on the appropriate button events. To do this, edit the /etc/hotplug2.rules
file and remove the caret before the ^Buttons
string. Because this is an exception list, you enable events for buttons by removing the comment sign. From now on, the system runs all the scripts in the directory /etc/hotplug/button
for each button event. The variables BUTTON
and ACTION
are set.
An example that demonstrates the interaction with the LEDs is shown in Listing 6. This script is only for the WPS button (line 22), and it causes the WPS LED to flash for three seconds (lines 6-8 and 10) then go off for another three seconds. When you release the button, the script turns on the LED again (line 19).
Listing 6
LED Interaction
Instead of storing each script individually in the Button
directory and querying the status of the switch there, as in Listing 5, it makes sense to download a generic button script from the OpenWrt treasure trove [4]. Then, you can configure the switch similar to the LEDs in /etc/config/system
.
The WPS button is configured as an off switch here: If you hold down the button for at least three, and a maximum of six, seconds and then let go, the system shuts down (lines 37-42 in Listing 5).
This step also reveals the meaning of the program in Listing 6; the button LED flashes for three seconds and then switches off for three seconds – so you do not have to count to shut down the system. Likewise, you could also use the WPS button to start another operation with short clicks. Listing 5 (lines 44-49) configures a log entry for demonstration purposes.
The Slide Switch
The slide switch on the TL-MR3020 is slightly trickier for two reasons. First, the kernel does not see the slide switch as one button but as two; mapping the three possible states takes 2 bits. Each change of the switch thus triggers two events, which reach the processing script sequentially but must be evaluated together. Second, the event system only sees the changes.
Now you can try a little script that checks the status of the slide switch while booting, for example, to configure the network environment. This aspect, however, is only hinted at in the OpenWrt wiki documentation. Listing 7 shows you how: The script stores the status of the two buttons BTN_0
and BTN_1
in appropriately named files under /var/run
. The script runs once at startup, starting from /etc/rc.local
.
Listing 7
Checking Status of the Slide Switch
In contrast, the script in Listing 8 runs for every button event. It updates the Status button in /var/run
. Additionally, it starts a processing script. The extra magic in lines 10-12 ensures that only one processing script starts. The wait time before processing (line 21) ensures that all relevant button events are also received and processed. Lines 16 and 17 retrieve the processing script from the configuration file in /etc/config/system
. The processing script then starts at line 22.
Listing 8
Updating the Status Button
An example of such a script is shown in Listing 9. It reads the status of the slide switch and reconfigures the network. The actual network files are only symbolic links; thus, the reconfiguration consists of pointing the symlinks at the new configuration files. For example, /etc/config/network.AP
contains the network configuration when the slider is in the AP
position. It makes sense to start the processing script once at startup time (in /etc/rc.local
) after reading the slider status.
Listing 9
Processing Script
Conclusions
In this article, I've explained the hardware, so you "only" need to combine the individual components. For more detailed information about getting a UMTS stick to run, for example, or implementing specific network scenarios, please see the OpenWrt wiki.
The little TL-MR3020 router cannot cover every application (see the "More Application Examples" box). However, the mechanisms described here are at least similar for other devices, including those by other manufacturers. At the upper end of the power spectrum are the QNAP NAS devices that are supplied with OpenWrt in place. However, the range of preconfigured services makes customization more difficult.
More Application Examples
The usefulness of the TL-MR3020 is a result of its low power consumption and mobility. I use it as a synchronization server using the "Rsync for Android" app, and it synchronizes data between my mobile devices, the server, and other computers. On the road, the server acts as a router and emulates my home network, with no need to reconfigure my mobile zoo.
Further application scenarios for the TL-MR3020 can be found online through a simple web search. These range from web servers and VPN gateways to a simple social networking platform. To explore the computer's limits, I also installed ownCloud on the TL-MR3020. The application needs a web server and a complete PHP stack.
Basic functions, such as viewing and maintaining the calendar, do work, but slowly. Also, the TL-MR3020 crashed reproducibly while attempting to upload multiple images simultaneously. Perhaps a little tuning could tweak a bit more out of the box, but to run ownCloud seriously, you need something more powerful on the hardware side.
Infos
- TP-Link: http://www.tp-link.com.de
- OpenWrt project: https://openwrt.org
- Details for TL-MR3020: http://wiki.openwrt.org/toh/tp-link/tl-mr3020
- Generic processing of button events: https://dev.openwrt.org/browser/trunk/target/linux/atheros/base-files/etc/hotplug.d/button/00-button
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.