mattlongman / Hassio-Access-Point

Hass.io addon to let you create a WiFi access point, perfect for using WiFi devices on off-grid installations.
MIT License
81 stars 62 forks source link

DHCP Not working? #1

Closed koffienl closed 3 years ago

koffienl commented 3 years ago

I'm scratching my head for a couple of hours but can't get it seem to work. Brand new HassOS install on RPi4. Installed the addon and configured as follow:

ssid: xxx
wpa_passphrase: xxx
channel: '6'
address: 192.168.4.1
netmask: 255.255.255.0
broadcast: 192.168.4.255
interface: wlan0
hide_ssid: '0'
dhcp: '1'
dhcp_start_addr: 192.168.4.10
dhcp_end_addr: 192.168.4.50
allow_mac_addresses: []
deny_mac_addresses: []
debug: 1

Clients can connect to the AP but without a IP address. The log file doesn't provide a clou at all:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Starting Hass.io Access Point Addon
# Setup interface:
Add to /etc/network/interfaces: iface wlan0 inet static
Run command: nmcli dev set wlan0 managed no
Run command: ip link set wlan0 down
Add to /etc/network/interfaces: address 192.168.4.1
Add to /etc/network/interfaces: netmask 255.255.255.0
Add to /etc/network/interfaces: broadcast 192.168.4.255
Run command: ip link set wlan0 up
# Setup hostapd:
Add to hostapd.conf: ssid=xxx
Add to hostapd.conf: wpa_passphrase=********
Add to hostapd.conf: channel=6
Add to hostapd.conf: ignore_broadcast_ssid=0
Add to hostapd.conf: macaddr_acl=0
Add to hostapd.conf: interface=wlan0
# DHCP enabled. Setup dnsmasq:
Add to dnsmasq.conf: dhcp-range=192.168.4.10,192.168.4.50,12h
Add to dnsmasq.conf: interface=wlan0
## Starting dnsmasq daemon
## Starting hostapd daemon
Configuration file: /hostapd.conf
rfkill: Cannot open RFKILL control device
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr dc:a6:32:0a:6c:bf and ssid "solar"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED 
wlan0: STA a4:34:d9:99:d8:dd IEEE 802.11: disassociated
wlan0: STA a4:34:d9:99:d8:dd IEEE 802.11: associated
wlan0: AP-STA-CONNECTED a4:34:d9:99:d8:dd
wlan0: STA a4:34:d9:99:d8:dd RADIUS: starting accounting session 6AD2A7256235BA6C
wlan0: STA a4:34:d9:99:d8:dd WPA: pairwise key handshake completed (RSN)
mattlongman commented 3 years ago

@koffienl thanks for the report. I'll do a fresh install later and see if I can re-create this. I'm assuming you've already checked this, but just in case: some OSs will let you use 'DHCP with manual address' so just make sure this is disabled.

If you want to test further, you could download to your local addons folder, set debug in the config to 0 (to quiet all other logging), and in run.sh, line 165, replace this:

killall -q dnsmasq; dnsmasq -C /dnsmasq.conf

with this:

killall -q dnsmasq; dnsmasq -k -C /dnsmasq.conf

I'm not too familiar with dnsmasq - I think -k should provide logging output, but if this doesn't work, try -d. I'm looking to add logging for the DHCP side.

koffienl commented 3 years ago

thanks for the quick response. The client is set to DHCP, tested with different devices (Windows 10, several android phones). and for what it's worth : the same pi with the same dnsmasq en hostappd config worked without a problem. I'll try your logging tip later.

mattlongman commented 3 years ago

I can recreate this on a Pi 4, 64bit Home Assistant OS.

I've tried a few different things but can't get it to reliably start.

When I enabled debug mode on dnsmasq, it said the interface wasn't available, so I suspect something is blocking dnsmasq from using wlan0 (or whichever interface is selected).

Might be worth adding sleep 10 (10 second pause) after dnsmasq starts but before hostapd as a test to see if hostapd started too quickly for the DHCP server.

I'll take another look tomorrow.

koffienl commented 3 years ago

Jup, looks like the wlan0 is somehow not available. Strange because a ifconfig show the wlan0

bash-5.0# dnsmasq --no-daemon --log-queries -C /dnsmasq.conf 
dnsmasq: started, version 2.81 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify dumpfile
dnsmasq: warning: interface wlan0 does not currently exist
dnsmasq: warning: no upstream servers configured
dnsmasq-dhcp: DHCP, IP range 192.168.4.10 -- 192.168.4.50, lease time 12h
dnsmasq: read /etc/hosts - 8 addresses
dnsmasq-dhcp: DHCP packet received on wlan0 which has no address
dnsmasq-dhcp: DHCP packet received on wlan0 which has no address
dnsmasq-dhcp: DHCP packet received on wlan0 which has no address

I'll try to dig in further.

mattlongman commented 3 years ago

Hi @koffienl - this should be fixed now.

dnsmasq: warning: interface wlan0 does not currently exist was occurring because wlan0 didn't have an IP address. Not sure why this has changed (although I hadn't tested on a 64bit Pi4 installation so can't say for sure it would've worked before) and why the IP isn't being set using the details from /etc/network/interfaces.

Added an ifconfig command to set the address in https://github.com/mattlongman/Hassio-Access-Point/commit/5ff3730011998ad83fbf89baed1b8bb56ab082b4#diff-f1580cf5a43af7a61ecf364087d219232417c2dda120f63adaf222cb373ea045 (and will test removing the interfaces file for a future update)

I've pushed it to 0.2.1 so please update the addon and give it a test.

koffienl commented 3 years ago

Yes, working after the update. Thanks!

wschaeffer commented 3 years ago

First: thanks for this add-on! Nice feature for IoT solutions :) However, DHCP is still not working for me. Running HassIO on Raspberry Pi 3B. Log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Starting Hass.io Access Point Addon
dnsmasq: failed to create listening socket for port 53: Address in use
Configuration file: /hostapd.conf
rfkill: Cannot open RFKILL control device
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr <mac> and ssid “said”
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED 
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: associated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: associated
wlan0: AP-STA-CONNECTED <mac>
wlan0: STA <mac> RADIUS: starting accounting session FFDEC520E090BD6A
wlan0: STA <mac> WPA: pairwise key handshake completed (RSN)
wlan0: STA 98:01:a7:97:ce:ff IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 98:01:a7:97:ce:ff
wlan0: STA 98:01:a7:97:ce:ff RADIUS: starting accounting session BBC0B5F54EC96473
wlan0: STA 98:01:a7:97:ce:ff WPA: pairwise key handshake completed (RSN)
wlan0: STA 98:01:a7:97:ce:ff IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 98:01:a7:97:ce:ff
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED <mac>
wlan0: STA <mac> IEEE 802.11: disassociated
wlan0: STA <mac> IEEE 802.11: associated
wlan0: AP-STA-CONNECTED <mac>
wlan0: STA <mac> RADIUS: starting accounting session 93D1B0C8FCBEF90A
wlan0: STA <mac> WPA: pairwise key handshake completed (RSN)
wlan0: STA <mac> IEEE 802.11: disassociated

I've hidden my mac-address and SSID ;)

It's rather strange that the client keeps reconnecting.

mattlongman commented 3 years ago

This stands out:

dnsmasq: failed to create listening socket for port 53: Address in use

Are you using any other add-ons that would provide DNS?

Try copying the add-on to your local add-ons directory, and add port=0 to dnsmasq.conf and see if that works.

I've created a new issue (see below), so if that still doesn't work, update that with your config & which other add-ons that you have running and I'll take a look tomorrow. I'll also look at adding some options to configure/disable DNS.