[FIX] point_of_sale: make POSBox print only one ticket when losing wifi

The POSBox attempts to maintain whatever Wi-Fi connection it has as best
it can. When it loses it's current Wi-Fi connection it will attempt
to recreate it every 30 seconds. This works well, but a side-effect of
this is that it'll also print a 'Could not connect to LAN' ticket every
time it fails. If you where to leave the POSBox with Wi-Fi on for an
extended period of time you could return to a lot of 'Could not connect
to LAN' tickets.

This makes it so that the 'Could not connect to LAN' ticket only gets
printed once upon connection loss. Although it would be simpler to just
not print this ticket at all when losing connection, it is very useful
to know when the POSBox has lost connection. Otherwise when it loses
connection it would stop working and noone would know why.
This commit is contained in:
Joren Van Onder 2016-02-09 16:30:01 +01:00
parent 3266d43399
commit cdf21ebe4a
1 changed files with 16 additions and 3 deletions

View File

@ -7,6 +7,7 @@ function connect () {
WPA_PASS_FILE="/tmp/wpa_pass.txt" WPA_PASS_FILE="/tmp/wpa_pass.txt"
PERSISTENT_WIFI_NETWORK_FILE="/home/pi/wifi_network.txt" PERSISTENT_WIFI_NETWORK_FILE="/home/pi/wifi_network.txt"
CURRENT_WIFI_NETWORK_FILE="/tmp/current_wifi_network.txt" # used to repair connection when we lose it CURRENT_WIFI_NETWORK_FILE="/tmp/current_wifi_network.txt" # used to repair connection when we lose it
LOST_WIFI_FILE="/tmp/lost_wifi.txt"
ESSID="${1}" ESSID="${1}"
PASSWORD="${2}" PASSWORD="${2}"
PERSIST="${3}" PERSIST="${3}"
@ -15,6 +16,7 @@ function connect () {
sleep 3 sleep 3
sudo pkill -f keep_wifi_alive.sh sudo pkill -f keep_wifi_alive.sh
WIFI_WAS_LOST=$?
# make network choice persistent # make network choice persistent
if [ -n "${ESSID}" ] ; then if [ -n "${ESSID}" ] ; then
@ -54,13 +56,24 @@ function connect () {
# give dhcp some time # give dhcp some time
timeout 30 sh -c 'until ifconfig wlan0 | grep "inet addr:" ; do sleep 0.1 ; done' timeout 30 sh -c 'until ifconfig wlan0 | grep "inet addr:" ; do sleep 0.1 ; done'
TIMEOUT_RETURN=$?
if [ $? -eq 124 ] && [ -z "${NO_AP}" ] ; then if [ ${TIMEOUT_RETURN} -eq 124 ] && [ -z "${NO_AP}" ] ; then
logger -t posbox_connect_to_wifi "Failed to connect, forcing Posbox AP" logger -t posbox_connect_to_wifi "Failed to connect, forcing Posbox AP"
sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh "force" & sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh "force" &
else else
logger -t posbox_connect_to_wifi "Restarting odoo" if [ ${TIMEOUT_RETURN} -ne 124 ] ; then
sudo service odoo restart rm -f "${LOST_WIFI_FILE}"
fi
if [ ! -f "${LOST_WIFI_FILE}" ] ; then
logger -t posbox_connect_to_wifi "Restarting odoo"
sudo service odoo restart
fi
if [ ${WIFI_WAS_LOST} -eq 0 ] ; then
touch "${LOST_WIFI_FILE}"
fi
logger -t posbox_connect_to_wifi "Starting wifi keep alive script" logger -t posbox_connect_to_wifi "Starting wifi keep alive script"
/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh & /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh &