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.

    Help with MMM-PIR-Sensor tvservice logical evaluation

    Scheduled Pinned Locked Moved Troubleshooting
    3 Posts 2 Posters 1.8k Views 2 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.
    • O Offline
      orayoflighto Project Sponsor
      last edited by

      Can someone help shed some light on this piece of code in the MMM-PIR-Sensor module? In the node_helper.js there is:

            // Check if hdmi output is already on
            exec("/opt/vc/bin/tvservice -s").stdout.on('data', function(data) {
              if (data.indexOf("0x120002") !== -1)
                exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
      

      I understand what it is doing. It is checking if the monitor is in standby [TV is off] and if so then it turns it on. This bit of code also executes when the monitor is on though which is the part that I am having trouble with. I understand that 0x120002 is what tvservice reports when the monitor is off. I don’t understand the!== -1

      Any help? I would like to change the logic so it doesn’t execute that line when the monitor is on (0x12000a)

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

        @orayoflighto if there is no occurence of the string 0x120002, the method indexOf returns -1. So he checks if the string 0x120002 is part of the variable data.

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

        1 Reply Last reply Reply Quote 0
        • O Offline
          orayoflighto Project Sponsor
          last edited by

          I figured it out. There are missing brackets for the if statement. In node_helper.js:

          From:

                  if (data.indexOf("0x120002") !== -1)
                    exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
          

          To:

                  if (data.indexOf("0x120002") !== -1){
                    exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
                 }
          

          @paviro

          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 / 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