Skip to content

Commit 6b30566

Browse files
committed
Expose Raspberry Pi serial number, trim \n from cat outputs
1 parent a6b4b9d commit 6b30566

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
motor_trim_factor=float(bot_config.get("move_motor_trim", 1.0)),
2121
)
2222

23+
def getserial():
24+
# Extract serial from cpuinfo file
25+
cpuserial = "0000000000000000"
26+
try:
27+
f = open('/proc/cpuinfo','r')
28+
for line in f:
29+
if line[0:6]=='Serial':
30+
cpuserial = line[10:26]
31+
f.close()
32+
except:
33+
cpuserial = "ERROR000000000"
34+
35+
return cpuserial
36+
2337
prog = None
2438
prog_engine = ProgramEngine.get_instance()
2539

@@ -62,16 +76,16 @@ def info():
6276
except:
6377
backend_commit = 'undefined'
6478
try:
65-
coderbot_version = subprocess.check_output(["cat", "/etc/coderbot/version"]).decode('utf-8')[:-2]
79+
coderbot_version = subprocess.check_output(["cat", "/etc/coderbot/version"]).decode('utf-8').replace('\n', '')
6680
except:
6781
coderbot_version = 'undefined'
6882
try:
69-
kernel = subprocess.check_output(["uname", "-r"]).decode('utf-8')[:-2]
83+
kernel = subprocess.check_output(["uname", "-r"]).decode('utf-8').replace('\n', '')
7084
except:
7185
kernel = 'undefined'
7286

7387
try:
74-
update_status = subprocess.check_output(["cat", "/etc/coderbot/update_status"]).decode('utf-8')[:-2]
88+
update_status = subprocess.check_output(["cat", "/etc/coderbot/update_status"]).decode('utf-8').replace('\n', '')
7589
except:
7690
update_status = 'undefined'
7791

@@ -82,6 +96,7 @@ def info():
8296
"backend commit build": backend_commit,
8397
"kernel" : kernel,
8498
"update status": update_status,
99+
"serial": getserial()
85100
}
86101

87102

0 commit comments

Comments
 (0)