Remote control presentation from a smartphone

    I recently made a report (on Percona Live ). And one night (jet-lag after all) I thought it would be nice to somehow see my comments on the slides - tips and switch slides without going to the laptop. I didn’t have miracle devices to switch slides and show comments. But there was a smartphone with Android. Google Market has disappointed. Most of these applications worked only with PowerPoint, for LibreOffice I found only one, paid, and it looked somehow wrong.

    But there is a simple solution - a browser. You can raise the http-server on a laptop, log in from the phone, and switch slides through the links. And it will work not only with Android, but also with apple, and with Windows phones. Yes, in general, a smartphone is not needed, you can even go through WAP, or from another laptop.

    It turned out pretty simple. About 70 lines in python, no external dependencies (almost).

    Comments are read from the file (I didn’t bother with pulling them out of the presentation). We raise BaseHTTPServer on some port, I try everything from 8000 to 9000 in random order until it works. According to the instructions with StackOverflow, we determine our IP. And in addition, we generate a large random number - it will be part of the URL so that no one in the audience switches the slides to us. As a minor convenience, I open the browser to show a QR code for accessing the server. If you don’t have Internet access during the conference, it doesn’t matter, you’ll have to enter the URL manually, and that’s it. And for work, enough internal wifi.

    According to the instructions for BaseHTTPServerTo handle GET requests you need to create a do_GET method. We create. The first thing you need to check is our random number. If there is, and the URL ends with next or prev, then we simulate a space or, respectively, backspace, and return the page with comments for the next or previous page.

    I have fvwm , so there were no problems with simulating clicks. For other window managers, you can use a separate program or even a special module for python, there are some - I checked.

    Well, actually, that's all. Only the font in the settings of the mobile browser needs to be made larger. And to write comments shorter, otherwise to read them for a long time - unpleasant pauses during the report turn out. Yes, and remove the timeout for turning off the screen on the smartphone and laptop.

    The test in combat conditions was successful.

    #!/usr/bin/pythonimport sys
    import os
    import random
    import socket
    import BaseHTTPServer
    import re
    handler_class=BaseHTTPServer.BaseHTTPRequestHandler
    token="/" + str(random.randint(0, sys.maxint)) + "/"
    page = 1
    validate = re.compile(token + "(prev|next)$")
    defsend_key(key):
      os.system("FvwmCommand 'All (VCLSalFrame) FakeKeypress press {}'".format(key))
    classHandler(BaseHTTPServer.BaseHTTPRequestHandler):deflink(self,s,n):if n < 0or n >= len(data):
          return" "return'<a href="{}{}">{}</a>'.format(token,s,s)
      defdo_GET(self):
        cmd = validate.match(self.path)
        if cmd isNone:
          self.send_response(404)
          self.send_header("Content-type", 'text/html')
          self.end_headers()
          self.wfile.write('<h1>OK</h1>')
          returnglobal page
        if cmd.group(1) == 'prev'and page > 0:
          page = page - 1
          send_key('BackSpace')
        elif cmd.group(1) == 'next'and page < len(data)-1:
          page = page + 1
          send_key('space')
        self.send_response(200)
        self.send_header("Content-type", 'text/html; charset=utf-8')
        self.end_headers()
        self.wfile.write("""
    {pagenum} - {next}
    <hr> {data} <hr>
    {prev} - {pagenum}
    """.format(prev = self.link('prev', page - 1), pagenum = page + 1,
               next = self.link('next', page + 1), data = data[page]))
    defread_file(s):with open(s) as f:
        return re.split('--- *\n?', f.read())
    defip():
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.connect(('192.168.1.1', 0)) # fake, but nobody caresreturn s.getsockname()[0]
    defmake_url(port):
      url="http://{}:{}{}prev".format(ip(), port, token)
      print url
      os.system("firefox 'http://chart.apis.google.com/chart?cht=qr&chs=200x200&chl={}' &".format(url))
    defrun():for port in random.sample(xrange(8000, 9000),1000):
        try:
          httpd = BaseHTTPServer.HTTPServer(('',port), Handler)
          httpd.server_activate()
          make_url(port)
          httpd.serve_forever()
        except socket.error, e:
          if e.errno notin (98,):
            print e
            exit()
        except KeyboardInterrupt:
          print"\nExiting"
          exit()
    data = read_file('notes.txt')
    print"Got {} slides".format(len(data))
    run()
    

    Also popular now: