Ic remote over HTTP

116 views
Skip to first unread message

Willem Huisman

unread,
Feb 17, 2014, 5:30:35 PM2/17/14
to web...@googlegroups.com
Hellow guys, i'm working on a raspberry pi powered home control. I bought myself an I/O expander but i dont know how to control that over HTTP. Can you guys maby help with that?

greetz

Toshi Bass

unread,
Feb 17, 2014, 6:25:40 PM2/17/14
to web...@googlegroups.com
Hi Willem

Webiopi is the best and easyest program you will find to control and program most I/O Expanders and gpio in general you can get started checking inputs and switching output with as little as 1 line of code, that beng said it would be usefull to know what type of expander you bought, wether you have it connected, if you down loaded and installed webiopi already and what stage your at like have you followed any of the tutorials yet and what you tried already, that way help would be forthcoming.

Toshi

Willem Huisman

unread,
Feb 18, 2014, 3:23:06 AM2/18/14
to web...@googlegroups.com
Hello and thank you for the fast reaction 
 
I have installed webiopi, loaded device into the list. I even can see it in devices on the normal webiopi List. but now i want to create my own html and use the IC into the html page.  
A normal GPIO button i created followin the webiopi tutorial

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>WebIOPi | Light Control</title>
        <script type="text/javascript" src="/webiopi.js"></script>
        <script type="text/javascript">
        webiopi().ready(function() {
                // Create a "Light" labeled button for GPIO 17
                var button = webiopi().createGPIOButton(17, "Light");
                var control = webiopi().createGPIOButton(25, "Control");

                // Append button to HTML element with ID="controls" using jQuery
                $("#controls").append(button);
                $("#controled").append(control);

                // Refresh GPIO buttons
                // pass true to refresh repeatedly of false to refresh once
                webiopi().refreshGPIO(true);
        });

        </script>
        <style type="text/css">
                button {
                        display: block;
                        margin: 5px 5px 5px 5px;
                        width: 160px;
                        height: 45px;
                        font-size: 24pt;
                        font-weight: bold;
                        color: white;
                }

                #gpio17.LOW {
                        background-color: Black;
                }

                #gpio17.HIGH {
                        background-color: Blue;
                }
        </style>
         <style type="text/css">
                control {
                        display: block;
                        margin: 5px 5px 5px 5px;
                        width: 160px;
                        height: 45px;
                        font-size: 24pt;
                        font-weight: bold;
                        color: white;
                }

                #gpio25.LOW {
                        background-color: Black;
                }

                #gpio25.HIGH {
                        background-color: Blue;
                }
        </style>

</head>
<body>
<table border ="2" style="width:600px">
<tr><td>Relay 1</td><td>Relay 2</td><td> Relay 3</td><td> Relay 4</td><td> Relay 5</td><td>Relay 6</td><td> Relay 7</td><td> Relay 8</td></tr>
<tr><td> <div id="controls"</td></div>
<td><div id="controled" align="left"></div></td></tr></table>
</body>
</html>

 
That is the code i use for controlling GPIO pins . var button = webiopi().createGPIOButton(17, "Light"); create the button for the pin 17 GPIO
 
but how i can i create another button that is controlling the GPIO pins of the IC?
i have a mcp = MCP23017 slave:0x20 imported in my webiopi. Removed it also from the blacklist and i'm able to control it in normal Webiopi interface. I just want to make an own HTML page with my own buttons!
 
Thanx ,
 
Willem
Message has been deleted

Toshi Bass

unread,
Feb 18, 2014, 11:21:40 AM2/18/14
to web...@googlegroups.com
Hi Willem

There are a number of ways to do this, however I would recommend that you continue to follow Tutorials - Using Devices - The "Heater" in this example is being switched using  MCP23017 pin 7 if you follow that you will be able to extrapolate how it is working and how to add further buttons to control more of your i/o expander pins.

Hope that's helpfully

Toshi

Or you could use the attached and add to it.
index.html

Willem Huisman

unread,
Feb 18, 2014, 3:47:07 PM2/18/14
to web...@googlegroups.com


Op dinsdag 18 februari 2014 17:21:40 UTC+1 schreef Toshi Bass:
Thank you again Toshi for the great help. Is it maby possible to upload a python script to? Should be awesome. Are you availible for chats if i need any help?

Greetz Willem 

Toshi Bass

unread,
Feb 18, 2014, 4:38:42 PM2/18/14
to web...@googlegroups.com
Hi Willem

Other than setting up the mcp function to OUT there is no requirement in this code for python.

So I think all you need in your script.py until you want to add other stuffs is the following:-

#!/usr/bin/python 
# Imports
import webiopi

mcp = deviceInstance("mcp")            # retrieve MCP23017 device named "mcp" in configuration file

# Called by WebIOPi at script loading
def setup():
# Sets all 16 pins on mcp to outputs
    for x in range(0, 16):
       mcp.setFunction(x,GPIO.OUT)


# Called by WebIOPi at server shutdown
def destroy():
# Sets all 16 pins on mcp back to input
    for x in range(0, 16):
        mcp.setFunction(x,GPIO.IN)

I had a further play around with this as I have some relays that require a pulse to energize and another pulse to de-energize so if anyone's interested see attached, the first 4 buttons use two mcp pins, one to hold the state (On or Off)  and another pin that would be connected to the relay that needs the pulses.

Please do not send me any private emails, I will help but only via this group, as I believe everyone benefits from the questions and answers.

Toshi Bass



index.html
Reply all
Reply to author
Forward
0 new messages