From 7ebb7e63c93bf08b5f929544513f4136e60f6f5c Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sun, 20 Apr 2025 22:52:35 +0200 Subject: [PATCH] webserver list files works! --- appstore.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/appstore.py b/appstore.py index 8ee36ab9..21d18a82 100644 --- a/appstore.py +++ b/appstore.py @@ -6,7 +6,6 @@ import machine import task_handler import cst816s import i2c -import network import urequests # Pin configuration @@ -602,3 +601,53 @@ print("Launcher script exiting") run_app(launcher_script,False,False) + + +import network +import time + +# Connect to Wi-Fi +def connect_wifi(): + wlan = network.WLAN(network.STA_IF) + wlan.active(True) + wlan.connect("SSIDHERE", "PASSWORDHERE") + print("Connecting to Wi-Fi...", end="") + for _ in range(30): # Wait up to 30 seconds + if wlan.isconnected(): + print(" Connected!") + print("IP:", wlan.ifconfig()[0]) + return True + time.sleep(1) + print(".", end="") + print(" Failed to connect!") + return False + + +connect_wifi() + + +#import mip +#mip.install('github:miguelgrinberg/microdot/src/microdot/microdot.py') +from microdot_asyncio import Microdot, Response + +app = Microdot() + +@app.route('/') +async def index(request): + return 'Hello, world!' + +import os +@app.route('/files') +async def list_files(req): + files = os.listdir('/') + html = '

Files

' + return Response(html, headers={'Content-Type': 'text/html'}) + + +def startit(): + app.run(port=80) + # http://192.168.1.115:5000 + + +import _thread +_thread.start_new_thread(startit, ())