<!DOCTYPE html>

<html>

<TITLE>Simple menu for switches</TITLE>

<STYLE type="text/css">

      html { width: 100%; height: 100%; }

      body { display: flex; justify-content: center;align-items: center;}

 div { height: 400px; width: 600px; background: white;

position: fixed; top: 20%;  left: 50%;

             margin-top: -100px; margin-left: -200px;}

   input { font-size: 32px;} 

      form {  outline-offset: 40px;}

</STYLE>

<body>

<div>

 

<?php

/* This program can be used to control 4 energenie switches from an apache2 web server. 

The program uses the PIN based GPIO access library, WiringPI. 

You can get that from:   http://wiringpi.com/

 

The code also leans heavily on that in the demo  python program 

ENER002-2PI.py published by Energenie  and available here:

https://energenie4u.co.uk/catalogue/download_software/ENER002-2PI.py

 

The program is a php program working in an apache web server environment. 

The web page has one $get parameter, an interger, 

fetched in a name value pair  using the Get method.  This is checked  

and contrained to valid values and the bit values used to control the 

rasberry pi GPIO pins enabling the switches to be controlled.  THe page 

can be called from another web page possibly with a GUI to control the 

switches.   

 

Valid on values  15,13,11,7,3.   13 is all on

Valid off values 14,10,10,6,2.   12 is all off

*/

        $sw = (int) $_GET['sw']; 

        /* get the name vallue pair from the  web page call */

    /* contrain the value of $sw to the values used for the switches */

if ($sw>0 and $sw<16  ) 

{

/*  convert the integer to bits values used to set the GPIO pins */

        $d3=$sw & 1;

        $d2=($sw &2) >> 1; 

        $d1=($sw &4) >> 2; 

        $d0=($sw &8) >> 3;

         /*set the gpio pins used to outputs */

         shell_exec("/usr/local/bin/gpio -g mode 17 out");

         shell_exec("/usr/local/bin/gpio -g mode 22 out");

         shell_exec("/usr/local/bin/gpio -g mode 23 out");

         shell_exec("/usr/local/bin/gpio -g mode 27 out");

         shell_exec("/usr/local/bin/gpio -g mode 24 out");

         shell_exec("/usr/local/bin/gpio -g mode 25 out");

         usleep(10000); /*let things settle */

/* set gpio pin values */ 

         shell_exec("/usr/local/bin/gpio -g WRITE 17 $d0");

         shell_exec("/usr/local/bin/gpio -g write 22 $d1");

         shell_exec("/usr/local/bin/gpio -g write 23 $d2");

         shell_exec("/usr/local/bin/gpio -g write 27 $d3");

         /* Set the modulator to ASK from FSK by setting pi GPIO 24 to 0*/

         shell_exec("/usr/local/bin/gpio -g write 24 0");

          /* we are going to toggle the modulator to transmit the signal to the switches */

        shell_exec("/usr/local/bin/gpio -g write 25 0");

         usleep(10000);

         shell_exec("/usr/local/bin/gpio -g write 25 1");

         usleep(250000);

         shell_exec("/usr/local/bin/gpio -g write 25 0");}

/*Having set the switches, we revisit the form for new clicks */

?>  

 

<hr>

  <form action=<?=$_SERVER['PHP_SELF']?> method="get">

  <input type="radio" name="sw" value="15"> <label style="font-size: 32px;">SWITCH ONE ON</label><br>

  <input type="radio" name="sw" value="14"><label style="font-size: 32px;">SWITCH ONE OFF</label><br>

  <input type="radio" name="sw" value="11"><label style="font-size: 32px;">SWITCH TWO ON</label> <br>

  <input type="radio" name="sw" value="10"><label style="font-size: 32px;">SWITCH TWO OFF</label><br>

  <input type="radio" name="sw" value="7"><label style="font-size: 32px;">SWITCH THREE ON</label><br>

  <input type="radio" name="sw" value="6"><label style="font-size: 32px;">SWITCH THREE OFF</label><br>

  <input type="radio" name="sw" value="3"><label style="font-size: 32px;">SWITCH FOUR ON</label><br>

  <input type="radio" name="sw" value="2"><label style="font-size: 32px;">SWITCH FOUR OFF</label><br>

  <input type="radio" name="sw" value="9"><label style="font-size: 32px;">SWITCH Five ON</label><br>

  <input type="radio" name="sw" value="8"><label style="font-size: 32px;">SWITCH Five OFF</label><br>

  <input type="radio" name="sw" value="5"><label style="font-size: 32px;">SWITCH Six ON</label><br>

  <input type="radio" name="sw" value="4"><label style="font-size: 32px;">SWITCH Six OFF</label><br>

  <input type="radio" name="sw" value="13"><label style="font-size: 32px;">SWITCH ALL ON</label><br>

  <input type="radio" name="sw" value="12"><label style="font-size: 32px;">SWITCH ALL OFF</label><br>

  <hr>

  <input type="submit" value="Submit">

  <hr></form>

 </div></body></html>