0
0
Raspberry Piprogramming~10 mins

Serving sensor data as JSON API in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask module.

Raspberry Pi
from [1] import Flask
Drag options to blanks, or click blank then click option'
AFlask
Bflask
Cjson
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Flask' instead of 'flask' as module name.
2fill in blank
medium

Complete the code to create a Flask app instance.

Raspberry Pi
app = [1](__name__)
Drag options to blanks, or click blank then click option'
AFlask
Bapp
Cflask
Djsonify
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'.
3fill in blank
hard

Fix the error in the route decorator to serve sensor data at '/sensor'.

Raspberry Pi
@app.route('[1]')
def sensor_data():
    return {'temperature': 22.5, 'humidity': 60}
Drag options to blanks, or click blank then click option'
A/sensor
B/Sensor
Csensor
D/data
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash.
Using uppercase letters in the path.
4fill in blank
hard

Fill both blanks to return JSON response using Flask's jsonify function.

Raspberry Pi
from flask import Flask, [1]

@app.route('/sensor')
def sensor_data():
    data = {'temperature': 22.5, 'humidity': 60}
    return [2](data)
Drag options to blanks, or click blank then click option'
Ajsonify
Bjson
CFlask
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'json' instead of 'jsonify'.
Not importing jsonify.
5fill in blank
hard

Fill all three blanks to run the Flask app on host '0.0.0.0' and port 5000.

Raspberry Pi
if __name__ == '__main__':
    app.run(host=[1], port=[2], debug=[3])
Drag options to blanks, or click blank then click option'
A'127.0.0.1'
B5000
CTrue
D'0.0.0.0'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '127.0.0.1' limits access to localhost only.
Setting debug to False during development.