Page 1 of 1

Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by GMawston
Well I have the Home Easy HE803s running now with no problems via the commandline and I have created a very simple index.php page for local and remote control when I am away from home but no matter what I try I cannot get the button to work.

To rule out some parts:

1. The php works ok for a Python command - controlling the Pi Face interface
2. The command lines work

I know a lot of you might be thinking why not use the Telldus Centre but I want to build this all from scratch as a learning curve.

The code below is my index.php file

Code: Select all

<?php


?>
<html>
<head>
<?php 
if (isset($_POST['RedON']))
{
exec("python /var/www/pifaceon.py");
}

if (isset($_POST['RedOFF']))
{
exec("python /var/www/pifaceoff.py");
}

if (isset($_POST['plugon']))
{
exec("tdtool -n 1");
}

if (isset($_POST['plugoff']))
{
exec("tdtool -f 1");
}



?>

  <title>Turn the lights on</title>
</head>
<body>
<form method="post">
  <table
 style="width: 75%; text-align: left; margin-left: auto; margin-right: auto;"
 border="0" cellpadding="2" cellspacing="2">
    <body>
      <tr>
        <td style="text-align: center;">Turn Lamp On</td>
        <td style="text-align: center;">Turn Lamp Off</td>
	<td style="text-align: center;">Turn Plug1 On</td>
	<td style="text-align: center;">Turn Plug1 Off</td>
      </tr>
      <tr>
        <td style="text-align: center;"><button name="RedON">Lamp On</button></td>
        <td style="text-align: center;"><button name="RedOFF">Lamp Off</button></td>
        <td style="text-align: center;"><button name="plugon">Plug On</button></td>
        <td style="text-align: center;"><button name="plugoff">Plug Off</button></td>
      </tr>

    </body>
  </table>
</form>

<p>
Hello there!
<?

?>
</p>


</body>
</html>
If anyone else can help on it would be appreciated. I hazard a guess there is a very simple thing I am missing so if anyone has done this basic step before please let me know.

All the best

Gavin

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by Zapper
You could probably look at the simple script I made for XBMC (And a simple web based remote)
http://www.telldus.com/forum/viewtopic.php?f=8&t=19679

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by davka003
Without any knowledge about php I belive your problem is that the user running the webserver doesn't have permissions to use the tellstick.
If I remember correctly it should be added to the plugdev group or something like that.

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by GMawston
Zapper, the link does not go to the post. Would love to see the code.

Davka, that sounds very plausable because I think the php code is pretty sound. If there is any example code or reference posts let me know.

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by Zapper
http://www.telldus.com/forum/viewtopic.php?f=8&t=3233 Hope this link works, the post is at the end.

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by GMawston
Hello Zapper

Yes it did work and having read your code I managed to pin the problem down very quickly.

I had not explictly stated where the Tdtool was residing so changing it did the trick.

Essentially this:

Code: Select all

exec("tdtool -n 1");
Became this:

Code: Select all

exec("/usr/local/bin/tdtool -n 1");
Such a small change made all the difference.

Thanks again Zapper.

Re: Linux command via PHP

Posted: Fri Mar 17, 2023 9:45 am
by Zapper
No problem, I'm not sure where the default cwd of exec in php is. It might be in the current dir you are running the script from. And exec has no environment so it doesn't know where to look for commands.