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.

    Python in to the magic mirror.

    Scheduled Pinned Locked Moved Solved Troubleshooting
    43 Posts 4 Posters 19.9k 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.
    • P Offline
      paulvanderheijden90 @sdetweil
      last edited by paulvanderheijden90

      @sdetweil
      it is almost 50 char long. Im making a screen movie to let you see what I meen so it will become clear.
      Send it you in a couple of minutes

      Please see the full movie and notice the fail at 1:41
      https://www.youtube.com/watch?v=VBYL1j4p2aI&feature=youtu.be

      S 1 Reply Last reply Reply Quote 0
      • cowboysdudeC Offline
        cowboysdude Module Developer
        last edited by

        Very interested in this project… I have a python script to control my thermostat and was wondering how to get port it over…this may give me some answers :)

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @paulvanderheijden90
          last edited by

          @paulvanderheijden90 i submitted a pull request to your repo. this code runs for hours and hours…
          tiny changes from yours…

          the biggest is that the module filename is changed to match the name of the project
          (but that isn’t why it hung)… I actually don’t know the cause on your side…

          please download my code and try it out… let me know

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          P 1 Reply Last reply Reply Quote 0
          • P Offline
            paulvanderheijden90 @sdetweil
            last edited by

            @sdetweil @Sean
            Hello Guys Thank you for your vallueed help!

            I found out that the spawn function is called every time. so in a couple of minuts the spawn function has called 100 python projects. and this is blocking the raspberry

            I changed is to this: and now im going to Import the project of sdetweil in the software. But it is no more blocking.
            thank you guys

            /// node_helper.js
            
            
            
            const spawn = require("child_process").spawn
            
            
            
            var NodeHelper = require("node_helper")
            
            
            var process = spawn("python", ["/home/pi/src/P2000.py"])
            
            
            
            
            module.exports = NodeHelper.create({
            
            
            
              socketNotificationReceived: function(notification, payload) {
            
            
            
                switch(notification) {
            
            
            
                  case "GIVE_ME_DATA":
            
            
            	
            
                    this.job()
            
            
            
                    break
            
            
            
                }
            
            
            
              },
            
            
            
              job: function() {
            
            	
                
                process.stdout.on("data", (data)=>{
            
                  console.log(data)
            
                  var result = String.fromCharCode.apply(null, new Uint16Array((data)))
            
                  this.sendSocketNotification("HERE_IS_DATA", result)
            
            
            
                })
            
            
            
              }
            
            
            
            })
            
            
            
            ? 1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil
              last edited by

              does your python script continue to run once its started? the design of the node helper starting the script every second depends on the script ending…

              or as you have found you will kill the system (doesn’t matter, pi or larger)…

              you could do it your suggested way… but typically, one would add code in the notification received to start it once…

              Sam

              How to add modules

              learning how to use browser developers window for css changes

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

                @paulvanderheijden90
                You can put var process = spawn("python", ["/home/pi/src/P2000.py"])
                into start function if you want to execute when module is successfully loaded.

                Or you can make some START notification from main module then use it as trigger for execution. You can use socketNotificationReceived function to that purpose.

                Or, you can terminate spawned child process when it becomes needless.

                1 Reply Last reply Reply Quote 0
                • P Offline
                  paulvanderheijden90 @sdetweil
                  last edited by

                  @sdetweil
                  Yes one time start the python and it will run.

                  1 Reply Last reply Reply Quote 0
                  • 1
                  • 2
                  • 3
                  • 4
                  • 5
                  • 5 / 5
                  • 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