Automation / Scripting of OpenWrt

Hi All,

Newbie question, so please excuse if I use wrong terminology. I have a Battery Powered LTE router running OpenWrt (Gl.Inet Pulli) which I use in my car as a travel router. Great little device and works really well, however with one minor annoyance, which I hope can be addressed with some form of script or automation...

When we arrive back home from a trip, I turn off the car engine, and (of course) the router switches to battery mode, and all the devices (kid's iPads etc) stay connected to the travel router. This has 2 downsides - 1) The devices are connected to the slower LTE network rather than home wifi and 2) The battery runs down.

I'd like to know if it's possible to write a script that would work this way...

TRIGGER - when the router switches to battery mode (ie car ignition turned off)
CONDITION - check if the home wifi SSID is detected
ACTION - power off the router

Is this kind of scripting / automation possible in OpenWrt? Or is there a better alternate approach that anyone could suggest?

Thanks for any help

condition and action are pretty straight forward. Trigger..probably you can't detect that but that shouldn't stop you from achieving what you want to do.

ubus call system board to let us know what firmware you are running.

1 Like

In which case is there a possibility of running a script periodically and checking for the home wifi?

Sorry - I’ll let you know in a week. Actually away for work and I’m travelling without my travel router!

yes. there are probably a number of ways you could go about it. The first that come to mind is iw or iwinfo and grep since they are immediately available. You could either place these into cron or daemonize them at rc.local startup. To boot everyone off your device just issue the wifi down command.

for turning off the power I doubt that is possible by software. I imagine that the device is directly powered by the battery, not the input voltage. Rather the input voltage is just used to charge the battery so there is no switchover from input voltage to battery.

1 Like

Check initially, whether power event is displayed in router log.

3 Likes

or just try the standard linux "poweroff" command to see if that works straight off the bat

2 Likes

Thanks @papdee - great suggestion. I guess I'd need to do something like iwinfo wlan0 scan and then grep the result? I think with a scan it temporarily suspends traffic, so I probably won't run it too frequently. Might try to find a way to spot the battery event, and only then scan.

1 Like

Thanks @ulmwind - I'll have a look. Is there some way to "watch" the logs and then trigger a script if I find the right event?

Thanks - will give that a try, and if it doesn't work will try the wifi down command

wpa_cli and wpa_supplicant all have similar functions for obtaining SSID and signal strength but these are packages you will need to download and install.

1 Like

Maybe see if any client connected. Once the devices roam to home network, there should not be any devices connected

1 Like

you could actually put the script on your router/AP inside the house. Setup a WDS connection to the mobile router and when it comes into range the WDS client should be able to establish a connection to the WDS server and the server SSH and power down the mobile router or shut down its wifi. That way all the mobile router has to do is connect with WDS when it is in range. There is little to no wifi interruption in that exchange. The only caveat to this method is that WDS or 802.11s for that matter doesn't always work 100% of the time ( I use WDS at home and sometimes they just won't connect without a hard reboot).

1 Like

Thanks @sammo - that's exactly the problem though - the clients don't roam to the home network - they stay connected to car wifi. Hence my wish to shut down the router. When I power it off the travel router manually, all the clients then connect to the home network again.

Thanks @papdee - another good suggestion, but my APs at home are all Ubiquiti, and I'm not sure they do WDS exactly like that - I think they have their own meshing technique. Also I use different SSID for home and travel.

How to solve hostapd excessive "deauthenticated due to local deauth request" - #8 by vgaetera

1 Like

Command logread. Start from it.

1 Like

Which smartphone model do you use?
With iPhone is possible to make automation based on location, once you arrive it will just send poweroff command to your travel router.

1 Like

Thanks @di_Niko - that's an interesting possibility. Yes iPhone. Do you mean the "shortcuts" app, or some other way?

1 Like