From 923bf60d06edcbf985f22362a1a96f4cec30aa03 Mon Sep 17 00:00:00 2001 From: Esteban Mackay Q Date: Sat, 9 Sep 2023 18:20:14 -0500 Subject: [PATCH] Update wifi-connect.sh --- install/wifi-connect.sh | 45 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/install/wifi-connect.sh b/install/wifi-connect.sh index e1d9433..9a712f9 100644 --- a/install/wifi-connect.sh +++ b/install/wifi-connect.sh @@ -16,7 +16,7 @@ TIEMPO_MONITOREO=30 # Tiempo de espera entre los chequeos en segundos TIEMPO_ESPERA=30 -# Función para verificar el estado de Internet +# Funcion para verificar el estado de Internet verificar_internet() { ping -c 5 noip.com > /dev/null 2>&1 return $? @@ -24,54 +24,53 @@ verificar_internet() { # Bucle infinito para monitorear while true; do - if verificar_internet; then - # Acción silenciosa - : - echo "internet ok" - else -# echo "sin internet" - sleep $TIEMPO_MONITOREO - + # Verificar el estado de la interfaz wlan0 + if iw dev wlan0 link | grep -q "Not connected"; then + # La interfaz wlan0 no esta conectada, continuar con la verificacion de Internet if verificar_internet; then - # Conexión restablecida -# echo "internet restablecido" + # Accion silenciosa : + echo "Internet OK" else - # Verifica si http.server-mmdvmh.service está habilitado - if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then - # Inicia http.server-mmdvmh.service si está habilitado - sudo systemctl stop http.server-mmdvmh.service - fi - wifi-connect -# echo "apliando reboot" + # Internet no esta disponible, realiza acciones necesarias + if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then + # Detiene http.server-mmdvmh.service si esta habilitado + sudo systemctl stop http.server-mmdvmh.service + echo "Detenido http.server-mmdvmh.service" + fi + wifi-connect + echo "Aplicando reboot" fi + else + # La interfaz wlan0 esta conectada, esperar antes de la proxima verificacion + echo "Interfaz wlan0 conectada" + sleep $TIEMPO_MONITOREO fi sleep $TIEMPO_ESPERA done - EOF sudo cat > /usr/local/bin/apoff.sh <<- "EOF" #!/bin/bash while true; do - # Verifica si wifi-connect está activo + # Verifica si wifi-connect esta activo if sudo systemctl is-active wifi-connect.service >/dev/null 2>&1; then # Realiza una prueba de ping a noip.com if ping -c 1 noip.com >/dev/null 2>&1; then # Si la respuesta de ping es positiva, reinicia autoap.service sudo systemctl restart autoap.service - # Verifica si http.server-mmdvmh.service está habilitado + # Verifica si http.server-mmdvmh.service esta habilitado if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then - # Inicia http.server-mmdvmh.service si está habilitado + # Inicia http.server-mmdvmh.service si esta habilitado sudo systemctl restart http.server-mmdvmh.service fi fi fi - # Espera 3 segundos antes de realizar la siguiente iteración + # Espera 3 segundos antes de realizar la siguiente iteracion sleep 3 done