Parse MSP messages from the backpack while TX is in mavlink mode (#2883)
[ExpressLRS.git] / src / python / serve_html.py
bloba8fba4f26a04da4f3fb7e15c02d2fbb54fb10f68
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 hasSubGHz
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 hasSubGHz = False
21 is8285 = True
22 chip = 'LR1121'
24 config = {
25 "options": {
26 "uid": [1,2,3,4,5,6], # this is the 'flashed' UID and may be empty if using traditional binding on an RX.
27 "tlm-interval": 240,
28 "fan-runtime": 30,
29 "no-sync-on-arm": False,
30 "uart-inverted": True,
31 "unlock-higher-power": False,
32 "is-airport": True,
33 "rcvr-uart-baud": 400000,
34 "rcvr-invert-tx": False,
35 "lock-on-first-connection": True,
36 "domain": 1,
37 # "wifi-on-interval": 60,
38 "wifi-password": "w1f1-pAssw0rd",
39 "wifi-ssid": "network-ssid"
41 "config": {
42 "uid": [1,2,3,4,5,6], # this is the 'running' UID
43 "uidtype": "On loan",
44 "ssid":"network-ssid",
45 "mode":"STA",
46 "modelid":255,
47 "pwm":[
49 # 10fs 4ch 1inv 4mode 1narrow
50 "config": 0 + 0<<10 + 0<14 + 0<<15 + 0<<19,
51 "pin": 0,
52 "features": 12
55 "config": 1536,
56 "pin": 4,
57 "features": 12 + 16
60 "config": 2048,
61 "pin": 5,
62 "features": 12 + 16
65 "config": 3584,
66 "pin": 1,
67 "features": 1 + 16
70 "config": 4608,
71 "pin": 3,
72 "features": 2 + 16
75 "serial-protocol": 3,
76 "sbus-failsafe": 0,
77 "product_name": "Generic ESP8285 + 5xPWM 2.4Ghz RX",
78 "lua_name": "ELRS+PWM 2400RX",
79 "reg_domain": "ISM2G4",
80 "button-actions": [
82 "color" : 255,
83 "action": [
85 "is-long-press": False,
86 "count": 3,
87 "action": 6
90 "is-long-press": True,
91 "count": 5,
92 "action": 1
97 #"color" : 224, # No color for you button 2
98 "action": [
100 "is-long-press": False,
101 "count": 2,
102 "action": 3
105 "is-long-press": True,
106 "count": 0,
107 "action": 4
115 def apply_template(mainfile):
116 global isTX, hasSubGHz, chip, is8285
117 if(isTX):
118 platform = 'Unified_ESP32_2400_TX'
119 is8285 = False
120 else:
121 platform = 'Unified_ESP8285_2400_RX'
122 is8285 = True
123 engine = Engine(
124 loader=FileLoader(["html"]),
125 extensions=[CoreExtension("@@")]
127 template = engine.get_template(mainfile)
128 data = template.render({
129 'VERSION': 'testing (xxxxxx)',
130 'PLATFORM': platform,
131 'isTX': isTX,
132 'hasSubGHz': hasSubGHz,
133 'chip': chip,
134 'is8285': is8285
136 return data
138 @route('/')
139 def index():
140 global net_counter, isTX, hasSubGHz, chip, is8285
141 net_counter = 0
142 isTX = 'isTX' in request.query
143 hasSubGHz = 'hasSubGHz' in request.query
144 if 'chip' in request.query:
145 chip = request.query['chip']
146 response.content_type = 'text/html; charset=latin9'
147 return apply_template('index.html')
149 @route('/elrs.css')
150 def elrs():
151 response.content_type = 'text/css; charset=latin9'
152 return apply_template('elrs.css')
154 @route('/scan.js')
155 def scan():
156 response.content_type = 'text/javascript; charset=latin9'
157 return apply_template('scan.js')
159 @route('/mui.js')
160 def mui():
161 response.content_type = 'text/javascript; charset=latin9'
162 return apply_template('mui.js')
164 @route('/hardware.html')
165 def hardware_html():
166 response.content_type = 'text/html; charset=latin9'
167 return apply_template('hardware.html')
169 @route('/hardware.js')
170 def hardware_js():
171 response.content_type = 'text/javascript; charset=latin9'
172 return apply_template('hardware.js')
174 @route('/cw.html')
175 def cw_html():
176 global chip
177 if 'chip' in request.query:
178 chip = request.query['chip']
179 response.content_type = 'text/html; charset=latin9'
180 return apply_template('cw.html')
182 @route('/cw.js')
183 def cw_js():
184 response.content_type = 'text/javascript; charset=latin9'
185 return apply_template('cw.js')
187 @route('/cw')
188 def cw():
189 response.content_type = 'application/json; charset=latin9'
190 return '{"radios": 2, "center": 915000000, "center2": 2440000000}'
192 @route('/lr1121.html')
193 def lr1121_html():
194 response.content_type = 'text/html; charset=latin9'
195 return apply_template('lr1121.html')
197 @route('/lr1121.js')
198 def lr1121_js():
199 response.content_type = 'text/javascript; charset=latin9'
200 return apply_template('lr1121.js')
202 @route('/lr1121.json')
203 def lr1121_json():
204 return {
205 "radio1": {
206 "hardware": 34,
207 "type": 3,
208 "firmware": 259
210 "radio2": {
211 "hardware": 34,
212 "type": 3,
213 "firmware": 257
217 @route('/lr1121', method="POST")
218 def lr1121_upload():
219 return '{ "status": "ok", "msg": "All good!" }'
221 @route('/config')
222 def options():
223 response.content_type = 'application/json; charset=latin9'
224 return config
226 @route('/config', method='POST')
227 def update_config():
228 if 'button-actions' in request.json:
229 config['config']['button-actions'] = request.json['button-actions']
230 if 'pwm' in request.json:
232 for x in request.json['pwm']:
233 print(x)
234 config['config']['pwm'][i]['config'] = x
235 i = i + 1
236 if 'protocol' in request.json:
237 config['config']['serial-protocol'] = request.json['protocol']
238 if 'modelid' in request.json:
239 config['config']['modelid'] = request.json['modelid']
240 if 'forcetlm' in request.json:
241 config['config']['force-tlm'] = request.json['forcetlm']
242 return "Config Updated"
244 @route('/options.json', method='POST')
245 def update_options():
246 config['options'] = request.json
247 return "Options Updated"
249 @route('/import', method='POST')
250 def import_config():
251 json = request.json
252 print(json)
253 return "Config Updated"
255 @route('/sethome', method='POST')
256 def options():
257 response.content_type = 'application/json; charset=latin9'
258 return "Connecting to network '" + request.forms.get('network') + "', connect to http://elrs_tx.local from a browser on that network"
260 @route('/networks.json')
261 def mode():
262 global net_counter
263 net_counter = net_counter + 1
264 if (net_counter > 3):
265 return '["Test Network 1", "Test Network 2", "Test Network 3", "Test Network 4", "Test Network 5"]'
266 response.status = 204
267 return '[]'
269 if __name__ == '__main__':
270 run(host='localhost', port=8080)