• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 7.3k 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.
  • S Offline
    strawberry 3.141 Project Sponsor Module Developer @justjim1220
    last edited by Oct 27, 2018, 6:39 AM

    @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
    • J Offline
      justjim1220 Module Developer @strawberry 3.141
      last edited by Oct 29, 2018, 1:33 AM

      @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 Oct 29, 2018, 6:54 AM Reply Quote 0
      • ? Offline
        A Former User @justjim1220
        last edited by A Former User Oct 29, 2018, 7:56 AM Oct 29, 2018, 6:54 AM

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

        J 1 Reply Last reply Oct 30, 2018, 12:07 AM Reply Quote 1
        • J Offline
          justjim1220 Module Developer @Guest
          last edited by Oct 30, 2018, 12:07 AM

          @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 Oct 30, 2018, 12:29 AM Reply Quote 0
          • ? Offline
            A Former User @justjim1220
            last edited by A Former User Oct 30, 2018, 12:30 AM Oct 30, 2018, 12:29 AM

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

            J 1 Reply Last reply Oct 30, 2018, 12:45 AM Reply Quote 1
            • J Offline
              justjim1220 Module Developer @Guest
              last edited by Oct 30, 2018, 12:45 AM

              @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 Oct 30, 2018, 1:34 AM Reply Quote 0
              • S Offline
                sdetweil @justjim1220
                last edited by Oct 30, 2018, 1:34 AM

                @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 Oct 30, 2018, 8:24 AM

                  @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
                  • 1
                  • 2
                  • 3
                  • 2 / 3
                  2 / 3
                  • First post
                    18/21
                    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