DietPi-Automation: Enable both WiFi and Ethernet adapters for WiFi Hotspot

Hi all, I’m trying to configure DietPi using DietPi-Automation to create a WiFi Hotspot.

I need to enable both the WiFi adapter (for the hotspot) and Ethernet adapter (for the internet connection) of my Raspberry Pi 4.
So, I’ve set the following in the dietpi.txt file:

##### Network Options #####
# Enable Ethernet or WiFi adapter: 1=enable | 0=disable
# - If both Ethernet and WiFi are enabled, WiFi will take priority and Ethernet will be disabled.
# - If using WiFi, please edit dietpi-wifi.txt to pre-enter credentials.
AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=1

But, as the comment suggests, WiFi takes priority and Ethernet is disabled. Therefore, the setup get stuck on the internet connection check, since I haven’t configured any WiFi credential.

I’ve tried also the following configuration:

##### Network Options #####
# Enable Ethernet or WiFi adapter: 1=enable | 0=disable
# - If both Ethernet and WiFi are enabled, WiFi will take priority and Ethernet will be disabled.
# - If using WiFi, please edit dietpi-wifi.txt to pre-enter credentials.
AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0

But in this case the WiFi Hotspot installation fails here:

Setting up isc-dhcp-server (4.4.1-2) ...
Generating /etc/default/isc-dhcp-server...
Job for isc-dhcp-server.service failed because the control process exited with error code.
See "systemctl status isc-dhcp-server.service" and "journalctl -xe" for details.
invoke-rc.d: initscript isc-dhcp-server, action "start" failed.
● isc-dhcp-server.service - LSB: DHCP server
   Loaded: loaded (/etc/init.d/isc-dhcp-server; generated)
   Active: failed (Result: exit-code) since Sat 2021-06-12 17:53:50 CEST; 28ms ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1918 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=1/FAILURE)

Jun 12 17:53:48 DietPi dhcpd[1930]: bugs on either our web page at www.isc.org or in the README file
Jun 12 17:53:48 DietPi dhcpd[1930]: before submitting a bug.  These pages explain the proper
Jun 12 17:53:48 DietPi dhcpd[1930]: process and the information we find helpful for debugging.
Jun 12 17:53:48 DietPi dhcpd[1930]:
Jun 12 17:53:48 DietPi dhcpd[1930]: exiting.
Jun 12 17:53:50 DietPi isc-dhcp-server[1918]: Starting ISC DHCPv4 server: dhcpdcheck syslog for diagnostics. ... failed!
Jun 12 17:53:50 DietPi isc-dhcp-server[1918]:  failed!
Jun 12 17:53:50 DietPi systemd[1]: isc-dhcp-server.service: Control process exited, code=exited, status=1/FAILURE
Jun 12 17:53:50 DietPi systemd[1]: isc-dhcp-server.service: Failed with result 'exit-code'.
Jun 12 17:53:50 DietPi systemd[1]: Failed to start LSB: DHCP server.

What can I do?
Thank you very much for your help.

let’s check with the developer

MichaIng
can you have a look pls. Is this something working at all? or should we disable HotSpot for interactive installations?

Hmm actually the WiFi modules are re-enabled during WiFi HotSpot installation: https://github.com/MichaIng/DietPi/blob/4a3767b/dietpi/dietpi-software#L5095-L5113

I mean e.g. in case of RPi, a reboot is required to have it really enabled, so an interactive install would then fail, as the WiFi criteria fails: https://github.com/MichaIng/DietPi/blob/4a3767b/dietpi/dietpi-software#L16444-L16490

But that check is not performed when doing CLI or non-interactive/automation installs and during first boot it does not play a role, since onboard WiFi is enabled on first boot and to really disable it, a reboot is required as well.

So now this happens during DHCP server install, with the auto-generated configuration, before the WiFi modules are (re-)enabled. What is the content of that config file?

cat /etc/default/isc-dhcp-server

Probably we need to enable the modules first, or we should even generate the config files before installing the package.

So, I’ve done some tests and that’s what I’ve found out.

On first boot, the WiFi Hotspot is created but is unaccessible because the isc-dhcp-server service fails to start.
This because the wlan0 interface is disabled on first boot, a reboot solves the problem since the WiFi Hotspot installation enables it. I’ve tried to enable the wlan0 interface before installing the isc-dhcp-server package (and so before starting the service) but nothing changes. The only way to get rid of that error seems to be to avoid starting the service on first boot.
As requested by MichaIng, this is the content of the isc-dhcp-server config file:

$ cat /etc/default/isc-dhcp-server
INTERFACESv4="wlan0"

However, after a reboot, the isc-dhcp-server service works fine but the WiFi Hotspot is not created. That’s because, in case of the RPi, the onboard wifi module is not enabled by the WiFi Hotspot installation. I don’t know if it is a bug or it is an intended behaviour but it needs to be enabled with:

/boot/dietpi/func/dietpi-set_hardware wifimodules onboard_enable

Also, during WiFi Hotspot installation, would be nice to set the wifi country code with something like this (note: I don’t really know how to access the properties set in /boot/dietpi.txt, the codebase is new for me, so I assume that they are environment variables):

/boot/dietpi/func/dietpi-set_hardware wificountrycode $AUTO_SETUP_NET_WIFI_COUNTRY_CODE

How did you try that? I just reviewed the image, and firmware-wise (/boot/config.txt), the onboard WiFi device isn’t disabled, so it should be possible to enable it without reboot. Otherwise every regular WiFi setup on first boot would fail as well.

But you are right that onboard_enable is missing. So while it should succeed in first boot, it would fail after reboot, as then the disabled device setting in /boot/config.txt kicks in. Okay so on first boot, wlan0 is assured to be onboard WiFi, as it is enabled (firmware-wise) and WiFi Hotspot by default uses wlan0. This means at least on first boot, we need to enable onboard WiFi explicitly, when WiFi Hotpost is installed. When this is done after first boot, the (interactive) menu throws an error when no WiFi interface has been found, so then it is okay that users enable it in network settings first. We could even offer that when we know it’s an RPi model with onboard WiFi and see it disabled.

The country code is applied automatically on first boot and applied to /etc/default/crda to be loaded on every next boot via udev rules, as fast as the WiFi device is attached/found by the kernel, but indeed only when WiFi is enabled dietpi.txt wise. Actually it makes sense to do that regardless whether WiFi is enabled or not, so that the correct country code is applied as fast as any WiFi adapter is enabled.

I’ve tried that by directly modifying the /boot/dietpi/dietpi-software script before inserting the SD card on my RPi. In particular, I moved the line in which the WiFi modules are enabled on top of the routine and added the onboard_enable:

software_id=60 # WiFi Hotspot
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == 1 )); then

	Banner_Installing
	
	# Enable WiFi modules
	/boot/dietpi/func/dietpi-set_hardware wifimodules onboard_enable
	/boot/dietpi/func/dietpi-set_hardware wifimodules enable

	local packages=('hostapd' 'isc-dhcp-server' 'iptables' 'libnl-3-200')

	# RTL8188C* device and special Realtek hostapd package available
	lsusb | grep -qi 'RTL8188C' && apt-cache dumpavail | grep -qE '^P(ackage|rovides):.* hostapd-realtek(,|$)' && packages[0]='hostapd-realtek'

	G_AGI "${packages[@]}"

	# Unmask hostapd service: https://github.com/MichaIng/DietPi/issues/2962
	G_EXEC systemctl unmask hostapd

fi

You are right, a reboot is actually not required to enable the onboard WiFi. In fact, if I run dietpi-services restart isc-dhcp-server after the first run the service starts flawlessly. However, although the WiFi Hotspot is created and accessible, networking seems to not work. I tried to connect to the hotspot from my PC and ssh into the RPi with ssh dietpi@192.168.42.1 but nothing happens. After a reboot everything works, so I think that it is required for all the changes in https://github.com/MichaIng/DietPi/blob/4a3767b2168fc6ca4eeb1efc29703d190e24dc3b/dietpi/dietpi-software#L9974-L10062 to take effect.

In conclusion I would say that these features should be added to the WiFi Hotspot installation:

  1. Enable the onboard WiFi
  2. Set the WiFi country code
  3. Require a reboot

In the meanwhile, for anyone interested, I share my workaround which solves the original problem.

dietpi.txt

...
AUTO_SETUP_NET_ETHERNET_ENABLED=1
AUTO_SETUP_NET_WIFI_ENABLED=0
AUTO_SETUP_NET_WIFI_COUNTRY_CODE=XX
AUTO_SETUP_AUTOMATED=1
AUTO_SETUP_INSTALL_SOFTWARE_ID=60
CONFIG_BOOT_WAIT_FOR_NETWORK=2
...

Automation_Custom_Script.sh

# Enable onboard WiFi
/boot/dietpi/func/dietpi-set_hardware wifimodules onboard_enable

# Set WiFi country code
/boot/dietpi/func/dietpi-set_hardware wificountrycode "$(sed -n '/^[[:blank:]]*AUTO_SETUP_NET_WIFI_COUNTRY_CODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)"

# Reboot
(while [ "$(</boot/dietpi/.install_stage)" != 2 ]; do sleep 1; done; /usr/sbin/reboot) > /dev/null 2>&1 &

Awesome, many thanks for sharing and verifying the solution :slight_smile:.