RaspberryConnect / AutoHotspot-Installer

For the RaspberryPi computers. Allows switching between a Raspberry Pi Access Point and Wifi Network connection without a reboot.
GNU General Public License v3.0
67 stars 24 forks source link

Disable Hotspot to get default RPI Scan for Wifi UI #22

Open x20011 opened 4 months ago

x20011 commented 4 months ago

Hello,

Firstly I must say thank you for this fantastic project. This is exactly what I've been looking for all this time!

I installed my hotspot with the autohotspot-setup.sh script and it works great in mode 1.

Since scanning for new wifi networks in the terminal and via the script is quite tedious, I've been trying for hours to write a script that disables the hotspot and reconfigures the Raspberry so that I get the normal wifi UI view in the taskbar again.

So I now have two different cases here:

1: Raspberry boots up and there is a known Wifi in range -Raspberry connects to the known Wifi and the normal Wifi GUI view with all Wifis in range is displayed. -Using ForceSwitch.sh I can now switch the hotspot on and off if necessary and the RPI connects to the known Wifi including the GUI view. Case 1 works great

2: Raspberry boots up and there is no known Wifi in range. -AutoHotspot recognises no known Wifi within range and starts the hotspot -Using my second KillHotspot script, the hotspot should now be switched off and the Raspberry should try to log into a known wifi. If there is no known wifi in range, the usual Raspberry Pi UI wifi view should also be displayed in the taskbar, where a mouse click on the WLAN / LAN symbol displays all available wifi networks within range. The Hospot should stay off until ForceSwitch.sh is used again.

I have now created / copied these two scripts for testing. For case 1, ForceSwitch.sh works as expected. For case 2, since ForceSwitch.sh only restarts autohotspot.service, i made a second script KillHotspot.sh for testing. This switches off the hotspot, but the RPI does not switch to the Wifi UI view thus I get the available networks in the range displayed. Is there a trick how I can get the normal Wifi view back even if there is no known Wifi in range? It would be great if i can combine both scripts into just one "Switch Wifi <> Hotspot" Script.

ForceSwitch.txt KillHotspot.txt

RaspberryConnect commented 4 months ago

Hi

I have not been able to check your scripts as I don't seem to have a SD that I can get to, that has the correct setup to test it. They all have other setups that I would have to untangle first. I will check when I have one available.

During the hotspot phase dhcpcd for wlan0 and wpa_supplicant are shutdown. When these are brought back up with the section at the bottom autohotspot scripts, it will reactivate the wifi gui. There is a bit of clean up that has to be done first so that wpa_supplicant can start ok. If you remove the parts ">/dev/null 2>&1" for dhcpcd -n.... and wpa_supplicant -B -i.... You will get more feedback on any issues causing any failures.

If I understand it right, by combining the scripts it will just activate wpa_supplicant and you would have to force it to the hotspot. This is only useful if a screen and keyboard is always available or a permanent ethernet connection.

You should get what you want with the autohotspot script running normally. Then a script similar to Killhotspot that does the opposite to the current status, that you run manually. Check if hostapd is running, if so then shut the hotspot down and activate wpa_supplicant. If hostapd is not running then shutdown wpa_supplicant etc and activate the hotspot.

I will get back to you when I can do a test about the gui.