e210 engineering cyber -physical systems (spring 2021) flask
TRANSCRIPT
Flask
Bryce Hime baugh
E210 Engineering Cyber-Physical Systems (Spring 2021)
INDIANA UNIVERSITY BLOOMINGTONINDIANA UNIVERSITY BLOOMINGTON
Raspberry PI/Basys3 Link
Flask Overview
INDIANA UNIVERSITY BLOOMINGTON
Flask1. Python Micro Web Framework
– Minimalist compared to Django Framework
2. First Release in 2010
3. Hammer vs toolbox
4. Used in projects as the API …
INDIANA UNIVERSITY BLOOMINGTON
System Architecture
Silo Pi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA Board
Pivot.iuiot.orgMQTT Broker
MQTT Messages
Your Flask Web Server
MQTT Messages
Browser Access to PI Systems
Minimal Example
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
Python Function Decorators
INDIANA UNIVERSITY BLOOMINGTON
Functions
https://realpython.com/primer-on-python-decorators/#functions
INDIANA UNIVERSITY BLOOMINGTON
Functions can be Passed as Arguments
https://realpython.com/primer-on-python-decorators/#functions
INDIANA UNIVERSITY BLOOMINGTON
Functions within Functions (Inner Functions)
https://realpython.com/primer-on-python-decorators/#functions
first_child andsecond_child only exist inside of parent
INDIANA UNIVERSITY BLOOMINGTON
Returning Functions
https://realpython.com/primer-on-python-decorators/#functions
Function Reference Returned
Can call these functions like any other function
INDIANA UNIVERSITY BLOOMINGTON
Decorators
https://realpython.com/primer-on-python-decorators/#functions
Decorators wrap the original function
INDIANA UNIVERSITY BLOOMINGTON
Dynamic Behavior
https://realpython.com/primer-on-python-decorators/#functions
When called after bedtime …
INDIANA UNIVERSITY BLOOMINGTON
@ symbol
Same as say_whee = my_decorator(say_whee)
https://realpython.com/primer-on-python-decorators/#functions
Back to the Example …
INDIANA UNIVERSITY BLOOMINGTON
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():
return 'Hello world'if __name__ == '__main__':
app.run(debug=True, port=55346, host='0.0.0.0')
Running the Code on Silo
INDIANA UNIVERSITY BLOOMINGTON
Find an Open Port
INDIANA UNIVERSITY BLOOMINGTON
Screen Command1. Versatile Linux Utility
2. Allows User Processes to Continue to Run after Terminal Closes
– Detach and Reattach
3. Key Bindings: https://www.gnu.org/software/screen/manual/html_node/Default-Key-Bindings.html
INDIANA UNIVERSITY BLOOMINGTON
Running Screen
New Screen Process
Start ServerDetach with ServerStill Running
INDIANA UNIVERSITY BLOOMINGTON
INDIANA UNIVERSITY BLOOMINGTON
Reattaching Right back where we left off when the detach was issued
INDIANA UNIVERSITY BLOOMINGTON
CTRL-C to stop
INDIANA UNIVERSITY BLOOMINGTON
System Architecture
Silo Pi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA BoardPi
Press/Temp Sensor
FPGA Board
Pivot.iuiot.orgMQTT Broker
MQTT Messages
Your Flask Web Server
MQTT Messages
Browser Access to PI Systems