Simple Temp monitor example using LCDLabel

Post

Posted
Rating:
#1 (In Topic #461)
Banned
This is a simple text based temperature display using LCDLabel
Made as an example it is simple and has many descriptive comments.

Gets temperature in one of 3 ways,
 Either runs a command and uses it's direct output or
 loads a temp file that stores the temperature as a simple number being the temperature X 1000

For raspberry pi many other systems simply give it the file path…
'/sys/class/thermal/thermal_zone0/temp'

Auto-detect checks ALL /sys/class/thermal zones and reports the hottest one found.

or it can use a shell command like sensors (from package lm-sensors) with grep and awk to get the temperature text.
Use 'sudo apt-get install lm-sensors' or use your package manager to install.

Command Example…

Code

sensors|grep 'Core 0'|awk '\{print $3}'
The above command runs 'sensors', uses grep to find the line with 'Core 0' in it that for me looks like this…
Core 0:       +45.0°C  (high = +82.0°C, crit = +100.0°C)

and then uses awk to get the 3rd bit of text '+45.0°C' (space separation makes 'Core 0:' 2 words)

Written in Gambas basic
Code has FULL comments explaining everything.
Has a minimum-requirement-installer to install required gambas components.

Other features…
Change background / text and highlight colour
Set Time delay between checks.
Show/Hide Window border/titlebar
Drag-Move/resize window

Bruce

(Note this is version 1.2 , scroll down for updated version 1.4)

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#2
Banned
updated this to auto-detect temp reading and resize window is possible.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
I am looking at the program and I think an option to display what the temperature relates to would be helpful. The display shows 52.0 then 44.0 and that's it. What is 52 or 44?

The program icon is missing.

<IMG src="https://www.cogier.com/gambas/MyTemp.png"> </IMG>

EDIT: -

I thought this might be fun, so I have made a simple version of this: -

Code (gambas)

  1. ' Gambas class file
  2.  
  3. '' Needs lm-sensors
  4. '' sudo apt-get -y install lm-sensors
  5.  
  6. Timer1 As Timer
  7. LCDLabel1 As LCDLabel
  8. HBox1 As HBox
  9. Label1 As Label
  10. Button1 As Button
  11. iCount As Integer
  12. sCmd As String = "sensors"
  13.  
  14. Public Sub Form_Open()
  15.  
  16.   BuildForm
  17.   Timer1.Trigger
  18.  
  19.  
  20. Public Sub Timer1_Timer()
  21.  
  22.   Dim iStart, iLen As Integer
  23.   Dim sSensors As String
  24.   Dim iLoop As Integer
  25.   Dim sValues As String[]
  26.  
  27.   Shell sCmd To sSensors
  28.   sValues = Split(sSensors, gb.NewLine, "", True)
  29.  
  30.   For iLoop = sValues.Max To 0 Step -1
  31.     If InStr(sValues[iLoop], "Core") = 0 Then sValues.Delete(iLoop, 1)
  32.   Next
  33.  
  34.   iStart = InStr(sValues[iCount], "+") + 1
  35.   iLen = InStr(sValues[iCount], " ", iStart) - iStart
  36.  
  37.   Label1.Text = Split(sValues[iCount], ":")[0]
  38.   LCDLabel1.Text = Mid(sValues[iCount], iStart, iLen)
  39.  
  40.   Inc iCount
  41.   If iCount > sValues.Max Then iCount = 0
  42.  
  43.  
  44. Public Sub Button1_Click()
  45.  
  46.   If sCmd = "sensors" Then
  47.     sCmd = "sensors -f"
  48.   Else
  49.     sCmd = "sensors"
  50.   Timer1.Trigger
  51.  
  52.  
  53. Public Sub BuildForm()
  54.  
  55.   With Me
  56.     .Height = 400
  57.     .Width = 875
  58.     .Padding = 5
  59.     .Arrangement = Arrange.Vertical
  60.     .Center
  61.     .Icon = Picture["icon:/24/hue"]
  62.  
  63.   With HBox1 = New HBox(Me) As "HBox1"
  64.     .Height = 35
  65.     .Width = 100
  66.  
  67.   With Label1 = New Label(HBox1) As "Label1"
  68.     .Height = 35
  69.     .Alignment = Align.Center
  70.     .Font.Size = 16
  71.     .Font.Bold = True
  72.     .Expand = True
  73.     .Border = Border.Plain
  74.  
  75.   With Button1 = New Button(HBox1) As "Button1"
  76.     .Height = 35
  77.     .Width = 35
  78.     .Text = "F/C°"
  79.  
  80.   With LCDLabel1 = New LCDLabel(Me) As "LCDLabel1"
  81.     .Padding = 20
  82.     .Sheared = True
  83.     .Background = Color.Black
  84.     .Foreground = Color.Black
  85.     .HighlightColor = Color.Green
  86.     .Expand = True
  87.  
  88.   With Timer1 = New Timer As "Timer1"
  89.     .Delay = 3000
  90.     .Enabled = True
  91.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned
I've updated the program in the first post to have a settings window to select sensor method
also updated the tooltips to show details about the sensor reading (as shown in pic)


hehe yeah a simple version is simple enough but i had to have some features ,
like i had to import and edit the LCDLabel.class just so i could adjust the LCD base colour (the not lit up bits)

This started as a simple example but went a bit past that over time  :roll:

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#5
Banned
Updates…..

Option to show on 2 screens.   opens another window so you can have one on each screen.

As well as the temp you can set a Date Format string /lang/format - Gambas Documentation and set the font/size/color

optional colour mode , you can set a cold/warm/hot colour and the main lcd colour blends according to temperature. (there is a test slider on the colour settings page)

enable/disable autostart with system on boot

Screenshot shows both screens.
Attachment
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
 It works well, nice job. My computer runs a lot hotter than yours, showing at around 60.00°.
Online now: No Back to the top
1 guest and 0 members have just viewed this.