2

I was able to control one arm of an OWI-535 (Maplin) Robot Arm using GPIO pins and python programming (via L293 driver) , so I tried to do the same using a web page created in PHP.

Created buttons for forward and reverse motions and tried to call the python program but it does work.

The web page is being displayed and when I press the button, the strings 'test1 and test2' corresponding to the button press is being displayed. (using echo function in php)

I'm using LIGHTTPD web server. Here is the code.

<html>
<head>
<?php
if(isset($_POST['ForwardMotion']))
{
exec('sudo python /var/www/ArmForward.py');
echo "test1";
}
if(isset($_POST['BackwardMotion']))
{
exec('sudo python /var/www/ArmBackward.py ');
echo"test2";
}

if(!(isset($_POST['ForwardMotion'])) & !isset($_POST['BackwardMotion']))
{
echo"</head>";

echo"<body>
<form id=\"form1\" name=\"form1\" method=\"post\" action=\"Roboarmdemo.php\">
<table width=\"333\" height=\"124\" border=\"1\">
<tr>
<td width=\"155\" height=\"30\"> UPWARD</td>
<td width=\"162\">DOWNWARD</td>
</tr>
<tr>
<td><input type=\"submit\" name=\"ForwardMotion\" value=\"Forward\" /></td>
<td><input type=\"submit\" name=\"BackwardMotion\" value=\"Backward\" /></td>
</tr>

</table>
</form>
</body>
</html>";

}

?>
Piotr Kula
  • 17,336
  • 6
  • 66
  • 105
Ron Thomas
  • 363
  • 2
  • 5
  • 14

3 Answers3

1

Edit your /etc/sudoers

sudo nano /etc/sudoers

add:

www-data ALL=(ALL) NOPASSWD: ALL
s3bi
  • 160
  • 1
  • 2
  • 7
1

Alternatively, without making www-data a sudoer, you can look into some gpiod software that allow you to drive GPIO pins through a socket, without root privileges.

Maxthon Chan
  • 1,051
  • 8
  • 14
0

It is because lighttpd is being run from it's own user which is NOT:

  1. in the sudoers group
  2. listed as a sudoer with no password authentication for all commands

So basically the sudo command is being executed but it returns a warning about how the lighttpd user is not in the sudoers file/sudo group and this incident will be reported.

Two possible solutions would include:

  1. Adding lighttpd user(it's www-data or www, don't recall exactly) to the sudoers file and add the corresponding entry to execute python(or all commands) without using password authentication

  2. Run lighttpd as root user and omit sudo

The later solution is quick and dirty, but this is rPi. It's an embedded solution with probably no intention of leaving your desk, so basically do everything with root.

Oh and if you decide to make something production ready, please read online materials for securing embedded devices. Hope my answer was useful

Artis
  • 31
  • 3