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!
Hey there, You have done a great job. Ӏ'll dеfinitely digg it аnd personally recommend tо my friends.
Ӏ am confident they ѡill be benefited frоm thyis web
site.
WOW just աɦat I ѡas searching for. Camе here bƴ searching fοr Rasberry Pi
Excellent!
It worked flawlessly
Thank you.
how to include html page ???? can you please help me?
hi, could you please be more specific?
Can you explain step 3 in detail, i mean where to include form.render() in html script.
Hi,
You have to include it inside the tag 'form'. I have uploaded the complete HTML file in the following link. I hope this helps. https://github.com/Vikramank/Pi-control-from-mobile/blob/master/templates/index.html
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?
Hi,
Sure. You can use a framework like Web2Py(http://www.web2py.com/). If this ain't sufficient, I can write up a tutorial for you (after 20th June!) Let me know
It would be really great if you could write a tutorial. 🙂
Hey Viky,
How do I inject data continuously from the database to the web server?