Froggle
Posts: 3
Joined: Tue Mar 12, 2019 7:53 pm

Losing connection after setting up hotspot and connecting back to wifi

Tue Mar 12, 2019 8:02 pm

Hi there,

after tons of hours trying to fix the problem I still don't get it to work.
Thought my problem is related to the wifi bouncing one, but I don't get carrier lost nor does it disconnect from my router. (viewtopic.php?f=36&t=234058)

I got two Scripts: One to open the Hotspot, the other one to get connect the Pi itself back to a wifi network. The script to open the wifi hotspot works perfectly.
The other one connects the Pi to the network too, but then it gets tricky. Every one or two minute I'm losing my SSH-Connection but the Pi can still reach the internet. Sometimes my router says the Pi is still in the network but it has a "0.0.0.0" address assigned. Some moments later everything works fine. Then after hours the same procedure repeats.
I hope you can help me with this one.

The StartHotspotScript.sh

Code: Select all

#!/bin/bash

rm /etc/wpa_supplicant/wpa_supplicant.conf

systemctl stop dnsmasq #beforehand sudo apt-get install dnsmasq hostapd and disable them (no auto start)
systemctl stop hostapd

echo -e 'hostname\nclientid\npersistent\noption domain_name_servers, domain_name, domain_search, host_name\noption interface_mtu\nrequire dhcp_server_identifier\ninterface wlan0\n    static ip_address=192.168.4.1/24' | tee /etc/dhcpcd.conf

systemctl daemon-reload
service dhcpcd restart


echo -e 'interface=wlan0\n  dhcp-range=192.168.4.2,192.168.4.255,255.255.255.0,24h' | tee /etc/dnsmasq.conf

echo -e 'interface=wlan0\ndriver=nl80211\nssid=SomeSSID\nhw_mode=g\nchannel=6\nwmm_enabled=0\nauth_algs=1' | tee /etc/hostapd/hostapd.conf

echo -e 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' | tee /etc/default/hostapd

systemctl start hostapd
systemctl start dnsmasq
The StopHotspotAndConnectScript.sh

Code: Select all

#!/bin/bash

systemctl stop dnsmasq
systemctl stop hostapd

SSID=$1
PASSWORD=$2

echo -e 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\ncountry=DE\nnetwork={\n       ssid="'WiFiSSID"\n        psk="'Password"\n}' | tee /etc/wpa_supplicant/wpa_supplicant.conf

echo -e 'hostname\nclientid\npersistent\noption domain_name_servers, domain_name, domain_search, host_name\noption ntp_servers\noption interface_mtu\nrequire dhcp_server_identifier\nslaac private\ninterface wlan0 inet auto' | tee /etc/dhcpcd.conf

systemctl restart dhcpcd

Froggle
Posts: 3
Joined: Tue Mar 12, 2019 7:53 pm

Re: Losing connection after setting up hotspot and connecting back to wifi

Tue Mar 26, 2019 7:22 am

I can't find any rule about bumping, but my problem is still occurring and I can't find any solution

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Losing connection after setting up hotspot and connecting back to wifi

Tue Mar 26, 2019 9:34 am

Don't know if this will be of much help, but I see similarities with a problem I was having.
viewtopic.php?f=36&t=229968&p=1413254&h ... d#p1413254

Are you using Stretch or Jessie?

Since I got rid of dchpcd and using a static interface on one of the wlan0 interfaces then went to using dhcp to assign the address everything started to work properly. Like several other people in that thread there was no indication of what went wrong, it just stopped working.

Are you looking through /var/log/syslog and syslog.1 for any clues?

Froggle
Posts: 3
Joined: Tue Mar 12, 2019 7:53 pm

Re: Losing connection after setting up hotspot and connecting back to wifi

Wed Mar 27, 2019 8:08 am

davef wrote:
Tue Mar 26, 2019 9:34 am
Don't know if this will be of much help, but I see similarities with a problem I was having.
viewtopic.php?f=36&t=229968&p=1413254&h ... d#p1413254

Are you using Stretch or Jessie?

Since I got rid of dchpcd and using a static interface on one of the wlan0 interfaces then went to using dhcp to assign the address everything started to work properly. Like several other people in that thread there was no indication of what went wrong, it just stopped working.

Are you looking through /var/log/syslog and syslog.1 for any clues?
Hi there,
thanks for your answer. I'm using Raspbian Stretch Lite.

I don't know if its just the wifi interface that makes problems, because this morning I had the same problem of losing connection every minute with ethernet. I looked in my syslog but I'm not that experienced with linux to spot the faulty lines.
I've added the syslog below where it reboots over and over. At this point it is connected via ethernet and not via wifi.
https://file.io/ymvEJe

Thanks and best regards

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Losing connection after setting up hotspot and connecting back to wifi

Wed Mar 27, 2019 7:17 pm

I get <502 Bad Gateway> when I try to look at the file.

Return to “Networking and servers”