Flask is a tool for having the pi host a local webserver (A web server is a computer that runs websites). Flask should be pre-installed on the Pi.
Start by creating your Python/Flask application in Thonny. The basic example to get you started is flask_led.py
Python and Flask will manage the incoming data and physical reaction
HTML will take care of displaying everything in a browser.
Start by creating your Python/Flask application in Thonny. The basic example to get you started is flask_led.py
Python and Flask will manage the incoming data and physical reaction
HTML will take care of displaying everything in a browser.
You'll need to create a folder in the same directory as the Python file. This directory must be called templates.
In the templates folder you to have an HTML file called led-index.html.
This will be easiest to do using the application Geany (you already have the file but you'll need to change the name from led-index.html to index.html)
When you run the code in Thonny, you'll see a link show up in the shell something like http://0.0.0.0:5000/. Click on that link to open your web application in a browser.
you can also use the hostname. For example http://lemur.local:5000
Take a minute to interact with this application.
Any device on the same network (like your phone) can also interact with this web application. Type your Pi's IP address into a browser with :5000 on the end. Example: 10.1.15.75:5000
Note: to see the updates on your Pi's page, click the refresh button.
Here's another example that throws some Javascript into the HTML and prints the status of the LED. If you are in other room, you can know what the status of the LED is. Just replace the index.html file with this one called led_status_index.html
Challenges / Take it further:
Can you create multiple buttons that control multiple LEDs?
Can you add a toggle button that turns the LED to the opposite state no matter what state its in?
Style the web app to make it look more interesting