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 22.0k 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 @Guest
      last edited by

      @Sean Hello Sean,
      I was thinking somting was wrong because I see the buffer printing in the terminal showing:

      Buffer 48 61 6c 6c 6f 20 49 6b 20 62 65 6e 20 50 61 75 6c>

      i was trying to figure out the text line that it was representing but it was not showing something.

      So im happy you came up with the solution for the buffer.

      Unfortunly wenn at the var result code the magic mirror is crashing again and im not able to debug.
      Can you please heave a look at it

      /// node_helper.js
      
      const spawn = require("child_process").spawn
      
      var NodeHelper = require("node_helper")
      
      
      
      module.exports = NodeHelper.create({
      
        socketNotificationReceived: function(notification, payload) {
      
          switch(notification) {
      
            case "GIVE_ME_DATA":
      
              this.job()
      
              break
      
          }
      
        },
      
        job: function() {
      
          var process = spawn("python", ["/home/pi/src/test.py"])
      
          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
      • ? Offline
        A Former User @paulvanderheijden90
        last edited by

        @paulvanderheijden90
        Crashing? show me the error log.

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

          @sean said in Python in to the magic mirror.:

          Crashing? show me th

          App threw an error during load
          /home/pi/MagicMirror/modules/MMM-P2000/node_helper.js:76
          }.call(this, exports, require, module, __filename, __dirname); });
                                                                      ^
          
          SyntaxError: missing ) after argument list
              at createScript (vm.js:80:10)
              at Object.runInThisContext (vm.js:139:10)
              at Module._compile (module.js:606:28)
              at Object.Module._extensions..js (module.js:653:10)
              at Module.load (module.js:561:32)
              at tryModuleLoad (module.js:504:12)
              at Function.Module._load (module.js:496:3)
              at Module.require (module.js:586:17)
              at require (internal/module.js:11:18)
              at loadModule (/home/pi/MagicMirror/js/app.js:127:17)
          Whoops! There was an uncaught exception...
          /home/pi/MagicMirror/modules/MMM-P2000/node_helper.js:76
          }.call(this, exports, require, module, __filename, __dirname); });
                                                                      ^
          
          SyntaxError: missing ) after argument list
              at createScript (vm.js:80:10)
              at Object.runInThisContext (vm.js:139:10)
              at Module._compile (module.js:606:28)
              at Object.Module._extensions..js (module.js:653:10)
              at Module.load (module.js:561:32)
              at tryModuleLoad (module.js:504:12)
              at Function.Module._load (module.js:496:3)
              at Module.require (module.js:586:17)
              at require (internal/module.js:11:18)
              at loadModule (/home/pi/MagicMirror/js/app.js:127:17)
          MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
          If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
          Launching application.
          
          
          
          ? 1 Reply Last reply Reply Quote 0
          • ? Offline
            A Former User @paulvanderheijden90
            last edited by A Former User

            @paulvanderheijden90 said in Python in to the magic mirror.:
            Your log is telling you what is wrong.
            See the 76 line of node_helper.js. There could be missing ) after argument list.

            P 2 Replies Last reply Reply Quote 0
            • P Offline
              paulvanderheijden90 @Guest
              last edited by

              @sean So sorry you’re totally right… I was little bit confused by all the “at” conclusens.
              Im sorry I could had fixed that. And I did !

              Now it is working !!!
              So very nice ! im going to put this in my P2000 Raspberry python Programma. and will heave a lot of play with it.

              I will post/ show you the and result !

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

                Hello @Sean,
                Again thank you for the help. As I say after your help it was possible for me to “print” a string variable on the magic mirror module through python.
                But is was not able to put my P2000 alarm from the fire department on my screen. I noticed that it was a problem in the python script of the alarm.
                I used the stdout.write function again. like you told me. but I needed to add the flush function as wel.
                so now it is

                sys.stdout.write("hallo ik ben Paul")
                sys.stdout.flush()
                
                

                And then it was working !
                so thank you and here the result:

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

                  @sean
                  Hello Sean,
                  like I posted yesterday the app is running now. And it is showing wat I need to display. So im very happy.

                  But…
                  After a time ( more after a couple of runs ) the magic mirror app is crashed and freezed. So noting is updating any more.

                  My feeling is telling that the buffer were I put in the string value is filling up.

                  wenn i run the python script without the mirror it is running fine.

                  Please can you give me a help?

                  ? S 2 Replies Last reply Reply Quote 0
                  • ? Offline
                    A Former User @paulvanderheijden90
                    last edited by

                    @paulvanderheijden90
                    I have no idea about Python. I think you’d better reboot once or twice per daily to maintain RPI to be stable. You can do it with cron automatically.
                    The better approach would be implementing your job as native nodeJS MagicMirror module instead external python script.

                    P 1 Reply Last reply Reply Quote 0
                    • S Do not disturb
                      sdetweil @paulvanderheijden90
                      last edited by

                      @paulvanderheijden90 can u put your project on github and tell me where it is… I will look at it later today (us time)

                      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
                        Hallo Thank you for you’re Replay

                        I managed to upload the project on git hub ( new experience for me )
                        I uploaded the magic mirror Module ( P2000) I made and the node helper.

                        And I added the Python project.

                        The python project works fine on it self. But wenn I call ( spawn ) the python. The magic mirror application stops and freezes.

                        I think the flush/write fills the buffer and wenn it is it full the application is stoped.

                        https://github.com/paulvanderheijden90/MMM-P2000-python-connect

                        Here is the link

                        1 Reply Last reply Reply Quote 0
                        • S Do not disturb
                          sdetweil
                          last edited by

                          sorry, the is no PUBLIC repo there

                          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 @Guest
                            last edited by

                            @sean
                            Hello Sean,
                            The problem is not the python project. But I think the buffer is filling up ore something.

                            At this point all the massages are displayed on the mirror and after 15 min the mirror is freeze.

                            So im looking in to it.

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

                              @sdetweil fixed sorry

                              S 2 Replies Last reply Reply Quote 0
                              • S Do not disturb
                                sdetweil @paulvanderheijden90
                                last edited by sdetweil

                                @paulvanderheijden90 i don’t see the python module

                                you can add it to the directory and repo temporarily, then remove it later

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                1 Reply Last reply Reply Quote 0
                                • S Do not disturb
                                  sdetweil @paulvanderheijden90
                                  last edited by

                                  @paulvanderheijden90 so far I don’t see the same crash error…

                                  I did have to make some minor changes…

                                  Module name to match the git repo name
                                  path to a python script
                                  and change the display handling…
                                  rule is ONLY content change location is getDom()…
                                  other routines should store data and call updateDom(0 to signal that there ARE changes to display

                                  I’m gonna let it run for a while…

                                  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
                                    hello ! Thank you for your help so far.

                                    The python project is running fine on it selfs.

                                    But wenn I use it with the magic mirror the buffer of the magic mirror is filling. And freezes.

                                    the python project is made in combination with a Antenna.
                                    Setup looks like https://nl.oneguyoneblog.com/2016/08/09/p2000-ontvangen-decoderen-raspberry-pi/#comment-488

                                    so you’ll need to have data from the Multimom to get different information to send to the mirror

                                    S 1 Reply Last reply Reply Quote 0
                                    • S Do not disturb
                                      sdetweil @paulvanderheijden90
                                      last edited by

                                      @paulvanderheijden90 I wrote a little hello world python script to send data. All that is working as expected so far

                                      How big is the data buffer your python script sends?

                                      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 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 Do not disturb
                                            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

                                            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
                                            • 3
                                            • 2 / 3
                                            • 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