Management, update arduino, add initial webapp

This commit is contained in:
2017-09-09 23:44:49 +02:00
parent b6f4601972
commit fd6f26f202
7 changed files with 76 additions and 14 deletions

3
raspi/mgmt/autostart Normal file
View File

@@ -0,0 +1,3 @@
@xset s noblank
@xset s off
@xset -dpms

7
raspi/mgmt/playbook.yml Normal file
View File

@@ -0,0 +1,7 @@
- hosts: raspi
become: True
become_user: root
tasks:
- copy: src=autostart dest=/home/pi/.config/lxsession/LXDE-pi/autostart
- copy: src=sejf.desktop dest=/etc/xdg/autostart
- apt: name=python-flask state=present

7
raspi/mgmt/sejf.desktop Executable file
View File

@@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=sejf
NoDisplay=true
Exec=python /home/pi/sejf/raspi/pySejf.py
Terminal=true
NotShowIn=GNOME;KDE;XFCE;

View File

@@ -2,8 +2,10 @@
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
import subprocess
subprocess.call('(date; pwd) >> /tmp/log', shell=True)
import serial
import webapp
webapp.init(serial.Serial('/dev/ttyUSB0', 115200))
import random, math, pygame
from pygame.locals import *
@@ -176,6 +178,7 @@ def waitForEvents():
global slide
print("waiting for events")
while 1:
time.sleep(0.01)
if GPIO.input(PIN_SET1) == 0 and slide != SLIDE_KEY:
print "Ardu said go to key slide"
slide = SLIDE_KEY

View File

@@ -0,0 +1,19 @@
<html>
<body>
<table>
<tr>
<th>Włącz</th>
{% for n in range(10) %}
<td><a href="/set/{{ n }}">{{ n + 1 }}</a></td>
{% endfor %}
</tr>
<tr>
<th>Wyłącz</th>
{% for n in range(10) %}
<td><a href="/clear/{{ n }}">{{ n + 1 }}</a></td>
{% endfor %}
</tr>
</table>
</body>
</html>

28
raspi/webapp.py Normal file
View File

@@ -0,0 +1,28 @@
import flask
import string
import threading
app = flask.Flask(__name__)
@app.route('/set/<int:task>')
def set_task(task):
app.port.write(string.uppercase[task])
return flask.redirect('/')
@app.route('/clear/<int:task>')
def clear_task(task):
app.port.write(string.lowercase[task])
return flask.redirect('/')
@app.route('/')
def index():
return flask.render_template('index.html')
def init(ser):
app.port = ser
app.th = threading.Thread(target=app.run, kwargs={
'host': '0.0.0.0'
})
app.th.daemon = True
app.th.start()