Report comment

Hi Greg, from your dhcpcd logs it shows wlan0: DHCP lease expired, this is why you are getting a 169.254. ip. The lease is managed by the router and the dhcp server. What should happen is each time you are issued an ip it is valid for a period of time such as 12 hours or 24 hours. When the wifi device is off and then brought back up the lease should be renewed. Your pi is not renewing the ip lease so it defaults to a local one. This is not the cause of the autohotspot script because all it does is take down wifi and bring it back up again.

The lines you have disabled would cause no wifi to be generated when you go from hotspot to wifi. So you may have wpa_supplicant running twice on your pi from some other network config. I presume your /etc/.network/interfaces file has no config for wlan0 or an entry for wpa_supplicant?

If you enter the command sudo dhclient -v you should get a line with your IP and renewal in 41568 seconds. the seconds may will be different. If this is really low then your lease will expire while your pi is active.

if you do sudo dhclient -v -r it should release the ip and create a new lease.
Try this with the autohotspot script enabled and disabled.

The file /var/lib/dhcp/dhclient.leases should give you some info on current ip lease times.

and sudo grep dhclient /var/log/syslog should tell you more on what it happening with your dhcp client.

You can take down and bring up with the following commands to see if your lease is being renewed with the autohotspot script disabled.
ip link set dev wlan0 down
ip link set dev wlan0 up

But something is not working properly on your network setup outside of the changes from the article. Disabling those lines should cause no network wifi from a hotspot on a standard network setup and have no effect if the wifi is already active.
In normal use the wifi device is not brought down so you never see the effect of the lease not renewing when it brought back up.

Can you confirm you /etc/wpa_supplicant/wpa_supplicant.conf file has the correct lines at the top of the file. As missing lines will cause issues

It should look like this but the country different if you are not in the UK

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
ssid="mySSID1"
psk="myPassword"
key_mgmt=WPA-PSK
}


Hopefully this highlight an underlying issue.