I've got PHP script for control Arduino's diode via website, but I've got a problem.
My Arduino code is:
int green = 8;
int incomingbyte;
void setup()
{
Serial.begin(9600);
pinMode(green,OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
incomingbyte = Serial.read();
}
if(incomingbyte == '0'){
digitalWrite(green,HIGH);
}
if(incomingbyte == '1'){
digitalWrite(green,LOW);
}
}
My PHP code is:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
if (isset($_GET['action'])) {
require("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("COM3");
$serial->confBaudRate(9600);
$serial->deviceOpen();
if ($_GET['action'] == "green1") {
$serial->sendMessage("0");
} else if ($_GET['action'] == "green0") {
$serial->sendMessage("1");
}
$serial->deviceClose();
}
And my HTML code:
<!DOCTYPE html>
<html>
<head>
<title>ARDUINO</title>
</head>
<body>
<h1> ARDUINO AND PHP COMMUNICATION </h1>
<a href="led.php?action=green1">ON</a></br>
<a href="led.php?action=green0">OFF</a></br>
</body>
</html>
I've got two problems:
Arduino is getting only incomingbyte = 0, so I can turn diode on, but I cannot turn it off. I modified code to set incomingbyte = 1 to turn diode on, but it's not working also. So I think Arduino is getting only incomingbyte = 0.
My website is shuting down after running script. When I click on "ON" or "OFF" script is running and I'm getting white (blank) site. What should I do to stay all the time on my HTML site?