24 lines
592 B
Python
24 lines
592 B
Python
from pc_utils import get_cpu_usage, get_memory_usage
|
|
import serial
|
|
from time import sleep
|
|
|
|
# connect to microbit
|
|
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
|
ser.flush()
|
|
print("Connected to microbit.")
|
|
|
|
while True:
|
|
sleep(1)
|
|
cpu_usage = get_cpu_usage()
|
|
memory_usage = get_memory_usage()
|
|
print(f"CPU Usage: {cpu_usage}%")
|
|
print(f"Memory Usage: {memory_usage}%")
|
|
print('--------')
|
|
|
|
data = [cpu_usage, memory_usage]
|
|
data_str = ','.join(map(str, data))
|
|
ser.write(data_str.encode('utf-8'))
|
|
ser.write(b'\n')
|
|
print(data_str.encode('utf-8'))
|
|
|