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
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.