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

How to have Python and JS talk to each other?

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 1.1k 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.
  • L Offline
    lavolp3 Module Developer
    last edited by Aug 16, 2019, 10:27 PM

    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 Aug 16, 2019, 11:53 PM Reply Quote 0
    • S Offline
      sdetweil @lavolp3
      last edited by sdetweil Aug 17, 2019, 3:44 AM Aug 16, 2019, 11:53 PM

      @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

      L 1 Reply Last reply Aug 17, 2019, 6:41 AM Reply Quote 1
      • L Offline
        lavolp3 Module Developer @sdetweil
        last edited by Aug 17, 2019, 6:41 AM

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

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

        S 1 Reply Last reply Aug 17, 2019, 9:25 AM Reply Quote 0
        • S Offline
          strawberry 3.141 Project Sponsor Module Developer @lavolp3
          last edited by Aug 17, 2019, 9:25 AM

          @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 Aug 17, 2019, 11:16 AM Reply Quote 0
          • S Offline
            sdetweil @strawberry 3.141
            last edited by Aug 17, 2019, 11:16 AM

            @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
            1 / 1
            • First post
              1/5
              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