Skip to content

Instantly share code, notes, and snippets.

@RajivCodeLab
Created March 31, 2024 09:32
Show Gist options
  • Save RajivCodeLab/5d0f165b551af729e81d453ae8a4002e to your computer and use it in GitHub Desktop.
Save RajivCodeLab/5d0f165b551af729e81d453ae8a4002e to your computer and use it in GitHub Desktop.
Build Your Own Web Server on Raspberry Pi Pico W and Phew
<!doctype html>
<html lang="en">
<head>
<title>Raspberry Pi Pico Web Server</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- Bootstrap CSS v5.2.1 -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous"
/>
</head>
<body>
<header>
<nav
class="navbar navbar-expand-sm navbar-dark bg-success"
>
<a class="navbar-brand" href="#">&nbsp; Pi Pico Web Server</a>
</nav>
</header>
<main class="container">
<div class="d-grid gap-3 p-5">
<a
href="/on"
class="btn btn-danger"
>
LED ON
</a>
<a
href="/off"
class="btn btn-success"
>
LED OFF
</a>
</div>
</main>
<footer>
<!-- place footer here -->
</footer>
<!-- Bootstrap JavaScript Libraries -->
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"
integrity="sha384-BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+"
crossorigin="anonymous"
></script>
</body>
</html>
from phew import server, connect_to_wifi
import machine
ip = connect_to_wifi("Airtel_RAJEEV","00351553")
print(ip)
page = open("index.html","r")
html= page.read()
page.close()
led = machine.Pin("LED", machine.Pin.OUT)
@server.route("/", methods=["GET"])
def home(request):
return str(html)
@server.route("/<command>", methods=["GET"])
def command(request, command):
if command == "on":
led.on()
elif command == "off":
led.off()
return str(html)
@server.catchall()
def catchall(request):
return "Page not found", 404
server.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment