Linux command via PHP
Posted: Fri Mar 17, 2023 9:45 am
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
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
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>
All the best
Gavin