In this follow-up guide, we’ll elevate the previously built OpenWrt router with powerful automation features. The goal is to transform it into a truly ‘set it and forget it’ device that intelligently manages its own internet connection, power state, and system updates—making it perfect for use in a vehicle, as a travel router, or for any mobile application.
Project Highlights
- Intelligent Network Roaming: Automatically scans for and connects to known Wi-Fi networks based on a priority system. It uses a hybrid event-driven and time-based approach for instant failover and proactive switching to better networks, all without disrupting the local access point.
- Idle Auto-Poweroff: To save energy and reduce component wear, the device automatically shuts down after 15 minutes of inactivity (no connected Wi-Fi clients).
- “Catch-Up” Auto-Updates: The router periodically checks for software updates. The system is smart enough to run an update check on boot if a scheduled check was missed, ensuring the device stays current and secure. Kernel-related packages are automatically excluded to maintain stability.
Core Features Explained
1. Intelligent Network Roaming
The centerpiece of this project is a smart, hybrid roaming system that replaces manual network selection. This provides a seamless, hands-off experience that is both fast and reliable.
How It Works (Hybrid Approach):
- Instant Failover (Event-Driven): A
hotplugscript (/etc/hotplug.d/iface/99-roam-trigger) constantly watches the WAN connection. If the current Wi-Fi network goes out of range and disconnects, this script triggers immediately, running the main roaming script to find and connect to the next best network. This ensures a rapid switch-over with minimal downtime. - Proactive Switching (Time-Based): A cron job runs the main roaming script (
/usr/bin/roam.sh) every 3 minutes. This handles situations where the current connection is stable, but a higher-priority network has come into range. The script will detect the better network and switch to it automatically. - Prioritized Profiles: The script makes decisions based on a
prioritynumber assigned to each saved Wi-Fi network in/etc/config/wireless. It always tries to connect to the available network with the highest priority number.
2. Idle Auto-Poweroff
To save power, the device will automatically shut down if no clients are connected to its local Access Point for 15 minutes.
- Script:
/usr/bin/idle-poweroff.sh - Trigger: Runs every minute via a cron job.
- Logic: If the script detects zero connected clients, it starts a 15-minute timer. If a client connects, the timer is cancelled. If 15 minutes pass with no clients, it performs a final check and then powers off the device.
3. “Catch-Up” Auto-Update
This script ensures your OpenWrt system stays up-to-date without requiring manual intervention, even if the device is powered off for long periods.
- Script:
/usr/bin/auto-update.sh - Trigger: Runs at every boot (
@reboot) via a cron job. - Logic: On boot, the script checks a timestamp to see when the last update was run. If it has been more than 7 days, it automatically runs
opkg updateandopkg upgrade, safely excluding kernel packages. On success, it updates the timestamp.
Download & Installation
You can download all the scripts mentioned in this guide in a single zip file.
Installation Instructions
After downloading and unzipping the file, you will need to place each script in the correct location on your OpenWrt device and make them executable. You can use an SCP client like WinSCP or the command line.
- Roaming Script:
Placeroam.shin/usr/bin/and run:chmod +x /usr/bin/roam.sh - Roaming Trigger:
Place99-roam-triggerin/etc/hotplug.d/iface/and run:chmod +x /etc/hotplug.d/iface/99-roam-trigger - Idle Power-Off Script:
Placeidle-poweroff.shin/usr/bin/and run:chmod +x /usr/bin/idle-poweroff.sh - Auto-Update Script:
Placeauto-update.shin/usr/bin/and run:chmod +x /usr/bin/auto-update.sh
Configuration
Adding a New Wi-Fi Network
The roaming script will automatically incorporate new networks. Simply add a new network profile in the OpenWrt web interface (under Network -> Wireless) and follow these steps:
- Scan and join the new network as a client (station) on the correct radio device. Make sure it’s assigned to the correct firewall zone.
- Find the new network profile, click Edit, and go to the Advanced Settings tab.
- In the “Interface-Properties” section, find the Priority field and enter a number. A higher number means a higher priority. For example, your most preferred network could be 10, while a less-preferred one is 5.
- Ensure the interface is disabled. The script will enable it as needed.
- Save and apply your changes.
Verifying Cron Jobs
After installation, the system’s cron jobs should be configured to run the automation scripts. You can verify this by running crontab -l via SSH. The output should look like this:
@reboot /usr/bin/auto-update.sh
*/3 * * * * /usr/bin/roam.sh
* * * * * /usr/bin/idle-poweroff.sh
Conclusion
This setup transforms a standard Raspberry Pi into a powerful, self-sufficient mobile routing platform. It reliably manages its internet connectivity and system health, providing a seamless experience with minimal user intervention.
