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.

    How to have Python and JS talk to each other?

    Scheduled Pinned Locked Moved Development
    5 Posts 3 Posters 1.3k Views 3 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.
    • lavolp3L Offline
      lavolp3 Module Developer
      last edited by

      Hi all,
      I have a question for the JS / Python pros out there:
      I have a python program doing some long lasting process and consistently printing out the progress of its work to the console. (I have it running in a tmux virtual shell)
      I was wondering what would be the best way to “include” this program into a mirror module.

      A first step would be to pass on the python stdout print to a JS module.
      What is the best way for that?
      Is there any way for a python program to “talk” to my JS module?

      Thanks for any help or hints!

      How to troubleshoot modules
      MMM-soccer v2, MMM-AVStock

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

        @lavolp3 in JavaScript, node_helper use the spawn function, and handle.stdout.on() method to get called when there is data from the python script

        https://www.freecodecamp.org/news/node-js-child-processes-everything-you-need-to-know-e69498fe970a/

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        lavolp3L 1 Reply Last reply Reply Quote 1
        • lavolp3L Offline
          lavolp3 Module Developer @sdetweil
          last edited by

          @sdetweil Great! Will have a look at it. Thank you Sam!

          How to troubleshoot modules
          MMM-soccer v2, MMM-AVStock

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

            @lavolp3 you can have a look into https://github.com/paviro/MMM-Facial-Recognition/blob/master/node_helper.js which is doing the communication between the python script and module

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

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

              @strawberry-3-141 and that uses a larger wrapper of python scripts called PythonShell

              Sam

              How to add modules

              learning how to use browser developers window for css changes

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