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.

    MMM-Remote-Control API Questions

    Scheduled Pinned Locked Moved Troubleshooting
    17 Posts 3 Posters 3.2k 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.
    • S Offline
      sgarg15
      last edited by sgarg15

      @Jopyth Hey so i was going through your MMM-Remote-Control API and i had some questions.
      So i am trying to make a python script that detects a swiping motion to then change pages, but since this is a seperatte python script (not in a module), the MMM-pages module cant accept the notifications given to it.
      So the creater of MMM-pages, told me if i had a look at your API i could possible achieve this. but after giving it a thorough read, i was having difficulty figuring it out.

      So essentially i wanted something like this

      def swiper():
        #code here to detect swipe
        if leftSwipe:
          #send a notification to pages to go left
        if rightSwipe:
          #send a notification to pages to go right
      
      1 Reply Last reply Reply Quote 0
      • S Offline
        sgarg15
        last edited by

        If you could help me achieve this, or give me some info that could help me do this i would really appreciate it

        1 Reply Last reply Reply Quote 0
        • S Offline
          sgarg15
          last edited by

          If anyone else who understands the API could help me out i would really appreaciate it as well @sdetweil

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

            @sgarg15 so, you need a node_helper for the python script to send the notice to(as it can launch the python script and read the messages) and then the node helper can send the notification up to its modulename.js, which can then send the notification.

            lots of modules work this way, PIR

            MMM-Swipe does this exact thing, which is what I think u want to use

            fork it, change the name, and modify the node_helper to launch your python script and accept your python messages

            Sam

            How to add modules

            learning how to use browser developers window for css changes

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

              @sdetweil If possible could you please give me an example of how i would do it, i dont know much about js. and i looked at the MMM-Swipe but i couldnt understand much

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

                @sgarg15 swipe isn’t a good example after all, uses a library which hides all that… nor PIR…

                your python script needs to run forever and put out messages for each movement it sees…

                then you use the nodejs Python_Shell library to launch it

                import {PythonShell} from 'python-shell';
                
                let pyshell = new PythonShell('my_script.py');  // < --- whatever your script name, in the module folder
                 
                // the .on handler gets called each time the pythin script writes a message to stdout
                pyshell.on('message', function (message) {
                  // received a message sent from the Python script (a simple "print" statement)
                  console.log(message);
                  // send info up to modulename.js
                  this.sendSocketNotification("movement", message)
                });
                

                Sam

                How to add modules

                learning how to use browser developers window for css changes

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

                  @sdetweil This may be a stupid question, but is there any way i can test this on my laptop, without the raspberry pi?

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

                    @sgarg15 of course. See my comments in .txt file include
                    https://forum.magicmirror.builders/topic/555/txt-file-include/57

                    Not the actual node_helper but the code inside. Of course u can install mm on your PC as well

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    S 3 Replies Last reply Reply Quote 0
                    • S Offline
                      sgarg15 @sdetweil
                      last edited by

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        sgarg15 @sdetweil
                        last edited by

                        @sdetweil

                        var dataFile=["Archer S01E02Someshow.tv",
                        "Archer S01E03Someshow .tv",
                        "Archer S01e02Someshow .tv",
                        "Archer S01E04Someshow .tv",
                        "Archer S01E05someshow .tv",
                        "Archer s01E02Someshow .tv",
                        "Archer S01E09Someshow .tv",
                        ]
                        var counter1=10
                        
                        
                                            if(dataFile){
                                                var output_list= [];
                                                // should make this a config variable by adding to module defaults
                                               // then would be this.config.counter
                                               // get display limit, 10 if not specified in defaults
                                               var counter=counter1 || 10
                                                // setup regex, no i  no g (only once, and case sensitive)
                                                var splitRegExp = /.*[S][(0-9)]+[E][(0-9)]+/;
                                                // loop thru the list of filenames
                                                for(filename of dataFile) {
                                                    // if the name is not zero length (split could have returned for just linefeed
                                                    if(filename.length >0 && counter >0) {
                                                       // get the filename prefix
                                                       var split = splitRegExp.exec(filename);
                                                       // save name to the output list, as a table entry
                                                       // remove space after the ->< , the forum hides everything after unless a space
                                                       // table has a row, 
                                                       output_list.push("<tr><td>")
                                                       // with data
                                                       if(split)
                                                          output_list.push(split)
                                                       else 
                                                           output_list.push('name not matched '+ filename)
                                                       // end of data and row
                                                       output_list.push("</td></tr>")
                                                       counter--;
                                                    } 
                                                }  
                                            }
                                                // insert the table into the wrapper
                                    console.log( "<table>" + output_list.join('')+ "</table>");
                        

                        This correct?

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