CPU temp [Solved]

Hello guys!
Can someone help me, how to read every 5 secs cpu temperature and print it on sitemap?

I have frame “Diagnostics”, where i can review whats going on with the house, network and system.

Thanks!

What hardware are you using? What operating system?

Personally, I do this with SNMP, but it depends on what services your system provides as there are probably a few ways to do this, but without more information, it’s hard to say what’s possible, or best…

Hi Chris.

I’m using Raspberry pi 2 runing Jessie.

Take a look here. This shows how to set up an SNMP server on the PI. You can then use the SNMP binding to monitor the temperatures.

I do exactly this with my Synology NAS with the following item settings -:

Number	NAS_Temperature	"NAS CPU Temperature [%.1f]"	<network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.6574.1.2.0:60000]" }
Number	NAS_SystemFanFail  	"NAS System Fan [MAP(NASFanState.map):%s]"	    <network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.6574.1.4.1.0:60000]" }
Number	NAS_CPUFanFail  	"NAS CPU Fan [MAP(NASFanState.map):%s]"	    <network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.6574.1.4.2.0:60000]" }
Number	NAS_UPSLoad  	"NAS UPS Load [%d %%]"	    <network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.6574.4.2.12.1.0:60000]" }
Number	NAS_UPSBatteryLevel  	"NAS UPS Battery Level [%d %%]"	    <network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.6574.4.3.1.1.0:5000]" }
Number	NAS_UPSCPULoad1  	"NAS CPU Load (1min) [%.2f]"	    <network>	{ snmp="<[192.168.2.1:public:.1.3.6.1.4.1.2021.10.1.5.1:30000]" }

You’ll need to change the IP address to your PI (you might be able to use localhost) and you’ll need to ensure the OIDs are correct (that’s the long number after the public word) - the link above had them I think. The number on the end is the polling period. Depending on what the Pi supports, you can monitor quite a lot using this system (you just need to find the OID)…

Thanks for a tip!

I’m not sure, if i can run another service on my Pi. CPU shows about 5% usage with peaks around 20%.
I need to add mysql server to log data, so this will add some usage to the cpu and RAM.

For the other diag., I’m using system info binding. Could it be used too? Or execute the :
$ /opt/vc/bin/vcgencmd measure_temp with EXEC binding?

Hi Ondrej,

just write a script and use the vcgencmd and call this script using the exec binding.
here’s my script (rasptemp.sh) that reads the raspi cpu temps
#!/bin/bash TEMP=$(cat /sys/class/thermal/thermal_zone0/temp) awk "BEGIN {printf \"%.2f\n\", $TEMP/1000}"

the item would look like this

Number Temp_RaspWoZi "OH-Rasp2 Temperatur [%.1f °C]" <temperature> (HW_Temp) { exec="<[/opt/openhab/configurations/scripts/rasptemp.sh:60000:REGEX((.*?))]" }

i hope this helps…

No matter what you do, it will take some CPU. Loading another service doesn’t necessarily mean it will consume a load of CPU, just like running a standalone program to get the info doesn’t man it won’t… A well written service shouldn’t use any processing time if it’s not doing anything…

Anyway, there are many options, so pick search around and you should find one that suits :smile:

Hi,

thanks for the script. I copied the code into nano editor, then made it executable with chmod +x. When I run it trough SSH like this . ./cputemp.sh, i get 34.17. When i create item:

Number Cputemp “Temperature [%.1f °C]” { exec=“<[/etc/openhab/configurations/scripts/cputemp.sh:5000:REGEX((.*?))]” }

and sitemap:

Text item=Cputemp

I’m getting this:

Ok. some hints to check:

  • is the script executeable for the user openhab is running under?
  • i often had problems, because when executing shell scripts with ssh, it all works but openhab won’t get any results, because of different users.
  • You could check the logs (openhab.log or events.log) if they indicate any error when executing the script.
  • change the Item Type from Number to String and return only %s, that may display an errormessage.

I tried the String on sitemap, that showed nothing but - °C.

Then I navigated to /var/log/openhab to look at the logs. I found out, that there is no sign of executing the command at all. I got my exec binding in addons folder. It would show error with wrong user, right?

Not sure, what is the problem then.

Okay! That happened…

I reuploaded EXEC binding and it works :smiley:

Thanks for the tips!

Hi @chris, I’m struggling to work out the OIDs. As I understand it they refer to the virtual ‘devices’ that are then reported upon, is that right? How do I determine the OIDs for my Pi?

Also, is it possible to just get the CPU temp directly now?

> /opt/vc/bin/vcgencmd measure_temp
> temp=48.7'C

Thanks

The OID normally come from a standard database, so maybe doing a search for “SNMP CPU OID” might work - I’ve not tried. For my NAS, the supplier has a link to their database, and I normally use some sort of open source SNMP ‘walk’ program to query the results for testing.

Did you could try the OIDs that I’ve used in my example above - they are I think the standard ones.

Oh yeah, I googled it, and it looks like they are standard addresses on the Raspberry Pi.

Cheers

Thank you! Works fine and looks good with the Rotini gauges :slight_smile: :thumbsup: