1

I use my RPI as wifi repeater using hostapd and dnsmasq.

Since I'm using hostapd_cli to disconnect the pi from the internet if the repeater is not in use, I often can’t connect to my access point and I have to restart hostapd or dnsmasq.

How is it possible that hostapd_cli makes my access point inaccessible?

I start hostapd_cli by using rc.local:

hostapd_cli -a /home/pi/autoConnectWLAN.sh &

The script contains:

#!/bin/bash

if sudo hostapd_cli all_sta | grep -q "ASSOC" && ! ip link show wlan1 | grep -q "UP"; then
  sudo ip link set wlan1 up 

  if ! pgrep -x "wpa_supplicant"; then
    sudo wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-wlan1.conf -Dnl80211,wext -iwlan1 -B 
  fi

elif ! sudo hostapd_cli all_sta | grep -q "ASSOC" && ip link show wlan1 | grep -q "UP"; then
  sudo ip link set wlan1 down
fi
jake
  • 1,367
  • 1
  • 11
  • 23

1 Answers1

1

Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using rc.local.

In addition your script is doing things that assumes that hostapd is up and running. That may or may not be possible because there is no dependency to start your script After=hostapd.service.

The same is with wpa_supplicant. You start it in your script. If you use a default raspbian image then wpa_supplicant is managed by dhcpcd. I cannot see that you do things to avoid conflicts by starting wpa_supplicant a second time on another way.

In general you are completely ignoring the init system systemd with its dependencies to manage services. I'm sure this is the reason why hostapd_cli makes your access point inaccessible. You should use a systemd Unit file to start your access point (but that wasn't asked).

Ingo
  • 42,961
  • 20
  • 87
  • 207