Gemini Xrossband (GemX) - LR1121 Driver (#2540)
[ExpressLRS.git] / src / python / serve_html.py
blobb2d63b2cad9a9241c0831f4291885a5f818a35eb
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 A simple http server for testing/debugging the web-UI
7 open http://localhost:8080/
8 add the following query params for TX and/or 900Mhz testing
9 isTX
10 sx127x
11 """
13 from external.bottle import route, run, response, request
14 from external.wheezy.template.engine import Engine
15 from external.wheezy.template.ext.core import CoreExtension
16 from external.wheezy.template.loader import FileLoader
18 net_counter = 0
19 isTX = False
20 sx127x = False
22 config = {
23 "options": {
24 "uid": [1,2,3,4,5,6], # this is the 'flashed' UID and may be empty if using traditional binding on an RX.
25 "tlm-interval": 240,
26 "fan-runtime": 30,
27 "no-sync-on-arm": False,
28 "uart-inverted": True,
29 "unlock-higher-power": False,
30 "is-airport": True,
31 "rcvr-uart-baud": 400000,
32 "rcvr-invert-tx": False,
33 "lock-on-first-connection": True,
34 "domain": 1,
35 # "wifi-on-interval": 60,
36 "wifi-password": "w1f1-pAssw0rd",
37 "wifi-ssid": "network-ssid"
39 "config": {
40 "uid": [1,2,3,4,5,6], # this is the 'running' UID
41 "uidtype": "On loan",
42 "ssid":"network-ssid",
43 "mode":"STA",
44 "modelid":255,
45 "pwm":[
47 # 10fs 4ch 1inv 4mode 1narrow
48 "config": 0 + 0<<10 + 0<14 + 0<<15 + 0<<19,
49 "pin": 0,
50 "features": 12
53 "config": 1536,
54 "pin": 4,
55 "features": 12 + 16
58 "config": 2048,
59 "pin": 5,
60 "features": 12 + 16
63 "config": 3584,
64 "pin": 1,
65 "features": 1 + 16
68 "config": 4608,
69 "pin": 3,
70 "features": 2 + 16
73 "serial-protocol": 3,
74 "sbus-failsafe": 0,
75 "product_name": "Generic ESP8285 + 5xPWM 2.4Ghz RX",
76 "lua_name": "ELRS+PWM 2400RX",
77 "reg_domain": "ISM2G4",
78 "button-actions": [
80 "color" : 255,
81 "action": [
83 "is-long-press": False,
84 "count": 3,
85 "action": 6
88 "is-long-press": True,
89 "count": 5,
90 "action": 1
95 "color" : 224,
96 "action": [
98 "is-long-press": False,
99 "count": 2,
100 "action": 3
103 "is-long-press": True,
104 "count": 0,
105 "action": 4
113 def apply_template(mainfile):
114 global isTX, sx127x
115 engine = Engine(
116 loader=FileLoader(["html"]),
117 extensions=[CoreExtension("@@")]
119 template = engine.get_template(mainfile)
120 data = template.render({
121 'VERSION': 'testing (xxxxxx)',
122 'PLATFORM': '',
123 'isTX': isTX,
124 'sx127x': sx127x
126 return data
128 @route('/')
129 def index():
130 global net_counter, isTX, sx127x
131 net_counter = 0
132 isTX = 'isTX' in request.query
133 sx127x = 'sx127x' in request.query
134 response.content_type = 'text/html; charset=latin9'
135 return apply_template('index.html')
137 @route('/elrs.css')
138 def elrs():
139 response.content_type = 'text/css; charset=latin9'
140 return apply_template('elrs.css')
142 @route('/scan.js')
143 def scan():
144 response.content_type = 'text/javascript; charset=latin9'
145 return apply_template('scan.js')
147 @route('/mui.js')
148 def mui():
149 response.content_type = 'text/javascript; charset=latin9'
150 return apply_template('mui.js')
152 @route('/hardware.html')
153 def hradware_html():
154 response.content_type = 'text/html; charset=latin9'
155 return apply_template('hardware.html')
157 @route('/hardware.js')
158 def hardware_js():
159 response.content_type = 'text/javascript; charset=latin9'
160 return apply_template('hardware.js')
162 @route('/config')
163 def options():
164 response.content_type = 'application/json; charset=latin9'
165 return config
167 @route('/config', method='POST')
168 def update_config():
169 if 'button-actions' in request.json:
170 config['config']['button-actions'] = request.json['button-actions']
171 if 'pwm' in request.json:
173 for x in request.json['pwm']:
174 print(x)
175 config['config']['pwm'][i]['config'] = x
176 i = i + 1
177 if 'protocol' in request.json:
178 config['config']['serial-protocol'] = request.json['protocol']
179 if 'modelid' in request.json:
180 config['config']['modelid'] = request.json['modelid']
181 if 'forcetlm' in request.json:
182 config['config']['force-tlm'] = request.json['forcetlm']
183 return "Config Updated"
185 @route('/options.json', method='POST')
186 def update_options():
187 config['options'] = request.json
188 return "Options Updated"
190 @route('/import', method='POST')
191 def import_config():
192 json = request.json
193 print(json)
194 return "Config Updated"
196 @route('/sethome', method='POST')
197 def options():
198 response.content_type = 'application/json; charset=latin9'
199 return "Connecting to network '" + request.forms.get('network') + "', connect to http://elrs_tx.local from a browser on that network"
201 @route('/networks.json')
202 def mode():
203 global net_counter
204 net_counter = net_counter + 1
205 if (net_counter > 3):
206 return '["Test Network 1", "Test Network 2", "Test Network 3", "Test Network 4", "Test Network 5"]'
207 response.status = 204
208 return '[]'
210 if __name__ == '__main__':
211 run(host='localhost', port=8080)