Skip to content

Commit 4681884

Browse files
committed
fix: Resolve invalid SSID of access point for Wi-Fi config
1 parent 51a0f18 commit 4681884

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

libs/reset_device/reset.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
import RPi.GPIO as GPIO
22
import os
3+
import re
34
import time
45
import subprocess
56
import reset_lib
67

8+
def get_serial():
9+
pattern = r'^Serial\s*:\s*(\w+)$'
10+
cpuinfo = subprocess.check_output(['cat', '/proc/cpuinfo']).decode()
11+
lines = cpuinfo.split('\n')
12+
13+
for line in lines:
14+
match = re.match(pattern, line.strip())
15+
if not match:
16+
continue
17+
return match.group(1)
18+
19+
return ''
20+
21+
722
GPIO.setmode(GPIO.BCM)
823
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
924

1025
counter = 0
11-
serial_last_four = subprocess.check_output(['cat', '/proc/cpuinfo'])[-5:-1].decode('utf-8')
26+
serial_last_four = get_serial()
27+
serial_last_four = serial_last_four[-4:] if len(serial_last_four) > 4 else serial_last_four # get last 4 characters of serial
1228
config_hash = reset_lib.config_file_hash()
1329
ssid_prefix = config_hash['ssid_prefix'] + " "
1430
reboot_required = False

0 commit comments

Comments
 (0)