Skip to content

Commit b46aad2

Browse files
committed
add uptime, gpiozero
1 parent 7ff085d commit b46aad2

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

Diff for: coderbot/api.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import os
88
import subprocess
99
import urllib
10+
import uptime
11+
from gpiozero import CPUTemperature, Device
1012

1113
import connexion
1214
from flask import Response, request, send_file
@@ -54,17 +56,8 @@ def get_status():
5456
(Cached method)
5557
"""
5658

57-
temp = "undefined"
58-
try:
59-
temp = os.popen("vcgencmd measure_temp").readline().replace("temp=", "")
60-
except Exception:
61-
pass
62-
63-
uptime = 0
64-
try:
65-
uptime = subprocess.check_output(["uptime"]).decode('utf-8').replace('\n', '')
66-
except Exception:
67-
pass
59+
temp = str(CPUTemperature().temperature)
60+
uptime = uptime.uptime()
6861

6962
internet_status = False
7063
try:
@@ -84,18 +77,35 @@ def get_info():
8477
"""
8578
device = {}
8679
serial = get_serial()
87-
80+
board_info_dict = {}
8881
try:
8982
device = Balena.get_instance().device()
90-
logging.info("device: %s", str(device))
83+
logging.debug("device: %s", str(device))
84+
board_info = Device.pin_factory.board_info
85+
board_info_dict["model"] = board_info.model
86+
board_info_dict["revision"] = board_info.revision
87+
board_info_dict["released"] = board_info.released
88+
board_info_dict["manufacturer"] = board_info.manufacturer
89+
board_info_dict["soc"] = board_info.soc
90+
board_info_dict["pcb_revision"] = board_info.pcb_revision
91+
board_info_dict["memory"] = board_info.memory
92+
board_info_dict["storage"] = board_info.storage
93+
board_info_dict["usb"] = board_info.usb
94+
board_info_dict["usb3"] = board_info.usb3
95+
board_info_dict["ethernet"] = board_info.ethernet
96+
board_info_dict["eth_speed"] = board_info.eth_speed
97+
board_info_dict["wifi"] = board_info.wifi
98+
board_info_dict["bluetooth"] = board_info.bluetooth
99+
91100
except Exception:
92101
pass
93102

94103
return { 'release_commit': device.get("commit"),
95104
'coderbot_version': os.getenv("CODERBOT_VERSION"),
96105
'update_status': device.get("status"),
97106
'kernel': device.get("os_version"),
98-
'serial': serial }
107+
'serial': serial,
108+
'board_info': board_info_dict }
99109

100110
prog = None
101111
prog_engine = ProgramEngine.get_instance()

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ tinydb==4.8.0
55
# Misc utils
66
setuptools==69.2.0
77
event-channel==0.4.3
8+
gpiozero==2.0.1
9+
uptime==3.0.1
810

911
# IO extensions
1012
pigpio==1.78

0 commit comments

Comments
 (0)