This document provides a brief documentation for the HTML code snippet given above. This code snippet includes a table of four relays with their ON and OFF buttons.
This is a Flask app that controls relays using the relay_module.
- Install Python 3 if not already installed
- Install Flask using
pip install flask
- Import the necessary functions from
relay_module
- Create a Flask app instance with
Flask(name)
- Define routes using
@app.route()
- Define functions to be executed when a route is accessed
- Run the app using
app.run()
home()
: Returns theindex.html
template when the/
route is accessed.on(num)
: Turns on the relay specified bynum
using theswitchOn()
function fromrelay_module
.off(num)
: Turns off the relay specified bynum
using theswitchOff()
function fromrelay_module
.
from flask import Flask, request, render_template from relay_module import *
app = Flask(name)
@app.route('/') def home(): return render_template('index.html')
@app.route('/on/') def on(num): switchOn(int(num)) return home()
@app.route('/off/') def off(num): switchOff(int(num)) return home()
if name == 'main': app.run(host='0.0.0.0')
This example creates a Flask app instance, defines routes for turning on and off relays, and runs the app on localhost port 5000.