Fix web server only serving file once and wifi country configuration

pull/746/head
mutatrum 2023-04-08 16:57:01 +02:00
rodzic 7b7352130f
commit 7bdd85d677
2 zmienionych plików z 8 dodań i 28 usunięć

Wyświetl plik

@ -39,9 +39,7 @@ try:
from tinyweb.server import webserver
except ImportError:
# WIFI settings
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
network_manager = NetworkManager(WIFI_COUNTRY, status_handler=status_handler)
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
# Install missing module
import upip
@ -53,16 +51,6 @@ except ImportError:
app = webserver()
# Static page
if is_mini:
html_file = open('index_mini.html', 'r')
else:
html_file = open('index.html', 'r')
# WIFI settings
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
class LEDs:
def not_exists(self):
@ -196,10 +184,10 @@ class relays:
# Index page
@app.route('/')
async def index(request, response):
# Start HTTP response with content-type text/html
await response.start_html()
# Send actual HTML page
await response.send(html_file.read())
if is_mini:
await response.send_file('index_mini.html', content_type='text/html')
else:
await response.send_file('index.html', content_type='text/html')
# HTTP redirection
@ -211,7 +199,7 @@ async def redirect(request, response):
def run():
# Setup wifi
network_manager = NetworkManager(WIFI_COUNTRY, status_handler=status_handler)
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
app.add_resource(outputs, '/outputs')
app.add_resource(relays, '/relays')

Wyświetl plik

@ -63,20 +63,12 @@ def status_handler(mode, status, ip):
# Create web server application
app = webserver()
# Static page
html_file = open('index.html', 'r')
# WIFI settings
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
# Index page
@app.route('/')
async def index(request, response):
# Start HTTP response with content-type text/html
await response.start_html()
# Send actual HTML page
await response.send(html_file.read())
await response.send_file('index.html', content_type='text/html')
# HTTP redirection
@ -120,7 +112,7 @@ def outline_text(text, x, y):
def run():
# Setup wifi
network_manager = NetworkManager(WIFI_COUNTRY, status_handler=status_handler)
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
app.add_resource(text, '/update')