Hi at all I’ve a problem with serial communication from PHP to Arduino.
Errors:
Warning: Unable to open the device in C:\xampp\htdocs\progetto\librerie\php_serial.class.php on line 187
Warning: Device must be opened in C:\xampp\htdocs\progetto\librerie\php_serial.class.php on line 608
I’m using the library php_serial.class.php, my OS is Windows and the port of Arduino Uno is COM13.
PHP code:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
if (isset($_GET['action'])) {
require("librerie/php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("COM13");
$serial->confBaudRate(9600);
$serial->deviceOpen();
sleep(2);
if ($_GET['action'] == "green1") {
$serial->sendMessage("0");
} else if ($_GET['action'] == "green0") {
$serial->sendMessage("1");
}
$serial->deviceClose();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ARDUINO</title>
</head>
<body>
<h1> ARDUINO AND PHP COMMUNICATION </h1>
<a href="?action=green1">ON</a>
<a href="?action=green0">OFF</a>
</body>
</html>
Arduino code:
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);
}
}