On my Raspberry Pies I can obtain the CPU temperature with an exec node calling vcgencmd measure_temp
Despite my almost total lack of knowledge of Windows OS, I am responsible for the health of a PC on the other side of the world and need to monitor the CPU temperature and send it by MQTT, so I am installing Node-red.
I have a bat file which works to obtain the temperature, unfortunately it has to be run as administrator.
@echo off
for /f "skip=1 tokens=2 delims==" %%A in ('wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value') do set /a "HunDegCel=(%%~A*10)-27315"
echo %HunDegCel:~0,-2%.%HunDegCel:~-2% Degrees Celsius
Can I run this file as administrator via the exec node?
Is there a better solution?
I have looked at @BartButenaers' 6 year old node-red-contrib-cpu but on two different PCs it gives a null value for temperature:
Grr!
I can add my user to "Performance Monitor Users" with net localhost "Performance Monitor Users" mememe /add
akrhuler's version of lusrmgr.exe is accepted by my antivirus and confirms that the user is a member of the group, but still getting null CPU info in Node-red.
If I run Node-red as administrator it works - 28.8 degrees (is that all?)
But how to run Node-red as an administrator on startup?
Thanks for all contributions so far, considering them in turn!
You might get away with adding the account to Power Users group.
As for running node-red on startup, I recommend using nssm to run it as a service (you can specify the "log on" account in the NSSM UI)
This doc: Run Node-RED as a service on Windows • FlowFuse has much of the detail you will need (albeit it is about running the Node-RED under the FlowFuse device agent, most of the info is relevant)
@zenofmud the batch file your link gives is where I started. It works but only when run as an administrator.
I can make it run as an administrator by making a shortcut but then Windows asks me if I want to allow it to make changes, and it seems you can't run the shortcut link from Node-red anyway.
It does make sense I suppose to make it hard to automatically run admin code at startup.
Can't see why CPU temperature is not available to a normal users command line though.
Not a good thing to do from a security standpoint. Instead, I'd write a powershell script to get the info, and configure Windows task manager to run it every 1 minute using SYSTEM privalages starting before login. That should be more than enough.
The script would either call a Node-RED http endpoint to send the data or you might find an MQTT library for PowerShell to send there directly.
I have seen suggestions online that the systeminfo/wmi data is not CPU temperature but some other motherboard sensor and sadly it seems likely to be true.
Configure WIndows task manager ...
Is that using Task Scheduler? I have defined tasks over and over on this PC but after a reboot I see no sign of them, nor evidence of them having run.
Yet Node-red did start, albeit not as administrator.
But I am thinking that the actual CPU temperature is not available to any command line tools.
Looking at the issues recorded for systeminformation referencing cpuTemperature, this most probably is to be confirmed. One user claims to have found an alternative way to get correct values though...
Well what sensors are available is largely dependent on the motherboard I believe. But on my Lenovo MiniPC, the CPU temps are certainly exposed to HWInfo
GPU temps also available.
But I wonder if something like this might work for you?