From cdf21ebe4aa3537d4fec12a649e5529b70b1c57a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 9 Feb 2016 16:30:01 +0100 Subject: [PATCH] [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. --- .../posbox/configuration/connect_to_wifi.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh b/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh index 11f6d18eae4..681732ae714 100755 --- a/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh +++ b/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh @@ -7,6 +7,7 @@ function connect () { WPA_PASS_FILE="/tmp/wpa_pass.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 + LOST_WIFI_FILE="/tmp/lost_wifi.txt" ESSID="${1}" PASSWORD="${2}" PERSIST="${3}" @@ -15,6 +16,7 @@ function connect () { sleep 3 sudo pkill -f keep_wifi_alive.sh + WIFI_WAS_LOST=$? # make network choice persistent if [ -n "${ESSID}" ] ; then @@ -54,13 +56,24 @@ function connect () { # give dhcp some time 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" sudo /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh "force" & else - logger -t posbox_connect_to_wifi "Restarting odoo" - sudo service odoo restart + if [ ${TIMEOUT_RETURN} -ne 124 ] ; then + 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" /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh &