WebIOPi : control your Pi’s GPIO with a browser


315 posts   Page 3 of 13   1, 2, 3, 4, 5, 6 ... 13
by frizkie » Mon Oct 01, 2012 4:49 pm
wallarug wrote:
frizkie wrote:Is there any way to use the Pi pin names as opposed to the Broadcom chip names? I'm gonna try and sift through the source code to see if I can get it changed.


If you are using python, You should find something like:
Code: Select all
GPIO.setmode(GPIO.BCM)


Change to:
Code: Select all
GPIO.setmode(GPIO.BOARD)

This will enable numbering using the "pin" numbers. eg. pin 7 = GPIO.output(7).


I'd honestly rather use the php/javascript flavor but I guess it's gonna have to make due. Is there an easy way to get the script to run in the background on startup?
User avatar
Posts: 12
Joined: Mon Sep 24, 2012 7:38 pm
Location: Santa Rosa, CA
by frizkie » Thu Oct 04, 2012 3:30 am
Could you give examples of using the REST API in PHP? I'm having trouble implementing it.
User avatar
Posts: 12
Joined: Mon Sep 24, 2012 7:38 pm
Location: Santa Rosa, CA
by mspitze » Thu Oct 04, 2012 3:19 pm
Great job, now I would like to modify the HTML and CSS files on the PI.
where are these files stored.

Is anyone else having difficulty using iPhone/iPad with Safari browser. I can load the page and toggle the GPIO one time then it stops working.
Posts: 4
Joined: Thu Oct 04, 2012 3:13 pm
by frizkie » Thu Oct 04, 2012 5:55 pm
mspitze wrote:Great job, now I would like to modify the HTML and CSS files on the PI.
where are these files stored.

Is anyone else having difficulty using iPhone/iPad with Safari browser. I can load the page and toggle the GPIO one time then it stops working.


Firstly, assuming you're using the javascript version (not python), it's all stored wherever your other webserver files are - by default it's
Code: Select all
/var/www
.

As for the page loading, make sure you have PHP up to date. You could also try setting the whole webiopi folder to "777" permissions.
User avatar
Posts: 12
Joined: Mon Sep 24, 2012 7:38 pm
Location: Santa Rosa, CA
by mspitze » Fri Oct 05, 2012 3:20 am
thanks for the reply. not sure exactly how to do what you suggested but ill eventually figure it out.

I'm not very familiar with Linux so the commands to perform what u suggest are unclear bit thank you.
Posts: 4
Joined: Thu Oct 04, 2012 3:13 pm
by Ant232 » Fri Oct 05, 2012 6:36 am
Try doing a search for chmod. This is the command for changing file permissions in terminal.
Not sure it is a permissions problem though as it worked the first time you tried it. I'm in a similar situation with phone browsers but haven't found a solution yet..
Posts: 71
Joined: Thu Jul 12, 2012 9:34 pm
by Bengt » Sat Oct 06, 2012 2:16 pm
Howdy again,,

Done some coding on the issue with code not working on IE/Android.

Can somebody guide me in AJAX :-)
I would like the buttons to change colour according to server return value. WEBIOPI returns 1 for on and 0 for off sa you know but how do i read that ?
Have searched alot for simple AJAX but it is often tooooo confusing. I can send the post with this code on both IE & Android.
Neither CSS or AJAX is my skill ;-)

<html>
<head>
<title>the title</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="webiopi.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#on").click(function(event){
$.post(
"/webiopi/GPIO/4/value/0",
function(data) {
$('#stage').html(data);
}
);
});

$("#off").click(function(event){
$.post(
"/webiopi/GPIO/4/value/1",
function(data) {
$('#stage').html(data);
$dta = data;
}
);
});

});
</script>
</head>
<body>
<p>Click on the button to load result.html file:</p>
<div id="stage" style="background-color:white;">
STAGE
</div>
<input type="button" id="on" value="On" />
<script type="text/javascript" language="javascript"> if($dta == "1"){document.write("test");}</script>
<input type="button" id="off" value="Off" style="color:red;" />
</body>
</html>
Posts: 4
Joined: Mon Sep 10, 2012 8:35 am
by Andy60 » Tue Oct 09, 2012 11:06 am
Some finding:
When stopping webiopi after having changed any input to an output you get a warning like "RuntimeWarning: This channnel ....." from the RPi.GPIO module when you restart the module. Saw some other post having this.

If you add "RPi.GPIO.cleanup() (or RPi.cleanup() in the latest file in the trunk path) to the code that stops the http server (direct before or after server.stop()) then this waring disappears.
This will reset all GPIO settings you change with webiopi, but you do that anyway right now when initializing your module, so this should not be a problem.
Posts: 4
Joined: Tue Oct 09, 2012 10:44 am
Location: Stuttgart, DE
by carlvk » Sun Oct 14, 2012 3:22 pm
after editing the conf file and adding the last set of text for lighttpd.conf I get this error

2012-10-14 16:02:02: (configfile.c.943) source: /etc/lighttpd/lighttpd.conf line: 36 pos: 13 parser failed somehow near here: (EOL)
Does anyone know what noob error I may have made this time?
all (polite) comments welcomed
Carlvk
Pi killer
Posts: 28
Joined: Tue Jun 19, 2012 7:43 am
by RobBen » Sat Oct 27, 2012 5:04 pm
Hi,

I tried to use the WebIOPI with my browser.
I succeed to display the image but it does not react to any click.
I use nginx+php.

May be it is due that i do not apply the rewrite part... like it is done for lighttpd.
url.rewrite += (
"^/webiopi/(.*)/$" => "$0",
"^/webiopi/(.*)\.(.+)$" => "$0",
"^/webiopi/(.+)$" => "/webiopi/webiopi.php"
)

What does mean this rewrite ?
How I could write it for nginx?

Thanks
Posts: 1
Joined: Sat Oct 27, 2012 4:55 pm
by rthorson » Tue Oct 30, 2012 1:01 am
Thank you for the work done on this project. It looks like a tool to remote control your Pi. I just can't get it to work. I followed the install instructions and when I access the website, I get the expected page, but when I click nothing happens.When I manually set via export, The website reflects that change but otherwise the direction of each of the I/o ports are gray. Do I need to connect something to the I/O ports because my breadboard and LEDs arrive tomorrow?
Posts: 3
Joined: Tue Oct 30, 2012 12:49 am
by oldcyberdude » Fri Nov 02, 2012 4:49 pm
I'm trying to use the webiopi API with REST in Python. I used the lighttpd implementation on Rpi

Using the requests module in Python for URL handling

r= requests.post("http://eeyore/webiopi/GPIO/18/direction/out", headers={'Content-Length':'0'})
r= requests.post("http://eeyore/webiopi/GPIO/18/value/0", headers={'Content-Length':'0'})
print r

without the content length I get a HTTP 411 response
with content length I get a HTTP 200 however nothing happens.

Everything works fine using my Firefox browser to control the direction and value i.e. send HTTP

Anyone have any thoughts? Thanks in advance.
User avatar
Posts: 9
Joined: Fri Nov 02, 2012 4:35 pm
Location: Aiken, SC
by oldcyberdude » Fri Nov 02, 2012 6:41 pm
Everything works perfectly
print r.content shows post responses etc

using requests get then testing r.content works to verify GPIO operation

webiopi is great thanks!!!
User avatar
Posts: 9
Joined: Fri Nov 02, 2012 4:35 pm
Location: Aiken, SC
by trouch » Sun Nov 04, 2012 7:03 pm
OMG, so many posts ! why I didn't get notified for that ?!
I'll read it all and give an answers as I can.
Thanks for peoples who already helped others ;)

WebIOPi 0.5 is on good way, and will allow many powerfull things
check http://code.google.com/p/webiopi/wiki/CHANGELOG for upcoming features

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by trouch » Sun Nov 04, 2012 7:47 pm
1) Using RPI pin numbering in python is a very bad idea with WebIOPi 0.3 as it suppose pin mode is BCM.
It is solved in 0.5 release as webiopi now relies on it's own native library, so you can use RPi.GPIO without any conflict.

2) Many people make miss-understood of WebIOPi architecture and how python/php/javascript are involved, I need to clarify :
You have a client part, and a server part in WebIOPi.
The client side uses HTML, Javascript and CSS independently of which server you use.

For the server side, you have the choice between PHP and Python :
Python server (webiopi.py) is fully standalone : it's both serve HTML/JS/CSS files and handle GPIO REST API.
PHP script only handle GPIO REST API. File serving relies on the upper server, which can be lighttpd or Apache.
You cannot use PHP and Python at the same time. If you install both, you will only use one of them !

As it's too complicated to maintain two versions at the same time, and as the Python is better (performance, extensibility, security), I stopped PHP development and WebIOPi 0.5 will only be available in Python.

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by pygmy_giant » Sun Nov 04, 2012 7:53 pm
could you theoretically have two pi's controlling each other if they were both each set up as server and client?

can't think of a useful application for that though.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by trouch » Sun Nov 04, 2012 8:04 pm
pygmy_giant wrote:could you theoretically have two pi's controlling each other if they were both each set up as server and client?

can't think of a useful application for that though.


yes you can using the REST API, but you will need to write you're own client.
it's a good idea, I will keep it in mind for 0.6 to include a python client.
the custom callable server macro give more senses to that idea as you will be able to make a RPi farm easily ;)

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by pygmy_giant » Sun Nov 04, 2012 8:19 pm
Essentially then you could build a Mega-Pi with GPIO stretching accross the planet - Mwa-ha-ha-ha.... :twisted:
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by oldcyberdude » Sun Nov 04, 2012 8:55 pm
When you look at a Python client take a look at the "requests" module for the HTTP POST and GET. Requests seems to be very easy to construct the necessary commands.

BTW, on the server side have you considered id, password authentication for more security?
User avatar
Posts: 9
Joined: Fri Nov 02, 2012 4:35 pm
Location: Aiken, SC
by trouch » Sun Nov 04, 2012 9:05 pm
oldcyberdude wrote:When you look at a Python client take a look at the "requests" module for the HTTP POST and GET. Requests seems to be very easy to construct the necessary commands.

Yes there is nothing difficult, just take some time to write a wrapper ;)

oldcyberdude wrote:BTW, on the server side have you considered id, password authentication for more security?

It's on the roadmap, this issue is more general and not only related to P2P (Pi to Pi :D)

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by trouch » Sun Nov 04, 2012 9:09 pm

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by trouch » Sun Nov 04, 2012 11:36 pm
trouch wrote:
oldcyberdude wrote:BTW, on the server side have you considered id, password authentication for more security?

It's on the roadmap, this issue is more general and not only related to P2P (Pi to Pi :D)


Now included in the upcoming release.

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
by spadez » Mon Nov 05, 2012 10:26 pm
Hi,

This script looks really good, I like the way it uses python.

Can you use this to active python scripts or functions on button presses, rather than simply turning pins on and off?
Posts: 2
Joined: Mon Nov 05, 2012 10:25 pm
by pygmy_giant » Mon Nov 05, 2012 10:53 pm
RISCOS comes with PHP 5.2.2 included - maybe it can run WebIOPi too ?
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by trouch » Mon Nov 05, 2012 10:58 pm
pygmy_giant wrote:RISCOS comes with PHP included - maybe it can run WebIOPi with minor alteration

not for the upcoming 0.5 release as PHP is not supported anymore.
only Python version will be available because PHP has too many security and design issue.

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France