Introduction: Browser Controlled Bot
We would like to introduce the BrowserBot: a project at Dexter Industries to turn the Raspberry Pi into a robot.
“The browserBot” is a web-browser controller robot using the BrickPi. With this project, we demonstrate how to control a BrickPi robot directly from the browser of any computer, tablet, or phone.
Step 1: Overview
Using the browserBot you can build your own web-controlled robot in very very easily with just a few lines of code. The browserBot is a good place to start if you want to build a project using BrickPi to send and receive information directly to a web page.
Step 2: Building the BrowserBot
Step 3: Code
The code for the browserBot is available on our BrickPi Python Github Repository under the “Project Examples” folder.
To pull the example code, just clone the BrickPi Python Repository,
There are two files in the Project_Examples\browserBot folder in the repository:
- Browser_Client_Code.html : This page runs on the client computer, cell phone, or tablet browser, the one from which you want to control the bot.
- RPi_Server_Code.py: This code runs on the Raspberry Pi Server and controls the robot.
Step 4: Prepare Your Pi
This code needs “Tornado” for python installed on your Raspberry Pi. Tornado will allow us to use Web Sockets with our Raspberry Pi. Web sockets will allow us to communicate back and forth between the Raspberry Pi and the client.
To install Tornado on Raspberry Pi, first install pip on the RaspberryPi:
sudo apt-get install python-pip
And then install Tornado for python using PIP:
pip install tornado
To run this example, you won’t need to know too much about tornado or websockets. But if you if you are new to Web Sockets and want to know more about how they work, here’s a good place to learn a little more.
Step 5: Using the Robot (Part 1)
The Raspberry Pi and the client (your browser, phone, tablet, or computer) must be connected to the same WiFi network. So begin by making sure everything is on the same wifi network.
Once you’re connected and have Tornado installed on the RaspberryPi, run RPi_Server_Code.py in terminal on the Raspberry Pi:
Step 6: Using the Robot (Part 2)
After the server is running on the Raspberry Pi, download Browser_Client_Code.html from the BrickPi Github Repository to the device you want to control the browserBot from.
Run the client code Browser_Client_Code.html in the web browser of any device such as a laptop or a Mobile Phone as long as they are on the same network as the Raspberry Pi.
Once the HTML page it loaded, enter the BrickPi’s IP address into the text box and press “clickme”. There will be a short lag as the browser connects to the Raspberry Pi, and then you should be able to control the browserBot with the buttons on your web page.
Step 7: Errors and Troubleshooting:
If you get the following error:
socket.error: [Errno 98] Address already in use
Run netstat on the terminal and check which process is currently using the port 9093:
sudo netstat -ap |grep :9093
Note down the PID (Process IDentifier) of the process running it and kill that process :
If it does not work use:
kill -9 pid
If the error does not go away, try changing the port number ’9093′ both in the client and server code.
Tip:Don’t use Ctrl+Z to stop the program, use Ctrl+c.
If you use Ctrl+Z, it will not close the socket and you won’t be able to run the python server on the Raspberry Pi the next time.
We have a be nice policy.
Please be positive and constructive.