MagicMirror² v2.5.0 is available! For more information about this release, check out this topic.

help converting code for module...


  • Module Developer

    Anybody know how I can turn the following :

    function Get-Temperature {
    $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | where -Property instancename -EQ "ACPI\ThermalZone\TZ01_0"
    
    $currentTempKelvin = $t.CurrentTemperature / 10
    $currentTempCelsius = $currentTempKelvin - 273.15
    
    $currentTempFahrenheit = (9/5) * $currentTempCelsius + 32
    
    return $currentTempCelsius.ToString() + " C : " + $currentTempFahrenheit.ToString() + " F : " + $currentTempKelvin + "K"  
    }
    

    into MM module fomat?

    I tried this:

    getTemperature: function() {
    		t = getWmiObject = MSAcpi_ThermalZoneTemperature (Namespace = "root/wmi" | where (Property = instancename) (EQ = "ACPI\ThermalZone\TZ01_0"));
    		
    	    currentTempKelvin = $t.CurrentTemperature / 10;
    		currentTempCelsius = $currentTempKelvin - 273.15;
    		
    		currentTempFahrenheit = (9/5) * $currentTempCelsius + 32;
    		
    		return currentTempCelsius.ToString() + " C : " + currentTempFahrenheit.ToString() + " F : " + currentTempKelvin + "K";
    	},
    

    didn’t get any errors, but didn’t get any resulting expected outcome either…

    Any hints would be greatly appreciated!!!
    Thanks in advance! 🙃



  • @justjim1220 this is not JavaScript, there are errors on all lines. Not sure why you didn’t see errors, are you sure you called that function?


  • Module Developer

    @strawberry-3-141

    yeah, sorry, I see some of the errors, but not all of them.

    Want to hint me a little?


  • Module Developer

    I need to know how to reconfigure the second line for this work in an MM module…

    getTemperature: function() {
    	var t = getWmiObject = MSAcpi_ThermalZoneTemperature(Namespace = "root/wmi" | where (Property = instancename) && (EQ = "ACPI\ThermalZone\TZ01_0"));
    	currentTempKelvin = t.CurrentTemperature / 10;
    	currentTempCelsius = currentTempKelvin - 273.15;
    	currentTempFahrenheit = (9/5) * currentTempCelsius + 32;		
    	return currentTempCelsius + " C " + currentTempFahrenheit + " F : " + currentTempKelvin + "K";
    },
    

    I’m pretty sure rest of the function is ok. But, I could be wrong! 😞


  • Module Developer

    latest attempt with this code…

    var checkSensorTemps = Temps["\root\wmi:MSAcpi_ThermalZoneTemperature"]["ACPI\ThermalZone"]["THRM_0"];
    if (typeof checkSensorTemps !== "undefined") {
    
    	// Core Temps
    	var core0Temp = document.createElement("div");
    	core0Temp.classList.add("large", "bright", "core0Temp");
    	core0Temp.innerHTML = Stats.cpu.threads[i].name + "    @    " 
    		+ ((Temps["\root\wmi:MSAcpi_ThermalZoneTemperature"]["ACPI\ThermalZone"]["THRM_0"].value / 10) -273.15) + " °C "
    		+ ((((Temps["\root\wmi:MSAcpi_ThermalZoneTemperature"]["ACPI\ThermalZone"]["THRM_0"].value / 10) -273.15) * 9/5) + 32) + " °F "
    		+ (Temps["\root\wmi:MSAcpi_ThermalZoneTemperature"]["ACPI\ThermalZone"]["THRM_0"].value  / 10) + "°K";
    	wrapper.appendChild(core0Temp);
    }
    

    HELP! LMAO! 😜



  • @justjim1220 do you have a log of the structure of Temps


  • Module Developer

    @strawberry-3-141

    PS C:\WINDOWS\system32> powershell.exe Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
    
    
    __GENUS              : 2
    __CLASS              : MSAcpi_ThermalZoneTemperature
    __SUPERCLASS         : MSAcpi
    __DYNASTY            : MSAcpi
    __RELPATH            : MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\THRM_0"
    __PROPERTY_COUNT     : 12
    __DERIVATION         : {MSAcpi}
    __SERVER             : DESKTOP-BEUARKC
    __NAMESPACE          : root\wmi
    __PATH               : \\DESKTOP-BEUARKC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\THRM_0
                           "
    Active               : True
    ActiveTripPoint      : {0, 0, 0, 0...}
    ActiveTripPointCount : 0
    CriticalTripPoint    : 3762
    CurrentTemperature   : 3172
    InstanceName         : ACPI\ThermalZone\THRM_0
    PassiveTripPoint     : 3882
    Reserved             : 0
    SamplingPeriod       : 100
    ThermalConstant1     : 2
    ThermalConstant2     : 10
    ThermalStamp         : 25
    PSComputerName       : DESKTOP-BEUARKC
    

  • Module Developer

    @strawberry-3-141

    this script ran in powershell …

    function Get-Temperature {
        $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
        $returntemp = @()
    
        foreach ($temp in $t.CurrentTemperature)
        {
            $currentTempKelvin = $temp / 10
            $currentTempCelsius = $currentTempKelvin - 273.15
            $currentTempFahrenheit = (9/5) * $currentTempCelsius + 32
            $returntemp += $currentTempCelsius.ToString() + " C : " + $currentTempFahrenheit.ToString() + " F : " + $currentTempKelvin + "K"  
        }
        return $returntemp
    }
    

    gives the following output for a single core …

    PS C:\WINDOWS\system32> get-temperature
    44.05 C : 111.29 F : 317.2K
    

    I’m really only interested in a C and F result, no need for K that I can think of.



  • @justjim1220 I can’t work with your powershell logs. You’re trying to access the variable Temps in js like your first line. var checkSensorTemps = Temps["\root\wmi:MSAcpi_ThermalZoneTemperature"]["ACPI\ThermalZone"]["THRM_0"];
    can you do console.log(Temps) so I can see the structure?


  • Module Developer

    @strawberry-3-141

    it throws this error…

    Uncaught (in promise) ReferenceError: Temps is not defined
        at Class.getDom (MMM-PC-Stats.js:103)
        at main.js:110
        at new Promise ()
        at updateDom (main.js:109)
        at Object.updateDom (main.js:514)
        at Class.updateDom (module.js:358)
        at Class.socketNotificationReceived (MMM-PC-Stats.js:218)
        at module.js:246
        at r. (socketclient.js:25)
        at r.emit (index.js:133)