Mam odpalone Rapsberry na Virtualboxie i za zadanie mam stworzyc graf pokazujacy temp procka
( https://projects.raspberrypi.org/en/pro ... ture-log/0 )
tylko ze to nie mozliwe jadac na VB, i napisalem kod :
Kod: Zaznacz cały
import random
temperautur = random.uniform(40, 60)
print(temperautur)
Kod: Zaznacz cały
from gpiozero import CPUTemperature
from time import sleep, strftime, time
import matplotlib.pyplot as plt
cpu = CPUTemperature()
plt.ion()
x = []
y = []
def write_temp(temp):
with open("/home/pi/cpu_temp.csv", "a") as log:
log.write("{0},{1}\n".format(strftime("%Y-%m-%d %H:%M:%S"),str(temp)))
def graph(temp):
y.append(temp)
x.append(time())
plt.clf()
plt.scatter(x,y)
plt.plot(x,y)
plt.draw()
while True:
temp = cpu.temperature
write_temp(temp)
graph(temp)
plt.pause(1)