Connect to WiFi and install OPKG package with AutoRun example
-
I have been reviewing the Autorun documentation here:
https://onion.io/usb-autorun/It seems fairly straightforward, however I do not write shell scripts that often. One of the suggestions is to write a script that connects to WiFi and then installs some packages via OPKG. That is exactly what I'm looking to do. However all methods of connecting to WiFi networks appear to be Asynchronous, my issue with that is I need to write a script that connects to a WiFi network, waits for that connection to be established and then install a package via OPKG. Thus I either need a blocking call to connect to WiFi, or I need to write a while block into the script that waits for valid wifi connection using something link ping. Would it be possible to get a super simple .sh example for this?
-
@IOTrav I would break this into 2 separate parts.
- Script that connects to the network
- Hotplug script that runs when the interface comes up and installs the packages.
Search the forum for hotplug, I posted a hotplug script that will run once the wwan interface comes up and executes a setup script for one of my IoT devices.
-
Thank you @crispyoz,
I actually finally got it working this morning just the way I wanted. Here's a simple example based on what I did:
printf "%s" "Connecting to WiFi" wifisetup add -ssid Network-SSID -encr wpa2 -password XXXXXXXX printf "%s" "Waiting for Internet" while ! ping -c 1 -n -w 1 www.google.com &> /dev/null do printf "%c" "." done printf "\n%s\n" "Internet Connected" opkg update
Seems to be running great. It waits indefinitely but I don't want it to proceed until Internet connection is there so I didn't figure there was any reason to have a retry count. I'm using an on board RGB LED to indicate when the script starts, when it connects to wifi and begins installing OPKG packages, and when it is complete. This will be used for configuring a group of Onion modules prior to installation in our product. AutoRun is fantastic!