So this code works, but something is not right. It can’t create a wifi-hotspot when orange pi zero has no internet.
#!/bin/sh -e
freq=120
sleep 10
while true; do
echo "Checking internet connectivity ..."
wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Your device is already connected to the internet."
echo "Skipping setting up Wifi-Connect Access Point. Will check again i>
else
echo "Your device is not connected to the internet."
echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi>
python3 /home/wifi.py # this could also probably be just `wifi-connect`>
fi
sleep $freq
done
But If code is written like this hotspot works. It creates hotspot when orange pi zero has internet connection.
#!/bin/sh -e
freq=120
sleep 10
while true; do
echo "Checking internet connectivity ..."
wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Your device is already connected to the internet."
echo "Skipping setting up Wifi-Connect Access Point. Will check again i>
python3 /home/wifi.py
else
echo "Your device is not connected to the internet."
echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi>
fi
sleep $freq
done
log:
Checking internet connectivity …
Your device is already connected to the internet.
Skipping setting up Wifi-Connect Access Point. Will check again in 120 seconds
can you please elaborate on what you are trying to achieve / what should the hotspot do?
The main purpose of wifi-connect is to let you specify wifi credentials if the device has no internet connection. If the device is connected to the internet it should not need wifi-connect at all.
I am trying to create hotspot when Orange pi zero has no active wired or wifi connection.
from the syslog I think problem is a permissions.
rc-local.service: Control process exited, code=exited, status=4/NOPERMISSION
Jul 21 11:06:31 orangepizero rc.local[862]: Your device is already connected to the internet.
Jul 21 11:06:31 orangepizero rc.local[862]: Skipping setting up Wifi-Connect Access Point. Will check again in 120 seconds
I am a little confused now, you mention you want to create the hotspot when the Orange Pi “has no active wired or wifi connection”, yet the logs you have attached are from a situation when the wired connection is in place?
The connectivity check is wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1 if the wired connection provides internet connection this will pass and wifi-connect will not start.
If what you are looking for is to run wifi-connect when there is no wifi connection and ignore ethernet you can replace the wget ... command by e.g. iwgetid -r.
Okay, I think something is very wrong. Then I try code like this, hotspot work. Wired connection in on.
#!/bin/sh -e
freq=120
sleep 10
while true; do
echo "Checking internet connectivity ..."
wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Your device is already connected to the internet."
echo "Skipping setting up Wifi-Connect Access Point. Will check again i"
python3 /home/wifi.py
else
echo "Your device is not connected to the internet."
echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi"
fi
sleep $freq
done
But if code is like this. Hotspot doesn’t show up. Wired connection is off.
Jul 21 12:10:13 orangepizero rc.local[893]: Checking internet connectivity …
Jul 21 12:10:13 orangepizero systemd[1]: rc-local.service: Control process exited, code=exited, status=4/NOPERMISSION
#!/bin/sh -e
freq=120
sleep 10
while true; do
echo "Checking internet connectivity ..."
wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Your device is already connected to the internet."
echo "Skipping setting up Wifi-Connect Access Point. Will check again i"
else
echo "Your device is not connected to the internet."
echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi"
python3 /home/wifi.py
fi
sleep $freq
done
Hi there, from your recent messages what I understand is:
When there is a wired connection, wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1 returns 0 and so your script enters the if condition
If you don’t have a wired connection, when your script gets to wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1, you receive an error: rc-local.service: Control process exited, code=exited, status=4/NOPERMISSION
Is this accurate? Have you tried to replace wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1 with iwgetid -r as my colleague suggested?
I was finally able to reproduce this and figure it out. The core issue is the -e in #!/bin/sh -e which kills the script after wget fails. Additionally having an infinite loop in /etc/rc.local seems to block some services from initalizing.
I would suggest doing the following:
Create a new file for the init script, e.g. /usr/local/sbin/wifi-connect-loop.sh containing
#!/bin/sh
freq=120
sleep 10
while true
do
echo "Checking internet connectivity ..."
wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Your device is already connected to the internet."
echo "Skipping setting up Wifi-Connect Access Point. Will check again in $freq seconds"
else
echo "Your device is not connected to the internet."
echo "Starting up Wifi-Connect. Connect to the Access Point and configure the SSID and Passphrase for the network to connect to."
python /home/wifi.py
fi
sleep $freq
done
Create a new file named /etc/systemd/system/wifi-connect.service containing
[Unit]
Description=Run wifi-connect in an infinite loop
[Service]
Type=simple
ExecStart=/usr/local/sbin/wifi-connect-loop.sh
[Install]
WantedBy=multi-user.target
Reload systemd: systemctl daemon-reload
Enable the service: systemctl enable wifi-connect.service
Reboot
The infinite loop script should be autostarted on boot and should spawn wifi-connect if no connection is available. When connected to the internet it will just loop infinitely until the connection is broken.