theMusicMan
Posts: 114
Joined: Tue May 23, 2017 8:41 pm

How to assign a variable to CPU temp in python using vcgencmd measure_temp

Sat Feb 16, 2019 10:41 pm

Hi All

So I am simply wanting to create a Dashboard item using Adafruit.io that displays my RPi Cpu temp. I know there is a command such as

Code: Select all

import os
import time

def measure_temp():
        temp = os.popen("vcgencmd measure_temp").readline()
        return (temp.replace("temp=",""))

while True:
        print(measure_temp())
        time.sleep(1)
but... how do I assign the CPU temperature to a variable so that I can then send that variable to Adafruit please?

Ta

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to assign a variable to CPU temp in python using vcgencmd measure_temp

Sat Feb 16, 2019 10:58 pm

. how do I assign the CPU temperature to a variable

Code: Select all

my_temperature_variable = measure_temp()

theMusicMan
Posts: 114
Joined: Tue May 23, 2017 8:41 pm

Re: How to assign a variable to CPU temp in python using vcgencmd measure_temp

Sun Feb 17, 2019 3:18 am

B.Goode wrote:
Sat Feb 16, 2019 10:58 pm
. how do I assign the CPU temperature to a variable

Code: Select all

my_temperature_variable = measure_temp()
John runs to the woods, hides his face from mankind, and hangs his head in shame - never to be seen asking such a dumb question again.

:D

Thanks... and d'oh!!

Return to “Advanced users”