Skip to content

Commit 0bf6020

Browse files
authored
Update mesh_power_detective.py
Multiple bug fixes to network manager and pcie power detection.
1 parent a17a278 commit 0bf6020

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

MeshAnalyzer/files/mesh_power_detective.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,6 @@ def check_wifi_power_save(self):
6565
except:
6666
pass
6767

68-
# Check iwconfig power management
69-
try:
70-
result = subprocess.run(f"iwconfig {self.interface}",
71-
shell=True, capture_output=True, text=True, timeout=5)
72-
if "Power Management:on" in result.stdout:
73-
issues.append({
74-
'severity': 'high',
75-
'issue': 'iwconfig shows Power Management ON',
76-
'impact': 'Causes disconnects every 1-5 minutes',
77-
'fix': f'sudo iwconfig {self.interface} power off'
78-
})
79-
except:
80-
pass
81-
8268
return issues
8369

8470
def check_usb_autosuspend(self):
@@ -150,12 +136,13 @@ def check_pcie_aspm(self):
150136
if os.path.exists(aspm_path): # FIXED: was "asmp_path"
151137
with open(aspm_path, 'r') as f: # FIXED: was "asmp_path"
152138
policy = f.read().strip()
153-
if "powersave" in policy or "powersupersave" in policy:
139+
if policy[policy.find('[')+1:policy.find(']')] in ['default', 'powersave', 'powersupersave']:
154140
issues.append({
155141
'severity': 'medium',
156142
'issue': f'PCIe ASPM set to: {policy}',
157143
'impact': 'Can cause latency and brief disconnects',
158-
'fix': 'Add pcie_aspm=off to kernel boot parameters'
144+
'fix': 'Add pcie_aspm=off to kernel boot parameters',
145+
'manual_only': True
159146
})
160147
except:
161148
pass
@@ -168,16 +155,13 @@ def check_network_manager_power(self):
168155

169156
try:
170157
# Check if NetworkManager is managing power
171-
nm_conf_paths = [
172-
"/etc/NetworkManager/conf.d/default-wifi-powersave-on.conf",
173-
"/etc/NetworkManager/conf.d/wifi-powersave.conf"
174-
]
158+
nm_conf_paths = [f for f in glob.glob("/etc/NetworkManager/conf.d/*.conf") if os.path.isfile(f)]
175159

176160
for conf_path in nm_conf_paths:
177161
if os.path.exists(conf_path):
178162
with open(conf_path, 'r') as f:
179163
content = f.read()
180-
if "wifi.powersave = 3" in content or "wifi.powersave = 2" in content:
164+
if "wifi.powersave = 3" in content or "wifi.powersave = 1" in content or "wifi.powersave = 0" in content:
181165
issues.append({
182166
'severity': 'high',
183167
'issue': 'NetworkManager WiFi power saving enabled',
@@ -600,29 +584,21 @@ def _generate_report(self, issues):
600584
def _generate_fix_script(self, issues):
601585
"""Generate a script to fix all issues"""
602586
fixes = []
587+
manual_fixes = []
603588

604589
for category_issues in issues.values():
605590
for issue in category_issues:
606591
if 'fix' in issue and issue.get('severity') in ['high', 'medium']:
607-
fixes.append(issue['fix'])
608-
609-
if fixes:
610-
print("\n📝 Generated fix script: /tmp/fix_wifi_power.sh")
611-
with open("/tmp/fix_wifi_power.sh", "w") as f:
612-
f.write("#!/bin/bash\n")
613-
f.write("# WiFi Power Management Fixes\n")
614-
f.write("# Generated by mesh_power_detective.py\n\n")
615-
616-
f.write("echo 'Applying WiFi power management fixes...'\n\n")
617-
618-
for fix in fixes:
619-
f.write(f"echo 'Running: {fix}'\n")
620-
f.write(f"{fix}\n\n")
621-
622-
f.write("echo 'Fixes applied! Restart WiFi or reboot to ensure all changes take effect.'\n")
623-
624-
os.chmod("/tmp/fix_wifi_power.sh", 0o755)
625-
print("Run with: sudo /tmp/fix_wifi_power.sh")
592+
if issue.get('manual_only', False):
593+
manual_fixes.append(issue['fix'])
594+
else:
595+
fixes.append(issue['fix'])
596+
597+
if manual_fixes:
598+
print("\n⚠️ Manual fixes required (cannot be automated):")
599+
for fix in manual_fixes:
600+
print(f" • {fix}")
601+
print(" 💡 These require editing boot parameters or configuration files")
626602

627603

628604
# Usage example and testing

0 commit comments

Comments
 (0)