MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    help converting code for module...

    Scheduled Pinned Locked Moved Development
    21 Posts 4 Posters 10.6k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • justjim1220J Offline
      justjim1220 Module Developer
      last edited by justjim1220

      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 + " &nbsp  @  &nbsp " 
      		+ ((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! :face_with_stuck-out_tongue_winking_eye:

      "Life's Too Short To Dance With Ugly People"
      Jim Hallock - 1995

      strawberry 3.141S 1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @justjim1220
        last edited by strawberry 3.141

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

        Please create a github issue if you need help, so I can keep track

        justjim1220J 2 Replies Last reply Reply Quote 0
        • justjim1220J Offline
          justjim1220 Module Developer @strawberry 3.141
          last edited by

          @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
          

          "Life's Too Short To Dance With Ugly People"
          Jim Hallock - 1995

          1 Reply Last reply Reply Quote 0
          • justjim1220J Offline
            justjim1220 Module Developer @strawberry 3.141
            last edited by

            @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.

            "Life's Too Short To Dance With Ugly People"
            Jim Hallock - 1995

            strawberry 3.141S 1 Reply Last reply Reply Quote 0
            • strawberry 3.141S Offline
              strawberry 3.141 Project Sponsor Module Developer @justjim1220
              last edited by

              @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?

              Please create a github issue if you need help, so I can keep track

              justjim1220J 3 Replies Last reply Reply Quote 0
              • justjim1220J Offline
                justjim1220 Module Developer @strawberry 3.141
                last edited by

                @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 (<anonymous>)
                    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.<anonymous> (socketclient.js:25)
                    at r.emit (index.js:133)
                

                "Life's Too Short To Dance With Ugly People"
                Jim Hallock - 1995

                strawberry 3.141S 1 Reply Last reply Reply Quote 0
                • strawberry 3.141S Offline
                  strawberry 3.141 Project Sponsor Module Developer @justjim1220
                  last edited by

                  @justjim1220 if the variable doesn’t even exist, the rest of the code cannot work at all. first you should make sure that you have your data in the variable and then the second step is displaying it.

                  It seems like you’re trying to do the ui before you have the data.

                  Please create a github issue if you need help, so I can keep track

                  justjim1220J 1 Reply Last reply Reply Quote 0
                  • justjim1220J Offline
                    justjim1220 Module Developer @strawberry 3.141
                    last edited by justjim1220

                    @strawberry-3-141

                    I defined Temps. then got this in console…

                    MMM-PC-Stats.js:104 Uncaught (in promise) TypeError: Cannot read property '
                    ootwmi:MSAcpi_ThermalZoneTemperature' of undefined
                        at Class.getDom (MMM-PC-Stats.js:104)
                        at main.js:110
                        at new Promise (<anonymous>)
                        at updateDom (main.js:109)
                        at Object.updateDom (main.js:514)
                        at Class.updateDom (module.js:358)
                        at Class.socketNotificationReceived (MMM-PC-Stats.js:213)
                        at module.js:246
                        at r.<anonymous> (socketclient.js:25)
                        at r.emit (index.js:133)
                    

                    "Life's Too Short To Dance With Ugly People"
                    Jim Hallock - 1995

                    1 Reply Last reply Reply Quote 0
                    • justjim1220J Offline
                      justjim1220 Module Developer @strawberry 3.141
                      last edited by

                      @strawberry-3-141

                      I had a syntax error in the declaration of Temps.

                      I’m totally thinking this isn’t going to work.

                      I will probably need to find a different way,
                      figured if I could pull it from the SIMBIOS using a simple script, that maybe it could be pulled using a module for MM.

                      there are some open source apps for Windows that work to get the data, I will just have to study them and see what I can come up with.

                      Thanks for trying to help.

                      "Life's Too Short To Dance With Ugly People"
                      Jim Hallock - 1995

                      strawberry 3.141S 1 Reply Last reply Reply Quote 0
                      • strawberry 3.141S Offline
                        strawberry 3.141 Project Sponsor Module Developer @justjim1220
                        last edited by

                        @justjim1220 if you don’t even have the data in js, you can also execute it in the node helper and parse the response https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

                        Please create a github issue if you need help, so I can keep track

                        1 Reply Last reply Reply Quote 0
                        • justjim1220J Offline
                          justjim1220 Module Developer @strawberry 3.141
                          last edited by

                          @strawberry-3-141

                          What are the chances of being able to do what I had been attempting with this?
                          https://github.com/moxystudio/node-cross-spawn

                          And would it be possible to add to a current node_helper being used for linux, or would a separate node_helper or script need made?

                          "Life's Too Short To Dance With Ugly People"
                          Jim Hallock - 1995

                          ? 1 Reply Last reply Reply Quote 0
                          • ? Offline
                            A Former User @justjim1220
                            last edited by A Former User

                            @justjim1220

                            exec(“YOUR-SHELL-COMMAND”, (error, stdout, stderr)=>{
                              console.log(stdout)
                              // do your job with `stdout`
                            })
                            

                            I think you can get the result of any execution of shell script.

                            justjim1220J 1 Reply Last reply Reply Quote 1
                            • justjim1220J Offline
                              justjim1220 Module Developer @Guest
                              last edited by

                              @sean

                              Not sure I follow …

                              what would be my ‘shell command’?

                              "Life's Too Short To Dance With Ugly People"
                              Jim Hallock - 1995

                              ? 1 Reply Last reply Reply Quote 0
                              • ? Offline
                                A Former User @justjim1220
                                last edited by A Former User

                                @justjim1220
                                **
                                PS C:\WINDOWS\system32> get-temperature
                                **
                                I don’t know anything about your intention, but ‘get-temperature’ could be executable in your shell or terminal, it could be the one.

                                justjim1220J 1 Reply Last reply Reply Quote 1
                                • justjim1220J Offline
                                  justjim1220 Module Developer @Guest
                                  last edited by

                                  @sean

                                  Yes, that is the command to get the temps from the PC using powershell or command prompt…

                                  BUT, where to use the command in node_helper.js?

                                  OR, where to use the command in the module.js file?

                                  "Life's Too Short To Dance With Ugly People"
                                  Jim Hallock - 1995

                                  S ? 2 Replies Last reply Reply Quote 0
                                  • S Offline
                                    sdetweil @justjim1220
                                    last edited by

                                    @justjim1220 let’s look at the design of your module.

                                    How often do u need to get the temps?
                                    Is it on a timer, or some other mechanism?

                                    Anyhow, on that cycle, you would issue the ‘run’ of the powershell app in the node_helper.js, and capture it’s output.

                                    Then process the output, remove all the useless data. Then send the raw data to the module.js, who will then format the HTML in the get_dom() function for display

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    1 Reply Last reply Reply Quote 0
                                    • ? Offline
                                      A Former User @justjim1220
                                      last edited by

                                      @justjim1220

                                      
                                      const exec = require('child_process').exec
                                      var NodeHelper = require("node_helper")
                                      
                                      module.exports = NodeHelper.create({
                                        socketNotificationReceived: function(noti, payload) {
                                          if (noti == "GIVE_ME_RESULT") {
                                            setTimeout(()=>{
                                              exec("C:\WINDOWS\system32\get-temperature", //I don't know WINDOWS system at all. Is it right?
                                                (err, sto, ste) => {
                                                  if (!err) {
                                                    this.sendSocketNotification("HERE_IS_RESULT", sto)
                                                  } else {
                                                    console.log("Error", err)
                                                  }
                                                }
                                              )
                                            }, 1000)
                                          }
                                        }
                                      })
                                      

                                      It isn’t tested. But you can catch the idea.

                                      1 Reply Last reply Reply Quote 1

                                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                      With your input, this post could be even better 💗

                                      Register Login
                                      • 1
                                      • 2
                                      • 2 / 2
                                      • First post
                                        Last post
                                      Enjoying MagicMirror? Please consider a donation!
                                      MagicMirror created by Michael Teeuw.
                                      Forum managed by Sam, technical setup by Karsten.
                                      This forum is using NodeBB as its core | Contributors
                                      Contact | Privacy Policy