MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. yep_DD
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Y
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 57
    • Groups 0

    Posts

    Recent Best Controversial
    • HTTP Server for streaming podcasts / news / volume

      Dear fellow Mirror Designers,

      I wasn’t sure where to put this so I will post it here. From various sources I created a small python httpserver that changes the mirrors volume, starts a podcast (100 Seconds german news, when brushing your teeth:grimacing_face: ) or opens a live stream. This is the code, nothing special but may be helpful for some of you.

      I use FHEM and Philips Hue Dimmer Switches to control it:

      0_1540136723272_IMG_20181021_174249.jpg

      Uses:
      python3, livestreamer, omxplayer

      #!/usr/bin/python3 -u
      
      host_name = '10.0.1.49'  # Change this to your Raspberry Pi IP address
      host_port = 8000
      proc = ''
      
      import RPi.GPIO as GPIO
      from pathlib import Path
      import os
      import subprocess
      import signal
      from subprocess import call
      from time import sleep
      from http.server import BaseHTTPRequestHandler, HTTPServer
      
      
      
      
      class MyServer(BaseHTTPRequestHandler):
      
          def do_HEAD(self):
              self.send_response(200)
              self.send_header('Content-type', 'text/html')
              self.end_headers()
      
          def do_GET(self):
              global proc
              html = '''
                 <html>
                 <body style="width:960px; margin: 20px auto;">
                 <h1>Magic Mirror Control</h1>
                 <p>Current GPU temperature is {}</p>
                 <p>Podcast: <a href="/play">Play</a> <a href="/stop">Stop</a></p>
                 <p>ARD Livestream: <a href="/ard">Play</a> <a href="/stop">Stop</a></p>
                 <p>Volume: <a href="/down">down</a> <a href="/up">up</a></p>
                 <p>System: <a href="/shutdown">Shutdown</a> <a href="/restart">Restart</a></p>
                 <div id="podcast-status"></div>
                 <script>
                     document.getElementById("podcast-status").innerHTML="{}";
                 </script>
                 </body>
                 </html>
              '''
              temp = os.popen("/opt/vc/bin/vcgencmd measure_temp").read()
              self.do_HEAD()
              status = ''
              if self.path=='/':
                  #GPIO.setmode(GPIO.BCM)
                  #GPIO.setwarnings(False)
                  #GPIO.setup(17, GPIO.IN)
                  status='nothing'
              elif self.path=='/play':
                  if proc=='':
                      my_file = Path("/home/pi/MagicMirror/video.mp4")
                      if my_file.is_file():
                          statinfo = os.stat('/home/pi/MagicMirror/video.mp4')
                          if statinfo.st_size > 0:
                              proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/video.mp4"], preexec_fn=os.setsid)
                              status='Playing Podcast'
                          else:
                              proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/Loading.mp4"], preexec_fn=os.setsid)
                              status='Not yet available'
                      else:
                          proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/Loading.mp4"], preexec_fn=os.setsid)
                          status='Not yet available'
                  else:
                      status='Stopping Podcast'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
              elif self.path=='/ard':
                  if proc=='':
                      proc = subprocess.Popen(["livestreamer", "hlsvariant://daserste_live-lh.akamaihd.net/i/daserste_de@91204/master.m3u8", "best", "-vnp", "omxplayer -o alsa:hw:ALSA --no-osd --timeout 20"], preexec_fn=os.setsid)
                      status='Playing ARD Livestream'
                  else:
                      status='Stopping Stream'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
              elif self.path=='/stop':
                  if proc!='':
                      status='Stopping Podcast'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
                  else:
                      status='Nothing to stop'
              elif self.path=='/shutdown':
                  status='Shutdown'
                  subprocess.Popen(["sudo", "shutdown", "-h", "now"], preexec_fn=os.setsid)
              elif self.path=='/restart':
                  status='Restart'
                  subprocess.Popen(["sudo", "reboot"], preexec_fn=os.setsid)
              elif self.path=='/down':
                  status='Volume down'
                  subprocess.Popen(["amixer", "set", "Master", "12%-"], preexec_fn=os.setsid)
              elif self.path=='/up':
                  status='Volume up'
                  subprocess.Popen(["amixer", "set", "Master", "12%+"], preexec_fn=os.setsid)
              self.wfile.write(html.format(temp[5:], status).encode("utf-8"))
      
      
      if __name__ == '__main__':
          http_server = HTTPServer((host_name, host_port), MyServer)
          print("Server Starts - %s:%s" % (host_name, host_port))
      
          try:
              http_server.serve_forever()
          except KeyboardInterrupt:
              http_server.server_close()
      
      
      posted in General Discussion
      Y
      yep_DD
    • RE: Strip Down Guide for BenQ 28" VA Monitor GC2870H

      @Adrien ah, okay I see… yes that might be a problem in my case it works just fine. I will see about the boot time tomorrow.

      posted in Hardware
      Y
      yep_DD
    • RE: Strip Down Guide for BenQ 28" VA Monitor GC2870H

      @Adrien No problem, I am pretty sure it should work but I have not tried it. I might in the future. I am working on a few other bugifxes as well (amplifier only turns on when sound is played and stuff like that). I also suggest to use the microwave / radar sensor instead of the PIR. it is much cleaner and can go behind the mirror.

      Regarding the OSD, instead of cutting wires to the backlight this seems like a valuable option. At the moment I can’t try this (I need a friend to help me take down the mirror as it is too heavy), but I will tomorrow: https://www.youtube.com/watch?v=y86AXOZwlgU (TL;DW: press menu button while turning monitor on and disable logo)

      posted in Hardware
      Y
      yep_DD
    • RE: Strip Down Guide for BenQ 28" VA Monitor GC2870H

      @adrien Hi Adrien, that was my initial plan but I use the two relays now for my speakers to avoid the initial crack sound when powering on the amplifier und I use one relay for the monitor power supply and one for the amplifier.

      posted in Hardware
      Y
      yep_DD
    • RE: Execute script (GPIO Relay) based on if sound is being played
      while sleep 1; do
        if grep -q 'RUNNING' '/proc/asound/card0/pcm0p/sub0/status';
        then
          echo "Running!"
        else
          echo "Not Running!"
        fi
      done
      

      this seems to work but the amplifier produces a too loud cracking sound when switching on, I have two spare relais und my MagicMirror, I will hook up the speakers to those and try again.

      posted in Troubleshooting
      Y
      yep_DD
    • Execute script (GPIO Relay) based on if sound is being played

      Hi guys, I want to monitor if audio is being played, e.g:

      cat /proc/asound/card*/pcm*/sub*/status
      

      And if any status contains running I want to execute a script (in my case turn on the amplifier). I want a simple solution and initially I thought it might be possible with udev or python or bash. Does any of you have a great and easy idea?

      Thanks

      posted in Troubleshooting
      Y
      yep_DD
    • RE: High CPU load of electron and MM freezes

      running your magic mirror in vertical mode? try horizontal and check again.

      posted in Troubleshooting
      Y
      yep_DD
    • RE: Updating problem: "commit your changes or stash them before you can merge" ???
      git stash //stash your changes and save them
      git pull //update to current version
      git stash pop //merge your stash back
      
      posted in Troubleshooting
      Y
      yep_DD
    • RE: Strip Down Guide for BenQ 28" VA Monitor GC2870H

      I am just going to follow up on that, I found a different solution. I am using a HUE Dimmer Switch that is controlled via FHEM and it controls a python script running on MagicMirror to play my podcast and change the volume:

      (I found that script somewhere on github and modified it a bit)

      #!/usr/bin/python3 -u
      
      host_name = '10.0.1.49' 
      host_port = 8000
      
      import RPi.GPIO as GPIO
      import os
      import subprocess
      import signal
      from subprocess import call
      from time import sleep
      from http.server import BaseHTTPRequestHandler, HTTPServer
      
      
      
      
      class MyServer(BaseHTTPRequestHandler):
      
          def do_HEAD(self):
              self.send_response(200)
              self.send_header('Content-type', 'text/html')
              self.end_headers()
      
          def do_GET(self):
              global proc
              html = '''
                 <html>
                 <body style="width:960px; margin: 20px auto;">
                 <h1>Magic Mirror Control</h1>
                 <p>Current GPU temperature is {}</p>
                 <p>Podcast: <a href="/play">Play</a> <a href="/stop">Stop</a></p>
                 <p>Volume: <a href="/down">down</a> <a href="/up">up</a></p>
                 <p>System: <a href="/shutdown">Shutdown</a> <a href="/restart">Restart</a></p>
                 <div id="podcast-status"></div>
                 <script>
                     document.getElementById("podcast-status").innerHTML="{}";
                 </script>
                 </body>
                 </html>
              '''
              temp = os.popen("/opt/vc/bin/vcgencmd measure_temp").read()
              self.do_HEAD()
              status = ''
              if self.path=='/':
                  status='nothing'
              elif self.path=='/play':
                  proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/tmp/video.mp4"], preexec_fn=os.setsid)
                  status='Playing Podcast'
              elif self.path=='/stop':
                  status='Stopping Podcast'
                  os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
              elif self.path=='/shutdown':
                  status='Shutdown'
                  subprocess.Popen(["sudo", "shutdown", "-h", "now"], preexec_fn=os.setsid)
              elif self.path=='/restart':
                  status='Restart'
                  subprocess.Popen(["sudo", "reboot"], preexec_fn=os.setsid)
              elif self.path=='/down':
                  status='Volume down'
                  subprocess.Popen(["amixer", "set", "Master", "12%-"], preexec_fn=os.setsid)
              elif self.path=='/up':
                  status='Volume up'
                  subprocess.Popen(["amixer", "set", "Master", "12%+"], preexec_fn=os.setsid)
              self.wfile.write(html.format(temp[5:], status).encode("utf-8"))
      
      
      if __name__ == '__main__':
          http_server = HTTPServer((host_name, host_port), MyServer)
          print("Server Starts - %s:%s" % (host_name, host_port))
      
          try:
              http_server.serve_forever()
          except KeyboardInterrupt:
              http_server.server_close()
      
      
      posted in Hardware
      Y
      yep_DD
    • RE: Strip Down Guide for BenQ 28" VA Monitor GC2870H

      @madscientist you were right, it does not work well behind the mirror. I will keep the sensor anyway as the way it is designed it is easier to affix to my aluminum frame. I am now thinking of getting small black plexiglas casing to attach to the bottom part to control the mirror and make it look nice… let’s see.

      So this could be the plan:

      • Plexiglas with Cutout letters
        0_1536574392126_aa1bc4b3-c3ee-43b0-94b4-4379c7562c39-image.png

      • behind that translucent plexiglas

      • glue together

      • LED Strip on top of translucent glas to illuminate the cutout letters

      • enjoy?

      posted in Hardware
      Y
      yep_DD
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 3 / 6