Here we will use Python web framework called Flask to create a dynamic web server in Odinub. Flask provides you with the tools, libraries and technologies that allow you to build a web application. thie web application can be some web pages, web server, a blog or a commercial website.
Step 0: WiFi setupFor setup the WiFi on your odinub board follow our another article
Step 1: Install FlaskIn order to install Flask we will need to have pip install. It can be installed by following commands.
sudo apt-get install python-pip
After installing pip we can use it to install Flask and its dependencies.
sudo pip install Flask
Step 2: Python ScriptTo test the installation create a new file called hello_odinub.py using this command.
sudo nano hello_odinub.py
Type this code in newly open window.
From flask import Flask
App=Flask(__name__)
@app.route(“/”)
Def hello():
Return “Hello!! its Odinub”
If __name__ == “__main__”:
App.run(host=”0.0.0.0”,port=80,debug=True)
Step 3: Get the IP addressWe have to replace 0.0.0.0 with the IP address of Odinub. This IP address can be known by the following command.
ifconfig wlan0
Now enter the following command to run the web server.
sudo python hello_odinub.py
Now open the web browser any type the following link.
http://0.0.0.0:80/
This is the small taste of what you can do with python and Flask. I hope this project helps you in your IoT applications as it creates the web server on local network and helps you to find your way into exciting world of electronics.
Comments
Please log in or sign up to comment.