From 3e0482c5c3ec62fcc69affdef7af5b7ad4f5e85d Mon Sep 17 00:00:00 2001 From: Lukasz Marcul Date: Thu, 16 Jul 2020 12:16:30 +0200 Subject: [PATCH] fix: Resolve invalid SSID of access point for Wi-Fi config --- libs/reset_device/reset.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libs/reset_device/reset.py b/libs/reset_device/reset.py index 950db042..e611122b 100644 --- a/libs/reset_device/reset.py +++ b/libs/reset_device/reset.py @@ -1,16 +1,32 @@ import RPi.GPIO as GPIO import os +import re import time import subprocess import reset_lib +def get_serial(): + pattern = r'^Serial\s*:\s*(\w+)$' + cpuinfo = subprocess.check_output(['cat', '/proc/cpuinfo']).decode() + lines = cpuinfo.split('\n') + + for line in lines: + match = re.match(pattern, line.strip()) + if not match: + continue + return match.group(1) + + return '' + + GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) counter = 0 -serial_last_four = subprocess.check_output(['cat', '/proc/cpuinfo'])[-5:-1].decode('utf-8') +serial_last_four = get_serial() +serial_last_four = serial_last_four[-4:] if len(serial_last_four) > 4 else serial_last_four # get last 4 characters of serial config_hash = reset_lib.config_file_hash() -ssid_prefix = config_hash['ssid_prefix'] + " " +ssid_prefix = config_hash['ssid_prefix'] reboot_required = False