Skip to main content
deleted 25 characters in body
Source Link
Steve Robillard
  • 34.9k
  • 18
  • 104
  • 109

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file.

This is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file.

This is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file.

This is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake?

see comment
Source Link
goldilocks
  • 60.1k
  • 17
  • 115
  • 230

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file. This is the jquery code:

<html>
<head>
<title>LED App</title>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<script>
$(document).ready(function(){
$("off").click(function(){
$.ajax({url:"/gpio/off.py"});
});
});
</script>
<script>
$(document).ready(function(){
$("on").click(function(){
$.ajax({url:"/gpio/on.py"});
});
});
</script>
</head>
<body>
<on><button>LED ON </button></on>
<off><button>LED OFF</button></off>
</body>
</html>

and thisThis is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file. This is the jquery code:

<html>
<head>
<title>LED App</title>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<script>
$(document).ready(function(){
$("off").click(function(){
$.ajax({url:"/gpio/off.py"});
});
});
</script>
<script>
$(document).ready(function(){
$("on").click(function(){
$.ajax({url:"/gpio/on.py"});
});
});
</script>
</head>
<body>
<on><button>LED ON </button></on>
<off><button>LED OFF</button></off>
</body>
</html>

and this is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file.

This is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)

Source Link

PHP or jquery to execute python scripts for GPIO

I want to use php or jquery to control gpio pins on my raspberry pi 2. I have apache installed. When i execute python files using LXTerminal, they work fine. I have made the .py files executable and added www-data to sudoers file. This is the jquery code:

<html>
<head>
<title>LED App</title>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<script>
$(document).ready(function(){
$("off").click(function(){
$.ajax({url:"/gpio/off.py"});
});
});
</script>
<script>
$(document).ready(function(){
$("on").click(function(){
$.ajax({url:"/gpio/on.py"});
});
});
</script>
</head>
<body>
<on><button>LED ON </button></on>
<off><button>LED OFF</button></off>
</body>
</html>

and this is the php code:

<html>
<head>
<?php 
if (isset($_POST['ON']))
{
exec('sudo python var/www/gpio/on.py');
}
if (isset($_POST['OFF']))
{
exec('sudo python var/www/gpio/off.py');
}
?>
</head>
<body>
<form method="post">
<button name="ON">LED On</button>
<button name="OFF">LED Off</button>
</form>
</body>
</html>

python script

#!/usr/bin/python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, 1)

What's the mistake? Thanks in advance :)