Controlling Raspberry Pi from your mobile


One of the best features of Raspberry Pi is that it provides a hassle-free methods to control with mobile devices. In this article I'll explain in detail how to blink LEDs connected Raspberry Pi from mobile. You'll need the following:

  • A Raspberry pi with Ethernet or Wifi card.
  • Bread Board
  • An LED and a corresponding resistance
  • Connecting wires

Incase if you don't have access to LEDs and breadboard components, never mind. You can still try out this experiment. I've given codes to print the status of LED. Every time you send the command to Rasperry Pi, it will print the status of LED.

Brief Intro:

In Rasperry Pi I'll be running a python script to switch ON and OFF the LED. I'll start a server in my Raspberry Pi which will give access to all the devices in the network to connect to it and send commands. The Raspberry Pi will receive commands and performs the desired actions.

Understanding Webpy

Webpy is a python framework which enables to write webpages using python. The beauty of it is, we can write Python inside HTML which makes things easy. Webpy runs a server in Raspberry Pi and the webpage we have created using webpy will be accessible to all the devices connected to the network . After starting the server we can send commands via the HTML page. These commands will be taken as inputs and the corresponding actions will be carried out.
Note: Webpy accesses the index.html file in the templates folder and the css,images etc in the static folder.

Understanding LED connections

Step one: Installing WebPy

You'll need to install Webpy package in your Raspberry pi. In your terminal screen type the following code.

~$wget http://webpy.org/static/web.py-0.37.tar.gz
~$ tar xvzf web.py-0.37.tar.gz
~$ cd web.py-0.37  
~$sudo python setup.py install

Step two: Writing the python scripts

In order to render the webpage and control GPIO pins, we have to import "web" and "GPIO" packages. I've uploaded the python script in my Git account

Step three: Writing HTML and CSS Scrits

In your HTML script include the following code that renders webpy's content.

 $:form.render()       

In order to have a better display in mobile devices I used Bootstrap CSS. I have uploaded the HTML and CSS files in my Git account.

Step four:Find the IP address of the Pi

Find the IP address of the Pi using the following command.

~$ifconfig

Step five: Run the code

Navigate to the folder and start the server by running the code.

~$sudo python led.py

Step six: Open in your mobile browser

Open the URL:"ip.address.of.pi:8080/" and start controlling your Pi. Enjoy!

12 thoughts on “Controlling Raspberry Pi from your mobile

  1. Hey Viky,

    Could you help me out on how I can develop a HMI system where I have to display entries from the database to to the website? How do we do the injection of data?

Leave a Reply

Your email address will not be published. Required fields are marked *