📜 ⬆️ ⬇️

Remote presentation control from a smartphone

I recently did a report (on Percona Live ). And one night (jet-lag after all) I thought that it would be nice to somehow see my comments on the slides — hints — and switch slides without going to the laptop. Wonder-device, so that the slides switch and the comments showed, I did not have. But there was a smartphone with Android. Google Market disappointed. Most of these applications only worked with PowerPoint, for LibreOffice I found only one thing, paid, and it looked somehow wrong.

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

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

Comments are read from the file (I didn’t bother with pulling them out of the presentation). Raise BaseHTTPServer on some port, I try everything from 8000 to 9000 in random order until it works. According to the instructions from 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 from the audience will switch slides to us. As a minor convenience, I open the browser to show the QR code for access to the server. If you don’t have access to the Internet during the conference, it’s not a problem, you’ll have to enter the URL with your hands, that's all. And for work enough internal wifi.
')
According to the instructions for BaseHTTPServer , to handle GET requests, you need to create a do_GET method. We create. First of all, you need to check that there is our random number. If there is, and the URL ends with next or prev, then we simulate pressing a space or, respectively, backspace, and return a page with comments for the next or previous page.

I have fvwm , so with the imitation of clicking the problems have arisen. 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 should be made larger. And the comments should be shorter, otherwise they should be read for a long time - unpleasant pauses are obtained during the report. Yes, and the timeout for turning off the screen is removed on the smartphone and in the laptop.

The test in combat conditions was successful.

#!/usr/bin/python import 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)$") def send_key(key): os.system("FvwmCommand 'All (VCLSalFrame) FakeKeypress press {}'".format(key)) class Handler(BaseHTTPServer.BaseHTTPRequestHandler): def link(self,s,n): if n < 0 or n >= len(data): return " " return '<a href="{}{}">{}</a>'.format(token,s,s) def do_GET(self): cmd = validate.match(self.path) if cmd is None: self.send_response(404) self.send_header("Content-type", 'text/html') self.end_headers() self.wfile.write('<h1>OK</h1>') return global 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])) def read_file(s): with open(s) as f: return re.split('--- *\n?', f.read()) def ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('192.168.1.1', 0)) # fake, but nobody cares return s.getsockname()[0] def make_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)) def run(): 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 not in (98,): print e exit() except KeyboardInterrupt: print "\nExiting" exit() data = read_file('notes.txt') print "Got {} slides".format(len(data)) run() 

Source: https://habr.com/ru/post/132331/


All Articles