Thanks to this thread I was able to debug the issue with my MacBook Pro. Like many users here I really liked using the "Unlock with Apple Watch" feature but I didn't like it so much that I would give up my reliable wifi

I put together a few things that were useful to me that I thought others may like.
First, I build a TouchBar button for BetterTouchTool (
https://folivora.ai) that showed the txRate scaled from red to green:
JavaScript:
#!/usr/local/bin/node
import { WifiCheck } from './WifiCheck';
import * as chroma from 'chroma-js';
const GREY = '192,192,192,255';
try {
const lastTxRate = WifiCheck.getCheckResult()?.lastTxRate;
const scale = chroma.scale(['#f00', '#0f0']).domain([0, 866]).mode('lrgb').correctLightness(true);
const color = scale(lastTxRate).rgb().join(',');
console.log("{\"text\":\"" + lastTxRate + "Mbps\",\"background_color\": \"" + color + ",255\"}");
} catch (err) {
// ignore it since we are running for BTT
console.log("{\"text\":\"???\",\"background_color\": \"" + GREY + "\"}");
}
import * as child_process from 'child_process';
export class WifiCheck {
public static getCheckResult(): { lastTxRate: number, state: string } {
let resultString = undefined;
try {
const resultBuffer = child_process.execSync('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I', {
timeout: 1000, //1s timeout,
});
resultString = resultBuffer.toString();
} catch (err) {
// some error with the command
const status = err.status;
console.error(`exited with ${status}: `);
console.error(`\t${err.stdout}`);
resultString = undefined;
}
const resultObject = WifiCheck.objectFromResultString(resultString);
return resultObject;
}
private static objectFromResultString(resultString: string | undefined) {
const resultObject: any = {};
if (resultString) {
const resultLines = resultString.split('\n');
for (const line of resultLines) {
const [key, value] = line.replace(/\s+/g, '').split(':');
const number = Number(value);
resultObject[key] = !isNaN(number) ? number : value;
}
}
return resultObject;
}
}
Then, I built a TouchBar button that would show whether or not the awdl0 interface was active:
Bash:
#!/bin/bash
awdlstatus=$(ifconfig awdl0| fgrep status | cut -d: -f2 | sed 's/[[:space:]]*//g')
if [[ "active" == $awdlstatus ]]; then
echo "{\"text\":\"active\",\"background_color\": \"255,0,0,255\"}"
else
echo "{\"text\":\"inactive\",\"background_color\": \"192,192,192,255\"}"
fi
Finally, I built a swift script that turns on the awdl0 interface when the computer locks and then turns it off when the computer unlocks. I leave the "Unlock with Apple Watch" setting enabled all the time as this is needed and doesn't actually cause the issue. The issue is with the awdl0 interface being up. I was a bit lazy and just added my user to sudoers as not needed a password to run ifconfig. I could have made a specific script that just bounced the interface and setuid script but I didn't.
Swift:
#! swift
// impl hints from https://github.com/raygesualdo/amiunlocked
import Foundation
if #available(OSX 10.13, *) {
func runTask(script: String){
let task = Process()
task.executableURL = URL(fileURLWithPath: script)
task.launch()
task.waitUntilExit()
let status = task.terminationStatus
if(status != 0){
NSLog("Error running process: "+String(status));
}
}
let dnc = DistributedNotificationCenter.default()
dnc.addObserver(forName: .init("com.apple.screenIsLocked"), object: nil, queue: .main) { notification in
NSLog("Event: \(notification.name.rawValue)")
runTask(script: "/Users/andrewjanian/projects/netmon/bin/awdlUp.sh")
}
dnc.addObserver(forName: .init("com.apple.screenIsUnlocked"), object: nil, queue: .main) { notification in
NSLog("Event: \(notification.name.rawValue)")
runTask(script: "/Users/andrewjanian/projects/netmon/bin/awdlDown.sh")
}
} else {
fatalError("Must be on OSX 10.13 or greater")
}
// Let's do this thing!
NSLog("Process: started")
RunLoop.main.run()
Since making all these changes I have been able to have Unlock with Apple watch working fine AND stable wifi. If anyone has any questions let me know. I have also reached out to someone who is close to the Apple team to see if they could share the information on this thread and show them how bad of an issue this is.
I should also point out:
1)
This post was really helpful to me to help understand what was going on technically
2) I think one reason that this isn't getting more traction with Apple is that it only really happens when you are on a 5Ghz wifi channel that is 80Mhz wide. If you change the width to 40 or 20Mhz then you don't get the issue. I have a Google WiFi mesh and don't have control of the channel width. For most users that have the router that came with their cable modem I don't think they will have this issue.