Skip to content

Switch On and Off everything via Wi-Fi with Raspberry Pi, Python and Bottle.

License

Notifications You must be signed in to change notification settings

VRB95/RaspberryPi_WifiRelayControl

Repository files navigation

RaspberryPi_WifiRelayControl

HitCount License: MIT

This project describe the usage of bottle web-framevork in combination with Raspberry Pi, for controlling any GPIO pins via Wi-fi. Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. The main controller is a WebPage wich also have some CSS styles and JS functions integrated wich can be extended as you want.

Table of Contents

Built With:

Prerequisites

I'll asume you already have installed python 3.x, now install Bottle on your Rpi:

  • via pip
pip install bottle
  • on Raspbian
sudo apt-get update
sudo apt-get install python-bottle

Circuit Diagram

Parts List:
  1. Raspberry Pi
  2. Relay module

Usage

Just run:

sudo python web_relay.py

in the repo folder. This script will transform your Rpi in a local-server. Now, enter in your web browser, or in the web browser of your phone (the Rpi and the phone need to be conected to the same network) the Rpi's IP adress, followed by the "/on" or "/off".

Example: 192.168.255.255/off

After the initial imports of the Bottle and RPi.GPIO libraries, the control pin for the relay is defined and set to be an output. There then follow three functions, each marked with a line preceding it that starts @route. Each of these functions will be called when the web server receives a request for a particular resource. So, “/”, the root page will just return the contents of the template “home.tpl”. If the request is for “/on” or “/off” then the template is still returned, but first the relay is switched on or off as appropriate. The final section of the code is a try/finally block that starts the web server running ctrl-c is pressed.

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature)
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Vesa Bogdan - vesabogdan95@gmail.com

Project Link: https://github.com/VRB95/RaspberryPi_WifiRelayControl

About

Switch On and Off everything via Wi-Fi with Raspberry Pi, Python and Bottle.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages