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> <HTML>
<!-- For file-serving convenience, both style and JS are present within this file -->
<style> <style>
div { div {
background-color: lightslategrey; background-color: lightslategrey;
@ -32,6 +33,7 @@
<div> <div>
<h1>Rover Control Interface</h1> <h1>Rover Control Interface</h1>
<br> <br>
<!-- Calls function which makes AJAX request, page need not reload -->
<button onclick="toggle()">Toggle Motor Status (On/Off)</button> <button onclick="toggle()">Toggle Motor Status (On/Off)</button>
</div> </div>
<p>A project by ENGR 107 Team 2</p> <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 from aiohttp import web
# gpiozero's OutputDevice class is suffificient for our needs
from gpiozero import OutputDevice from gpiozero import OutputDevice
# Creates the OutputDevice relay, controlling GPIO pin 17
relay = OutputDevice(17) relay = OutputDevice(17)
# Sets the pin as off. Not sure if this is required.
relay.off() relay.off()
# Handles requests for the home page
async def handle(req): async def handle(req):
print("Got request") print("Got request")
# Returns the HTML file for viewing
return web.FileResponse("page.html") return web.FileResponse("page.html")
# Handles requests to toggle the pin
async def toggle(req): async def toggle(req):
# Toggles the relay
relay.toggle() relay.toggle()
print(f"Toggled; Current value is {relay.value}") print(f"Toggled; Current value is {relay.value}")
return web.Response() return web.Response()
app = web.Application() 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)]) app.add_routes([web.get('/toggle', toggle), web.get('/', handle)])
# Starts the server, a blocking call
web.run_app(app) web.run_app(app)