Click the magnifying glass in the top right corner of the screen and type “terminal” to find the terminal app
Replace the text “pibot##” with the label on the PiBot
The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!
ssh pi@pibot##.local
sudo raspi-config
wget http://osoyoo.com/driver/picar/webcam.sh wget http://osoyoo.com/driver/picar/camstart.sh bash webcam.sh
bash camstart.sh
Replace the text “pibot##” with the label on the pibot
Answer “yes” or “y” when asked to install extra packages or continue
wget http://osoyoo.com/driver/picar/osoyoowebcar.sh bash osoyoowebcar.sh
Replace the text “pibot##” with the label on the pibot
sudo python3 webcar.py
Replace the text “pibot##” with the label on the pibot
You may need to adjust the mounting position of the camera holder to point straight forward
The webcar.py file uses a Python library called Flask that handles the details of serving a webpage to your web browser. Using libraries like Flask is a powerful way to get advanced capabilities in your software without having to write a lot of code from scratch. By using the Flask library there are only a few lines of code that are required to make the PiBot drive around from your web browser.
The app.run function is what calls the Flask library and tells it to send pages to your web browser.
Port 80 is the standard port used on the Internet when you type http:// at the beginning of the web address
If you don't remember what a variable is, review the description from Lesson 1
</WRAP round tip>The '@app.route' that appears above the action function is called a function decorator. It tells Python that this function has special meaning to the Flask library.</WRAP>
The @app.route decorator is used by Flask to run a function when a certain URL is accessed by your web browser. Every page displayed by your web browser can be accessed by a URL. Most URLs start with http:// or https:// and then the website name like google.com or yahoo.com. After the website, often there is a path that tells the web server exactly which web page you want to see. Flask uses that path to determine what function to run based on the @app.route decorator.
The '<action>' and '<cmd>' values in the call to the @app.route decorator are passed to the action function as the 'action' and 'cmd' parameters.
Each path ends up calling another function in the code as determined by the 'if' statements. Find where those functions are defined in the code to see what happens when each path is requested.
sudo python3 webcar.py
Replace the text “pibot##” with the label on the pibot
The render_function template takes the file name that is passed as its parameter and sends it to the web browser that is accessing it. All of the files must be in the 'templates' directory for Flask to be able to send them.
The “GET” command is a standard HTTP command that web browsers use to request a URL from the web server. Some other commands are “POST”, “PUT”, and “CONNECT”.
The '<script> tag starts a block of Javascript code in the middle of an HTML file. Javascript allows a web page to be more interactive than simply displaying information. The index.html file uses Javascript functions to send the commands back to the Raspberry Pi so that you can control the PiBot.
HTML uses tags that are contained between '<' and '>' brackets. The HTML tags are used to organize, format, and draw the elements that you see on a web page.
Don't forget to create a Javascript function to actually send the request. Copy one of the existing functions and modify it.
sudo shutdown -h now