Skip to content

Commit 307b22a

Browse files
dbieberclaude
andcommitted
Replace wpa_supplicant with NetworkManager for WiFi management
- Update WiFi module to use NetworkManager (nmcli) instead of wpa_supplicant - Update command handlers to work with NetworkManager - Add a new wifi-scan command to scan for available networks - Add a new migrate_to_networkmanager.sh script to help with migration - Update installation instructions and add NetworkManager to dependencies - Add migration information to README 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f23f440 commit 307b22a

File tree

6 files changed

+447
-202
lines changed

6 files changed

+447
-202
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ See the [hardware guide](hardware.md) to know exactly what to buy.
6666

6767
See the [installation instructions](installation.md) to get started.
6868

69+
## Recent Updates
70+
71+
### NetworkManager Support
72+
Go Note Go now uses NetworkManager instead of wpa_supplicant for WiFi management.
73+
This provides a more robust networking solution with easier configuration options.
74+
75+
If you're updating from a previous version, run the migration script:
76+
```bash
77+
sudo /path/to/GoNoteGo/scripts/migrate_to_networkmanager.sh
78+
```
79+
80+
Benefits of NetworkManager:
81+
- Better handling of network connections
82+
- Improved stability and reliability
83+
- More configuration options
84+
- Better integration with modern Linux distributions
85+
6986
## History
7087

7188
[Learn about Go Note Go's predecessor "Shh Shell" here.](https://davidbieber.com/projects/shh-shell/)
Lines changed: 141 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""WiFi command handlers for Go Note Go."""
1+
"""WiFi command handlers for Go Note Go using NetworkManager."""
22
from gonotego.command_center import registry
33
from gonotego.command_center import system_commands
44
from gonotego.settings import wifi
@@ -11,117 +11,169 @@
1111
@register_command('wifi {} {}')
1212
@register_command('wpa {} {}')
1313
def add_wpa_wifi(ssid, psk):
14-
if '"' in ssid or '"' in psk:
15-
say('WiFi not set.')
16-
return
17-
18-
# Load existing networks
19-
networks = wifi.get_networks()
20-
21-
# Check if this network already exists
22-
for network in networks:
23-
if network.get('ssid') == ssid:
24-
network['psk'] = psk
25-
break
26-
else:
27-
# Network doesn't exist, add it
28-
networks.append({'ssid': ssid, 'psk': psk})
29-
30-
# Save updated networks
31-
wifi.save_networks(networks)
32-
33-
# Update wpa_supplicant.conf
34-
if wifi.update_wpa_supplicant_config():
35-
wifi.reconfigure_wifi()
36-
say(f'WiFi network {ssid} added.')
37-
else:
38-
say('Failed to update WiFi configuration.')
14+
if '"' in ssid or '"' in psk:
15+
say('WiFi not set.')
16+
return
17+
18+
# Load existing networks
19+
networks = wifi.get_networks()
20+
21+
# Check if this network already exists
22+
for network in networks:
23+
if network.get('ssid') == ssid:
24+
network['psk'] = psk
25+
break
26+
else:
27+
# Network doesn't exist, add it
28+
networks.append({'ssid': ssid, 'psk': psk})
29+
30+
# Save updated networks
31+
wifi.save_networks(networks)
32+
33+
# Update NetworkManager connections
34+
if wifi.update_network_connections():
35+
wifi.reconfigure_wifi()
36+
say(f'WiFi network {ssid} added.')
37+
else:
38+
say('Failed to update WiFi configuration.')
3939

4040

4141
@register_command('wifi {}')
4242
def add_wifi_no_psk(ssid):
43-
if '"' in ssid:
44-
say('WiFi not set.')
45-
return
46-
47-
# Load existing networks
48-
networks = wifi.get_networks()
49-
50-
# Check if this network already exists
51-
for network in networks:
52-
if network.get('ssid') == ssid:
53-
network.pop('psk', None) # Remove password if it exists
54-
break
55-
else:
56-
# Network doesn't exist, add it
57-
networks.append({'ssid': ssid})
58-
59-
# Save updated networks
60-
wifi.save_networks(networks)
61-
62-
# Update wpa_supplicant.conf
63-
if wifi.update_wpa_supplicant_config():
64-
wifi.reconfigure_wifi()
65-
say(f'Open WiFi network {ssid} added.')
66-
else:
67-
say('Failed to update WiFi configuration.')
43+
if '"' in ssid:
44+
say('WiFi not set.')
45+
return
46+
47+
# Load existing networks
48+
networks = wifi.get_networks()
49+
50+
# Check if this network already exists
51+
for network in networks:
52+
if network.get('ssid') == ssid:
53+
network.pop('psk', None) # Remove password if it exists
54+
break
55+
else:
56+
# Network doesn't exist, add it
57+
networks.append({'ssid': ssid})
58+
59+
# Save updated networks
60+
wifi.save_networks(networks)
61+
62+
# Update NetworkManager connections
63+
if wifi.update_network_connections():
64+
wifi.reconfigure_wifi()
65+
say(f'Open WiFi network {ssid} added.')
66+
else:
67+
say('Failed to update WiFi configuration.')
6868

6969

7070
@register_command('wifi-list')
7171
def list_wifi_networks():
72-
networks = wifi.get_networks()
73-
if not networks:
74-
say('No WiFi networks configured.')
75-
return
76-
77-
network_list = [f"{i+1}. {network['ssid']}" for i, network in enumerate(networks)]
78-
say('Configured WiFi networks: ' + ', '.join(network_list))
72+
networks = wifi.get_networks()
73+
if not networks:
74+
say('No WiFi networks configured.')
75+
return
76+
77+
network_list = [f"{i+1}. {network['ssid']}" for i, network in enumerate(networks)]
78+
say('Configured WiFi networks: ' + ', '.join(network_list))
7979

8080

8181
@register_command('wifi-migrate')
8282
def migrate_wifi_networks():
83-
"""Scan wpa_supplicant.conf and migrate existing networks to Redis."""
84-
networks = wifi.migrate_networks_from_wpa_supplicant()
85-
86-
if networks is None:
87-
say('WiFi configuration file not found or error reading it.')
88-
return
83+
"""Migrate existing networks from wpa_supplicant.conf to NetworkManager."""
84+
networks = wifi.migrate_networks_from_wpa_supplicant()
8985

90-
# Save the extracted networks to Redis
91-
if networks:
92-
wifi.save_networks(networks)
93-
say(f'Migrated {len(networks)} WiFi networks to settings.')
86+
if networks is None:
87+
say('WiFi configuration file not found or error reading it.')
88+
return
89+
90+
# Save the extracted networks to Redis
91+
if networks:
92+
wifi.save_networks(networks)
93+
say(f'Migrated {len(networks)} WiFi networks to settings.')
94+
95+
# Update NetworkManager connections
96+
wifi.update_network_connections()
97+
wifi.reconfigure_wifi()
98+
else:
99+
say('No WiFi networks found to migrate.')
100+
101+
102+
@register_command('wifi-nm-migrate')
103+
def migrate_from_networkmanager():
104+
"""Migrate existing NetworkManager connections to Go Note Go settings."""
105+
networks = wifi.migrate_from_networkmanger()
94106

95-
# Update wpa_supplicant.conf
96-
wifi.update_wpa_supplicant_config()
97-
else:
98-
say('No WiFi networks found to migrate.')
107+
if networks is None:
108+
say('Error reading NetworkManager connections.')
109+
return
110+
111+
# Save the extracted networks to Redis
112+
if networks:
113+
wifi.save_networks(networks)
114+
say(f'Migrated {len(networks)} WiFi networks from NetworkManager to settings.')
115+
else:
116+
say('No WiFi networks found to migrate.')
99117

100118

101119
@register_command('wifi-remove {}')
102120
def remove_wifi_network(ssid):
103-
networks = wifi.get_networks()
104-
initial_count = len(networks)
105-
106-
# Remove networks with matching SSID
107-
networks = [network for network in networks if network.get('ssid') != ssid]
108-
109-
if len(networks) < initial_count:
110-
# Save updated networks
111-
wifi.save_networks(networks)
121+
networks = wifi.get_networks()
122+
initial_count = len(networks)
123+
124+
# Remove networks with matching SSID
125+
networks = [network for network in networks if network.get('ssid') != ssid]
112126

113-
# Update wpa_supplicant.conf
114-
if wifi.update_wpa_supplicant_config():
115-
wifi.reconfigure_wifi()
116-
say(f'WiFi network {ssid} removed.')
127+
if len(networks) < initial_count:
128+
# Save updated networks
129+
wifi.save_networks(networks)
130+
131+
# Update NetworkManager connections
132+
if wifi.update_network_connections():
133+
wifi.reconfigure_wifi()
134+
say(f'WiFi network {ssid} removed.')
135+
else:
136+
say('Failed to update WiFi configuration.')
117137
else:
118-
say('Failed to update WiFi configuration.')
119-
else:
120-
say(f'WiFi network {ssid} not found.')
138+
say(f'WiFi network {ssid} not found.')
121139

122140

123141
@register_command('reconnect')
124142
@register_command('wifi-refresh')
125143
@register_command('wifi-reconfigure')
126144
def reconfigure_wifi():
127-
wifi.reconfigure_wifi()
145+
wifi.reconfigure_wifi()
146+
147+
148+
@register_command('wifi-scan')
149+
def scan_wifi_networks():
150+
"""Scan for available WiFi networks."""
151+
try:
152+
# Ensure the WiFi adapter is on
153+
shell('sudo nmcli radio wifi on')
154+
155+
# Scan for networks
156+
result = shell('nmcli -t -f SSID,SIGNAL,SECURITY device wifi list')
157+
158+
networks = []
159+
for line in result.stdout.strip().split('\n'):
160+
if line:
161+
parts = line.split(':', 2)
162+
if len(parts) >= 3 and parts[0]: # Ensure SSID is not empty
163+
ssid, signal, security = parts
164+
networks.append((ssid, int(signal), security))
165+
166+
# Sort by signal strength (descending)
167+
networks.sort(key=lambda x: x[1], reverse=True)
168+
169+
# Take the top 5 networks
170+
top_networks = networks[:5]
171+
172+
if top_networks:
173+
network_list = [f"{i+1}. {ssid} ({signal}%)"
174+
for i, (ssid, signal, _) in enumerate(top_networks)]
175+
say('Available WiFi networks: ' + ', '.join(network_list))
176+
else:
177+
say('No WiFi networks found.')
178+
except Exception as e:
179+
say(f'Error scanning for WiFi networks: {str(e)}')

gonotego/settings/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def do_POST(self):
176176
# Handle WiFi networks specially
177177
if key == 'WIFI_NETWORKS':
178178
wifi.save_networks(value)
179-
wifi.update_wpa_supplicant_config()
179+
wifi.update_network_connections()
180180
wifi.reconfigure_wifi()
181181
else:
182182
# For all other settings, just use settings.set

0 commit comments

Comments
 (0)