Added comments

master
archfan7411 2021-04-18 16:22:58 +00:00
parent caa6c61d22
commit e3489172f4
2 changed files with 15 additions and 0 deletions

View File

@ -1,4 +1,5 @@
<HTML>
<!-- For file-serving convenience, both style and JS are present within this file -->
<style>
div {
background-color: lightslategrey;
@ -32,6 +33,7 @@
<div>
<h1>Rover Control Interface</h1>
<br>
<!-- Calls function which makes AJAX request, page need not reload -->
<button onclick="toggle()">Toggle Motor Status (On/Off)</button>
</div>
<p>A project by ENGR 107 Team 2</p>

View File

@ -1,19 +1,32 @@
# aiohttp will be used to create the webserver
from aiohttp import web
# gpiozero's OutputDevice class is suffificient for our needs
from gpiozero import OutputDevice
# Creates the OutputDevice relay, controlling GPIO pin 17
relay = OutputDevice(17)
# Sets the pin as off. Not sure if this is required.
relay.off()
# Handles requests for the home page
async def handle(req):
print("Got request")
# Returns the HTML file for viewing
return web.FileResponse("page.html")
# Handles requests to toggle the pin
async def toggle(req):
# Toggles the relay
relay.toggle()
print(f"Toggled; Current value is {relay.value}")
return web.Response()
app = web.Application()
# Requests to <address>/toggle should toggle, but normal
# requests to just the address should return the home page
app.add_routes([web.get('/toggle', toggle), web.get('/', handle)])
# Starts the server, a blocking call
web.run_app(app)