-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
36 lines (32 loc) · 987 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from flask import abort, Flask, render_template, request, Response
from flask_cors import CORS
sys.path.insert(0, 'pyenttec/')
import pyenttec
app = Flask(__name__)
if __name__ == '__main__':
app.run(host="0.0.0.0")
CORS(app)
dmx = pyenttec.DMXConnection('/dev/serial/by-id/usb-DMXking.com_DMX_USB_PRO_6AUTNPNW-if00-port0')
# {
# "channels_list": [
# {"channel": 50, "value": 255},
# {"channel": 51, "value": 0},
# {"channel": 52, "value": 0}
# ]
# }
@app.route('/api', methods=['POST'])
def jsonHandler():
try:
contents = request.get_json()['channels_list']
print(contents)
for content in contents:
# print(content['channel'],': ',content['value'])
dmx.dmx_frame[content['channel']-1] = content['value']
dmx.render()
return Response(status=204, mimetype='application/json')
except TypeError:
print('TypeError')
abort(400)
except:
print('other error')