Skip to content

Channel mismatch #506

Description

@Endrias90

[Workaround] Automatic channel selection for Wi-Fi Hotspot (linux-wifi-hotspot / wihotspot)

🐛 The Problem

When using linux-wifi-hotspot (or its GUI wihotspot) on Ubuntu, the hotspot often fails to start or clients cannot connect due to channel mismatch. This happens because:

· Your computer is connected to a Wi‑Fi network (say on 5 GHz channel 36).
· The hotspot tries to start on a channel that conflicts with the client mode of the same Wi‑Fi adapter.
· Many adapters cannot be both a client (connected to a network) and an access point on different channels simultaneously.

Manual workaround (already known):
Open the GUI → Advanced settings → check the Channel box → enter the channel number of your current Wi‑Fi network (find it with iw dev wlan0 info or nmcli). This works, but you have to do it every time you change networks or reboot.


✅ Automated Solution (Wrapper Script)

I created a small wrapper script that automatically detects the current Wi‑Fi channel and updates the configuration files before launching the hotspot GUI. Now you can simply click the icon and the hotspot starts with the correct channel – no manual intervention needed.

📦 Step‑by‑Step Implementation

  1. Locate the original .desktop launcher

Run:

find /usr/share/applications ~/.local/share/applications -name "*hotspot*" 2>/dev/null

On my system it was /usr/share/applications/wihotspot.desktop.
Check what command it runs:

grep "^Exec" /usr/share/applications/wihotspot.desktop

Example output:

Exec=bash -c 'CHAN=$(nmcli -f IN-USE,CHAN,SSID dev wifi | grep "*" | awk "{print $2}"); sed -i "s/^channel=.*/channel=$CHAN/" ~/.config/wihotspot.conf; wihotspot'
  1. Create the wrapper script

Create /usr/local/bin/wihotspot-channel-wrapper with the following content.
Important: Change WIFI_IFACE="wlp2s0" to match your Wi‑Fi interface (check with ip link show).

#!/bin/bash
# Auto‑channel wrapper for wihotspot

WIFI_IFACE="wlp2s0"                     # your Wi‑Fi interface
GLOBAL_CONF="/etc/create_ap.conf"
USER_CONF="$HOME/.config/wihotspot.conf"

# Get current channel using iw
CHANNEL=$(iw dev "$WIFI_IFACE" info 2>/dev/null | awk '/channel/ {print $2}' | tr -d ',')

# Fallback to nmcli if iw fails
if [ -z "$CHANNEL" ]; then
    CHANNEL=$(nmcli -t -f IN-USE,CHAN dev wifi | grep '^*' | cut -d: -f2)
fi

# Default to channel 1 if detection fails
if [ -z "$CHANNEL" ]; then
    CHANNEL=1
    echo "Could not detect channel, using default $CHANNEL"
else
    echo "Detected channel: $CHANNEL"
fi

# Update global config (uppercase CHANNEL)
if [ -f "$GLOBAL_CONF" ]; then
    sudo sed -i "s/^CHANNEL=.*/CHANNEL=$CHANNEL/" "$GLOBAL_CONF"
    sudo grep -q "^CHANNEL=" "$GLOBAL_CONF" || echo "CHANNEL=$CHANNEL" | sudo tee -a "$GLOBAL_CONF" >/dev/null
    # Force 2.4 GHz band to avoid 5 GHz issues
    sudo sed -i "s/^FREQ_BAND=.*/FREQ_BAND=2.4/" "$GLOBAL_CONF"
    sudo grep -q "^FREQ_BAND=" "$GLOBAL_CONF" || echo "FREQ_BAND=2.4" | sudo tee -a "$GLOBAL_CONF" >/dev/null
fi

# Update user config (lowercase channel)
if [ -f "$USER_CONF" ]; then
    sed -i "s/^channel=.*/channel=$CHANNEL/" "$USER_CONF"
    grep -q "^channel=" "$USER_CONF" || echo "channel=$CHANNEL" >> "$USER_CONF"
    # Also set freq_band if needed
    sed -i "s/^freq_band=.*/freq_band=2.4/" "$USER_CONF"
    grep -q "^freq_band=" "$USER_CONF" || echo "freq_band=2.4" >> "$USER_CONF"
fi

# Launch the real wihotspot
exec /usr/bin/wihotspot "$@"

Make it executable:

sudo chmod +x /usr/local/bin/wihotspot-channel-wrapper
  1. Modify the desktop launcher

Copy the original launcher to your local folder:

cp /usr/share/applications/wihotspot.desktop ~/.local/share/applications/

Edit the local copy:

nano ~/.local/share/applications/wihotspot.desktop

Replace the Exec= line with:

Exec=gnome-terminal -- sudo /usr/local/bin/wihotspot-channel-wrapper

(If you use a different terminal, replace gnome-terminal with your terminal command, e.g., xfce4-terminal, konsole, or x-terminal-emulator.)

Save the file.

  1. Test it

Click the hotspot icon. A terminal will open, ask for your sudo password, and then the hotspot GUI should appear – now using the correct channel automatically.

If the GUI doesn't appear, debug by running the wrapper manually:

sudo /usr/local/bin/wihotspot-channel-wrapper

🔍 Why This Works

· The script detects the channel of your current Wi‑Fi connection using iw (or falls back to nmcli).
· It updates both the global config (/etc/create_ap.conf) and the user config (~/.config/wihotspot.conf) – some versions of the GUI read one or the other.
· It forces the 2.4 GHz band (FREQ_BAND=2.4) as a safety net, completely avoiding 5 GHz conflicts.
· Running with sudo in a terminal ensures the GUI inherits your DISPLAY environment (unlike pkexec which caused "cannot open display" errors).


⚠️ Potential Issues & Fixes

· Wrong Wi‑Fi interface: Change WIFI_IFACE="wlp2s0" to match yours. Find it with ip link show | grep wl.
· Missing dependencies: Install iw and network-manager if not present:
sudo apt install iw network-manager
· Different hotspot executable: If your wihotspot is not at /usr/bin/wihotspot, find it with which wihotspot and update the last line of the script.
· pkexec alternative: If you prefer no terminal window, you can try pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" /usr/local/bin/wihotspot-channel-wrapper but it may still fail on some systems. The terminal method is more reliable.


↩️ Reverting to Original Behavior

To go back to the original launcher, simply remove the local .desktop file:

rm ~/.local/share/applications/wihotspot.desktop

The system will fall back to the original /usr/share/applications/wihotspot.desktop.


🧪 Tested On

· OS: Ubuntu 22.04 / 24.04
· Hardware: HP EliteBook 840 G3 (Wi‑Fi interface wlp2s0)
· Hotspot tool: wihotspot (linux-wifi-hotspot GUI)


💬 Conclusion

This workaround makes the Wi‑Fi hotspot completely automatic – no more manual channel adjustments. If you have improvements or encounter issues, please comment below! I hope this helps others facing the same problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions