I tried to find a solution for my problem searching google and this forum but had no luck so far. Some suggestions came close but I am kinda stuck and hopefully someone can point me in the right direction.
My Setup:
Raspberry Pi Zero
Blynk Cloud Server
Blynk Android App.
I installed everything following this guide:
Garage Door
The whole setup was real easy and nice, with one hiccup it works UNLESS I loose WLAN or Internet connection for a minute.
Once internet is gone or wlan drops out, I have to restart the blynk client on the raspberry because it doesn’t reconnect on its own. (app on android shows a red exclamation mark and tells me the last time it was online)
What I’ve done so far:
I followed some guides and created a script which checks if the raspberry has an active internet connection, if the connection is down it restarts wlan0 and the blink client.
# The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
SERVER=8.8.8.8
#specify wlan interface
WLANINTERFACE=wlan0
# Only send two pings, sending output to /dev/null
ping -I ${WLANINTERFACE} -c2 ${SERVER} > /dev/null
# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]
then
# Restart the wireless interface
ip link set wlan0 down
ip link set wlan0 up
sleep 10s
sudo /opt/nodejs/bin/blynk-client MY-TOKEN
fi
I made a crontab entry which runs the script every 10min.
The problem is, if I loose connection for a minute or so, the blink client looses connection, but when the script checks the 8.8.8.8, the connection is on again and it won’t trigger the blink-client restart.
One solution I could think of would be a crontab entry which restarts the client no matter what, but I reckon there must be some more elegant way to do it.
Sorry for any english mistakes, it’s not my native langugage (german is). I am not too good at linux (barely beginner) but usually I can find my way around with guides but here I am kinda stuck.