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
24 "uid": [1,2,3,4,5,6], # this is the 'flashed' UID and may be empty if using traditional binding on an RX.
27 "no-sync-on-arm": False,
28 "uart-inverted": True,
29 "unlock-higher-power": False,
31 "rcvr-uart-baud": 400000,
32 "rcvr-invert-tx": False,
33 "lock-on-first-connection": True,
35 # "wifi-on-interval": 60,
36 "wifi-password": "w1f1-pAssw0rd",
37 "wifi-ssid": "network-ssid"
40 "uid": [1,2,3,4,5,6], # this is the 'running' UID
42 "ssid":"network-ssid",
47 # 10fs 4ch 1inv 4mode 1narrow
48 "config": 0 + 0<<10 + 0<14 + 0<<15 + 0<<19,
75 "product_name": "Generic ESP8285 + 5xPWM 2.4Ghz RX",
76 "lua_name": "ELRS+PWM 2400RX",
77 "reg_domain": "ISM2G4",
83 "is-long-press": False,
88 "is-long-press": True,
98 "is-long-press": False,
103 "is-long-press": True,
113 def apply_template(mainfile
):
116 loader
=FileLoader(["html"]),
117 extensions
=[CoreExtension("@@")]
119 template
= engine
.get_template(mainfile
)
120 data
= template
.render({
121 'VERSION': 'testing (xxxxxx)',
130 global net_counter
, isTX
, sx127x
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')
139 response
.content_type
= 'text/css; charset=latin9'
140 return apply_template('elrs.css')
144 response
.content_type
= 'text/javascript; charset=latin9'
145 return apply_template('scan.js')
149 response
.content_type
= 'text/javascript; charset=latin9'
150 return apply_template('mui.js')
152 @route('/hardware.html')
154 response
.content_type
= 'text/html; charset=latin9'
155 return apply_template('hardware.html')
157 @route('/hardware.js')
159 response
.content_type
= 'text/javascript; charset=latin9'
160 return apply_template('hardware.js')
164 response
.content_type
= 'application/json; charset=latin9'
167 @route('/config', method
='POST')
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']:
175 config
['config']['pwm'][i
]['config'] = x
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')
194 return "Config Updated"
196 @route('/sethome', method
='POST')
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')
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
210 if __name__
== '__main__':
211 run(host
='localhost', port
=8080)