File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1
1
import RPi .GPIO as GPIO
2
2
import os
3
+ import re
3
4
import time
4
5
import subprocess
5
6
import reset_lib
6
7
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
+
7
22
GPIO .setmode (GPIO .BCM )
8
23
GPIO .setup (18 , GPIO .IN , pull_up_down = GPIO .PUD_DOWN )
9
24
10
25
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
12
28
config_hash = reset_lib .config_file_hash ()
13
29
ssid_prefix = config_hash ['ssid_prefix' ] + " "
14
30
reboot_required = False
You can’t perform that action at this time.
0 commit comments