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
69 stars 24 forks source link

Switching from hotspot to wifi not working #9

Open mineCraft031801 opened 1 year ago

mineCraft031801 commented 1 year ago

Hello I'm this "Mine Craft" guy from youtube. I think it is easyer to get to the solution of this problem in github.

I can not switch from the hotspot to wifi via the script(sudo ./autohotspot-setup.sh -> option 6). Also, the hotspot do not start when no known SSID is in range. When i use "sudo /usr/bin/autohotspotN" or "sudo /usr/bin/autohotspot" it works.

P1
mineCraft031801 commented 1 year ago

Hotspot is activated and i want to switch to wifi with sudo ./autohotspot-setup.sh -> (option 6):

option 6

Nothing happens.

Switch manualy with for option1 sudo /usr/bin/autohotspotN or for option2: sudo /usr/bin/autohotspot it works:

manualy turn off hotspot
RaspberryConnect commented 1 year ago

Hi Yep this is a bit easier than You tube.

It looks like option 2 is installed.

There seems to be a conflict in what you seeing. The autohotspot is started by a service. If the service is not active you have no wifi at all. So the fact that you can connect to the home network says the service is working and known ssids are being read ok to activate that connection. When you are in Hotspot mode and run option 6 it just restarts the service as it does at boot. The service runs the command "sudo /usr/bin/autohotspot" that works if run manually. To try the service use to go from the Hotspot to a wifi network: sudo systemctl restart autohotspot but usually you won't need to do this.

When you sudo ./autohotspot-setup.sh -> (option 6) and say Nothing Happens, how are you determining that. Can wifi devices still see the RpiHotspot ssid and your home routers SSID? On the pi , If you use the command "ip a" is the Access Points ip still showing for the wlan0 (10.0.0.5) or does it have a network ip from your router probably starting with 192.168. It shouldn't have both.

If you wasn't using sudo you would get permissions issues so its not to do with that.

The other possibility is if option 1 & option 2 have been swapped between, even though it will get uninstalled, i'm wondering if and something hasn't deleted properly. The setups are not compatible as they have different ip addresses, displayed when each one is installed. Which may cause an issue with option 6.

I would try an uninstall with option 4, then reboot and install option 1 or 2. Reboot then try option 6.

On youtube comment: "Also, the hotspot does not start if there is no SSID in range" Can you confirm if you mean at boot up? If a connected SSID is lost the access point won't start until a reboot or sudo /usr/bin/autohotspot is run as the script only runs once at boot and doesn't monitor the signal. This can be achieved with a timer cron task which is described in the manual guides on the website.

I am not able to replicate this on my setup so it's not clear what your Pi is doing. If you can bullet point what you do from boot. ie confirming connection to your router and then that the hotspot is active or not etc that would be useful and I will do my best to help.

Option 6 is needed to force to an hotspot while your are near a known router but to go back to your router, restarting the service or manually running the autohotspot script will do the job.

mineCraft031801 commented 1 year ago

Thank you, I will look into it when I have time and write you back in the next few days.

mineCraft031801 commented 1 year ago

Process 1:

Process 2 (Raspi is outside range of a known wifi):

Maybe I don't really understand how the autohotspot as a whole should work or do you think I understood it? However, the raspi should start the ap if it does not detect any known wifi, right?

RaspberryConnect commented 1 year ago

Hi I think you understand it, what you are seeing on your system is causing strange behaviour. Did you try uninstalling it and then reinstalling it? if so was there any change?

Which Pi and OS are you using?

My confusion is if it is not configured right it won't create an access point at all or it won't connect to your network. You can demonstrate it is able to do both. So the config should be fine. The service must be running as you have some type of wifi, otherwise you would have none.

I will go back to basics, you will want the pi setup with a screen to check this. Boot up. It should connect to your Home network. The command 'ip a' should show that wlan0 ip address is 192.168.#.### open /etc/wpa_supplicant/wpa_supplicant.conf change the line for your ssid to an invalid name, network={ ssid="mySSID1" to network={ ssid="mySSID1-off"

now run sudo /usr/bin/autohotspot once it is finished it should give feedback to show it is in access point mode. 'ip a' should show wlan0 with an ip address of 10.0.0.5

now go back to wpa_supplicant.conf and change the SSID back to the correct name. re-run sudo /usr/bin/autohotspot There will be feedback on what it is doing, It should now reconnect to your network. confirm with 'ip a'

If any of these stages do not work: check the status of the service with sudo systemctl status autohotspot it should be active

other checks: etc/dhcpcd.conf has the line nohook wpa_supplicant

/etc/dnsmasq.conf has the correct IP range dhcp-range=10.0.0.50,10.0.0.150,12h

/etc/hostapd/hostapd.conf the line wpa_passphrase=1234567890 has at least 8 characters after =

sudo nano /etc/systemctl/system/autohotspot.service has the line ExecStart=/usr/bin/autohotspot and not ExecStart=/usr/bin/autohotspotN

/etc/network/interfaces only contains these lines.

interfaces(5) file used by ifup(8) and ifdown(8)

Please note that this file is written to be used with dhcpcd

For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

Include files from /etc/network/interfaces.d:

source-directory /etc/network/interfaces.d

The installer does check all these things but lets see if anything shows up.

Option 6 works slightly differently to create and access point but with the same method, but to go from the access point to network wifi the autohotspot script is run as above. If it works at bootup it should work then as well.

Hopefully something will stand out and we can look into it.

mineCraft031801 commented 1 year ago

Hello

Yes I un- and reinstalled it and it changes nothing. Still the same problems.

Rasperry Pi cat /sys/firmware/devicetree/base/model shows: Raspberry Pi 3 Model B Rev 1.2

cat /etc/os-release shows:

PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

I had no issue when doing the process with changing the network SSID and run sudo /usr/bin/autohotspot and ip a.

The line nohook wpa_supplicant exists in /etc/dhcpcd.conf at the very bottom.

in /etc/dnsmasq.conf i have the range 50 to 100 not 50 to 150. dhcp-range=10.0.0.50,10.0.0.100,12h

in /etc/hostapd/hostapd.conf I have not changed this line wpa_passphrase=1234567890

/etc/systemd/system/autohotspot.service contains

[Unit]
Description=Automatically generates a Hotspot when a valid SSID is not in range
After=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
[Install]
WantedBy=multi-user.target

/etc/network/interfaces contains these lines.

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
RaspberryConnect commented 1 year ago

Thanks for the outputs. It is all as it should be. re " i have the range 50 to 100 not 50 to 150" that's fine it is just the range of IP's that connected devices can have so you can have up to 50.

I have retested on my PI4 Bullseye setup which works the same and am not able to reproduce the issue. For Option 6 creating the access point is the custom bit that is in autohotspot-setup.sh. This would be the bit that goes wrong if anything. Going back to the network is the natural features of /usr/bin/autohotspot which is run through the service which opt 6 will then activate and is only one command. If it detects the access point is running, as it does in the first image from your message, it just issues the command, sudo systemctl restart autohotspot.service

This is the same process that is activated at boot and works at that stage. I don't see what is causing the issue as this works normally and if it is manually activated.

The only other reason would be that if it cannot get an ip address from the router within 20 seconds it will fall back to a access point. running option six more than once may get a connection Otherwise just try sudo systemctl restart autohotspot.service or sudo autohotspot (this will work if /usr/bin/ is in the path which it should be, otherwise sudo /usr/bin/autohotspot)

Sorry I can't be more help but until I can replicate the behaviour I can't see where the issue is. If will get back to you if anything pops up.

mineCraft031801 commented 1 year ago

Hello

Thanks for your help. I reinstalled it again and weirdly it works fine now.

RaspberryConnect commented 1 year ago

That's good to hear. That does seem a bit weird, everything looked ok. I will keep check on that option in case I come across it.

Glad you are up and running now.

apreucil commented 1 year ago

Having the same problem. Wondering if its a permission problem? Sudo is not in the autohotspot-setup.sh file (line 552). I added it and option 6 works for me, but still not able to get it to restart on reboot. Where is the program being called at reboot?

RaspberryConnect commented 1 year ago

Hi Anthony

The the script should be run with sudo so it's not required in the script. At boot/reboot the systemd service autohotspot.service is run once, which will run the bash script at /usr/bin/autohotspotN for option 1 and /usr/bin/autohotspot for option 2. Options 3 is a static configuration and can't be switched.

If you have any wifi at all then the service has run and the autohotspot/N script has also run and decided how to setup the wifi.

If you want to run these manually then also use sudo. Running manually will only go to an access point if a known wifi network is not in range.

apreucil commented 1 year ago

Thanks, I'll check in the boot and make sure it's installed correctly there. Something interesting is that when the pi boots up, I can see via the desktop that it initially begins to connect to the known router wifi (I am not setting up headless), but before it has a chance to fully connect the hotspot overrides it. Any insight there?

RaspberryConnect commented 1 year ago

If the script finds your routers SSID being broadcast it will activate the Pi's normal wifi which will make the connection to the router. In the same way it does if the autohotspot wasn't installed. The pi should be assigned an IP address by the router within a few seconds, for me it has always been under 6 seconds. If no IP address has been assigned within 20 seconds. The script will decide that the connection has failed and activates the access point so there is still wifi available.

The 4 guides at the bottom of my websites homepage have the full details for the manual setup of option 1,2 & 3. www.raspberryconnect.com/