Commit b9f892fa authored by Kristian Tan's avatar Kristian Tan

Adding RPi.GPIO package and setting some pins

parent 03902bd3
......@@ -4,10 +4,10 @@
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../IoTSmartMeter">
<excludeFolder url="file://$MODULE_DIR$/../IoTSmartMeter/venv" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.6 (IoTSmartMeter)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
......
......@@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (untitled)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (IoTSmartMeter)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
from flask import Flask, render_template
import datetime
import RPi.GPIO as GPIO
app = Flask(__name__)
# Create a dictionary called pins to store the pin number, name, and pin state:
pins = {
24: {'name': 'coffee maker', 'state': GPIO.LOW},
25: {'name': 'lamp', 'state': GPIO.LOW}
}
# Set each pin as an output and make it low:
for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
@app.route("/")
def hello():
now = datetime.datetime.now()
time_string = now.strftime("%Y-%m-%d %H:%M")
def main():
# For each pin, read the pin state and store it in the pins dictionary:
for pin in pins:
pins[pin]['state'] = GPIO.input(pin)
# Put the pin dictionary into the template data dictionary:
template_data = {
'title' : 'HELLO!',
'time': time_string
'pins': pins
}
# Pass the template data into the template main.html and return it to the user
return render_template('main.html', **template_data)
@app.route('/button')
def button():
print("Button press")
now = datetime.datetime.now()
time_string = now.strftime("%Y-%m-%d %H:%M")
template_data = {
'title': 'HELLO!',
'time': time_string
}
return render_template('main.html', **template_data)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8090)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment