For this part, you'll need a working web server (like Apache) running on your computer, and you will need to put all the files at the root of your web server main folder.
You can find the complete code for this part by following this link:
http://arduino.local/mode/7/o
http://arduino.local/mode/8/o
Once this is done, we are going to code the web app. The app is basically composed of three parts:
- An HTML page that contains the interface (I also added some CSS to make it look better)
- A JavaScript file that handles the commands coming from the interface
- A PHP file to communicate with the Arduino board by making REST calls
<button class="relayButton" type="button" id="1" onClick="buttonClick(this.id)">On</button>
if (clicked_id == "1"){ $.get( "curl.php", { pin: "7", state: "1"} ); }
This PHP file starts by getting the pin & state to be sent to the Arduino board:
$pin = $_GET['pin']; $state = $_GET['state'];
$service_url = 'http://arduino.local/digital/' . $pin . '/' . $state;
$curl = curl_init($service_url);
$curl_response = curl_exec($curl); curl_close($curl);
echo $curl_response;