Go Down

Topic: Arduino Windows PHP (Read 18484 times) previous topic - next topic

RamiDuino

Hello everybody,

I am trying to get an arduino uno to work with PHP through the serial port using the USB cable of Arduino.

I have used the codes that are available in internet that allow you to make this communication between PHP and Arduino without having to install any additional software, library or whatever.

I have programmed the website as follows:

1st file "Serial.php":
-------------------------------------------------
<?php

// declare port

 `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;

?>
-------------------------------------------------


2nd file "SerialTest.php":
-------------------------------------------------
<?php

 //open port com1

 $fp = fopen ("COM1:", "w+");

 if (!$fp) {

    echo "Error while opening COM1.";
 
} else {

    $data = escapeshellcmd($_REQUEST["data"]);
    fwrite ($fp, $data );
}

fclose ($fp);

?>

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Serial port connection</title>
</head>
<body>
 <form method="get" action="SerialTest.php">
   <br />
   <button type="submit" name="data" value="1">ONE</button>
   <br />
   <button type="submit" name="data" value="2">TWO</button>
   <br />
 </form>
</body>
</html>
-------------------------------------------------


The first file seems to work although I am not 100% sure but the leds of the card blink.

the 2nd file gives this error

Warning: fopen(COM1:) [function.fopen]: failed to open stream: Permission denied in <filepath>\SerialTest.php on line 5

Might anyone help me with this issue?

Thank you very much in advance.

RamiDuino

Well, I don't understand this witchery very well, but it looks like the matter is that the first file doesn't do it's job well.

To make it to work I had to start the port COM1 from the Arduino's IDE. And looks like not all ports work, I didn't try it but I found somewhere that just port COM1 to COM4 can be used.

So if you have to change the number of the port because you got something like port COM6 you may change it to COM1 or COM2, COM3, COM4 with the "device manager".

there has to be any other better way using just PHP and Windows for sure.

if you know it please let me know if you got the same problem I may try to help you as soon as I can.

Greetings everybody!

ye646

Well i think i've seen this done before by someone using IOT core arduino c++in visual studio IDE... this code was communicating to a IP based device... i'm not extreemly familiar w/ network IP hardware systems communicating to interfaces but i'm sure this was communicating directly to a dynamic remote server for two way communication which had the .exe... i think i have the link w/ the IOT core just keep in mind windows group policy local/remote or user hosts restricts this type of behavior... so this is strictly for appliances running on a server somewhere w/ full administrative access....

https://docs.microsoft.com/en-us/windows/iot-core/learn-about-hardware/arduinowiringportingguide

xl97

I did some tests on this a WHILE back.. using Flash, PHP and an Arduino..

http://forum.arduino.cc/index.php/topic,124394.0.html

I'm not clear what it is you are even trying to do, to be honest.

Are you trying to READ FROM Arduino serial data using PHP?  or SEND serial data TO an Arduino using PHP?

From what I recall (and where I left off at).. that you can NOT use PHP to read from an Arduio on Windows.. (Linux/Mac do not have this issue)..


sending data TO an Arudino using PHP is possible though...


Also.. you can loading a completely new php file.. you want to do some COM port stuff.. but you never initiate the connection...  file 1 does nothing by itself..



Go Up