e210 engineering cyber -physical systems (spring 2021) flask
TRANSCRIPT
![Page 1: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/1.jpg)
Flask
Bryce Hime baugh
E210 Engineering Cyber-Physical Systems (Spring 2021)
![Page 3: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/3.jpg)
INDIANA UNIVERSITY BLOOMINGTONINDIANA UNIVERSITY BLOOMINGTON
Raspberry PI/Basys3 Link
![Page 4: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/4.jpg)
Flask Overview
![Page 5: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/5.jpg)
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 …
![Page 6: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/6.jpg)
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
![Page 7: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/7.jpg)
Minimal Example
![Page 8: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/8.jpg)
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')
![Page 9: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/9.jpg)
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')
![Page 10: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/10.jpg)
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')
![Page 11: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/11.jpg)
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')
![Page 12: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/12.jpg)
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')
![Page 13: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/13.jpg)
Python Function Decorators
![Page 14: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/14.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Functions
https://realpython.com/primer-on-python-decorators/#functions
![Page 15: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/15.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Functions can be Passed as Arguments
https://realpython.com/primer-on-python-decorators/#functions
![Page 16: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/16.jpg)
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
![Page 17: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/17.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Returning Functions
https://realpython.com/primer-on-python-decorators/#functions
Function Reference Returned
Can call these functions like any other function
![Page 18: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/18.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Decorators
https://realpython.com/primer-on-python-decorators/#functions
Decorators wrap the original function
![Page 19: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/19.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Dynamic Behavior
https://realpython.com/primer-on-python-decorators/#functions
When called after bedtime …
![Page 20: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/20.jpg)
INDIANA UNIVERSITY BLOOMINGTON
@ symbol
Same as say_whee = my_decorator(say_whee)
https://realpython.com/primer-on-python-decorators/#functions
![Page 21: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/21.jpg)
Back to the Example …
![Page 22: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/22.jpg)
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')
![Page 23: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/23.jpg)
Running the Code on Silo
![Page 24: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/24.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Find an Open Port
![Page 25: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/25.jpg)
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
![Page 26: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/26.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Running Screen
New Screen Process
Start ServerDetach with ServerStill Running
![Page 27: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/27.jpg)
INDIANA UNIVERSITY BLOOMINGTON
![Page 28: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/28.jpg)
INDIANA UNIVERSITY BLOOMINGTON
Reattaching Right back where we left off when the detach was issued
![Page 29: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/29.jpg)
INDIANA UNIVERSITY BLOOMINGTON
CTRL-C to stop
![Page 30: E210 Engineering Cyber -Physical Systems (Spring 2021) Flask](https://reader031.vdocuments.site/reader031/viewer/2022011803/61d355015509a2389a29013e/html5/thumbnails/30.jpg)
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