Skip to content

Wifi-Diagnostic.sh: Bind checks to Wi-Fi interface and handle disconnected state - #91

Open
techmandan wants to merge 1 commit into
FrameworkComputer:mainfrom
techmandan:fix/issue-41-wifi-diagnostic-interface
Open

techmandan wants to merge 1 commit into
FrameworkComputer:mainfrom
techmandan:fix/issue-41-wifi-diagnostic-interface

Conversation

@techmandan

Copy link
Copy Markdown

Summary

 check_internet_connection
+  WIFI_INTERFACE=$(iw dev | awk '$1=="Interface"{print $2; exit}')
-  ping -c 4 8.8.8.8
+  ping -I "$WIFI_INTERFACE" -c 4 -W 3 8.8.8.8
-  grep -q "0% packet loss"               # matched "100% packet loss"
+  [ "$ping_exit" -eq 0 ] && grep -qE '(^|[^0-9])0% packet loss'

 check_wifi_interfaces
-  iw dev ... | while read -r interface   # subshell dropped SSID/POWER_SAVE
+  while read -r interface ... done < <(iw dev ...)

 perform_speed_test
-  speedtest-cli --secure                 # ran over Ethernet when Wi-Fi down
+  speedtest-cli --secure --source "$wifi_ip"   # skipped if Wi-Fi has no IPv4

 summarize_findings
+  guard empty/non-numeric frequency2, signal_abs, tx_bitrate, speedtest values before bc -l

Evidence

  • Before (stubbed Ethernet UP + wlp1s0 Not connected.):
    Exited 0; ran ping -c 4 8.8.8.8 and speedtest-cli --secure over Ethernet; lost SSID="N/A" in the piped subshell; printed empty - SSID: and [: : integer expression expected errors across summarize_findings.
  • After (bash -n + 3 stubbed end-to-end runs):
    • Ethernet UP + wlp1s0 disconnected (100% packet loss on ping -I wlp1s0): exits 1 cleanly, notes active non-Wi-Fi default route, skips speedtest-cli, zero stderr.
    • Wi-Fi connected (5180 MHz, -55 dBm, 240.0 MBit/s, 192.168.1.50) + Ethernet UP: invokes ping -I wlp1s0 and speedtest-cli --source 192.168.1.50, preserves SSID and insights, zero stderr.
    • Disconnected summarize_findings: prints N/A cleanly with zero bc or [ errors.

Merge Danger

Door: Two-way

Blast Radius: Low — isolated to Network-Diagnostic-Scripts/Wifi-Diagnostic.sh.

Fixes #41

…ected state

- Detect the Wi-Fi interface before running connectivity checks and bind
  ping to it with `-I` so an active Ethernet/USB-Ethernet route does not
  produce a false pass when Wi-Fi is down.
- Check ping's exit status and use a word boundary before `0% packet loss`
  so `100% packet loss` does not falsely match.
- Replace the piped `while read` loop in `check_wifi_interfaces` with
  process substitution so `SSID`, `POWER_SAVE`, and `interface` survive
  into `summarize_findings`.
- Bind `speedtest-cli` to the Wi-Fi interface IPv4 address (`--source`)
  and skip the speed test when Wi-Fi has no active IPv4 connection.
- Validate numeric fields before invoking `bc -l` in `summarize_findings`
  to prevent syntax and integer-expression errors when disconnected.

Fixes FrameworkComputer#41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The WiFi diagnostic does not work if there is another operational network interface

1 participant