2 # -*- coding: utf-8 -*-
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
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
26 "uid": [1,2,3,4,5,6], # this is the 'flashed' UID and may be empty if using traditional binding on an RX.
29 "no-sync-on-arm": False,
30 "uart-inverted": True,
31 "unlock-higher-power": False,
33 "rcvr-uart-baud": 400000,
34 "rcvr-invert-tx": False,
35 "lock-on-first-connection": True,
37 # "wifi-on-interval": 60,
38 "wifi-password": "w1f1-pAssw0rd",
39 "wifi-ssid": "network-ssid"
42 "uid": [1,2,3,4,5,6], # this is the 'running' UID
44 "ssid":"network-ssid",
49 # 10fs 4ch 1inv 4mode 1narrow
50 "config": 0 + 0<<10 + 0<14 + 0<<15 + 0<<19,
77 "product_name": "Generic ESP8285 + 5xPWM 2.4Ghz RX",
78 "lua_name": "ELRS+PWM 2400RX",
79 "reg_domain": "ISM2G4",
85 "is-long-press": False,
90 "is-long-press": True,
97 #"color" : 224, # No color for you button 2
100 "is-long-press": False,
105 "is-long-press": True,
115 def apply_template(mainfile
):
116 global isTX
, hasSubGHz
, chip
, is8285
118 platform
= 'Unified_ESP32_2400_TX'
121 platform
= 'Unified_ESP8285_2400_RX'
124 loader
=FileLoader(["html"]),
125 extensions
=[CoreExtension("@@")]
127 template
= engine
.get_template(mainfile
)
128 data
= template
.render({
129 'VERSION': 'testing (xxxxxx)',
130 'PLATFORM': platform
,
132 'hasSubGHz': hasSubGHz
,
140 global net_counter
, isTX
, hasSubGHz
, chip
, is8285
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')
151 response
.content_type
= 'text/css; charset=latin9'
152 return apply_template('elrs.css')
156 response
.content_type
= 'text/javascript; charset=latin9'
157 return apply_template('scan.js')
161 response
.content_type
= 'text/javascript; charset=latin9'
162 return apply_template('mui.js')
164 @route('/hardware.html')
166 response
.content_type
= 'text/html; charset=latin9'
167 return apply_template('hardware.html')
169 @route('/hardware.js')
171 response
.content_type
= 'text/javascript; charset=latin9'
172 return apply_template('hardware.js')
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')
184 response
.content_type
= 'text/javascript; charset=latin9'
185 return apply_template('cw.js')
189 response
.content_type
= 'application/json; charset=latin9'
190 return '{"radios": 2, "center": 915000000, "center2": 2440000000}'
192 @route('/lr1121.html')
194 response
.content_type
= 'text/html; charset=latin9'
195 return apply_template('lr1121.html')
199 response
.content_type
= 'text/javascript; charset=latin9'
200 return apply_template('lr1121.js')
202 @route('/lr1121.json')
217 @route('/lr1121', method
="POST")
219 return '{ "status": "ok", "msg": "All good!" }'
223 response
.content_type
= 'application/json; charset=latin9'
226 @route('/config', method
='POST')
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']:
234 config
['config']['pwm'][i
]['config'] = x
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')
253 return "Config Updated"
255 @route('/sethome', method
='POST')
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')
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
269 if __name__
== '__main__':
270 run(host
='localhost', port
=8080)