Last active
August 15, 2020 14:11
-
-
Save libbymiller/e8fe6821e122e0a0ac921c8e557320a9 to your computer and use it in GitHub Desktop.
A version of https://github.com/balena-io/wifi-connect/blob/master/scripts/start.sh for raspberry pis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket | |
# ^^^ this can cause barfing and isn't needed | |
# Choose a condition for running WiFi Connect according to your use case: | |
# 1. Is there a default gateway? | |
# ip route | grep default | |
# 2. Is there Internet connectivity? | |
# nmcli -t g | grep full | |
# 3. Is there Internet connectivity via a google ping? | |
# wget --spider http://google.com 2>&1 | |
# 4. Is there an active WiFi connection? | |
sleep 30s | |
iwgetid -r | |
if [ $? -eq 0 ]; then | |
printf 'Skipping WiFi Connect\n' | |
else | |
printf 'Starting WiFi Connect\n' | |
wifi-connect -o 7777 | |
fi | |
# Start your application here. |
Thank you! I've updated it to add in a delay (and also I'm running it on a different port).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried using the instructions in your blog post for Ubuntu, and it required a few tweaks:
wireless-tools
is not installed by default, so I had to runsudo apt install wireless-tools
ExecStartPre=/bin/sleep 10
to the service configuration fixed this problem./home/ubuntu
instead of/home/pi
when using Ubuntu instead of RaspianOtherwise your blog post was very helpful!