Arduino and PHP communication via serial

0

Friends, forgive me for the post, but I do not understand PHP. I already read some other posts here on the site, applied a few things but turned into a mess. The idea is to make PHP send a letter that will serve as a trigger for the arduino to return a value (in my case the temperature of a thermometer) via serial port (COMx) Arduino is returning right temperature at its internal prompt, the only difficulty is to export that data to stop the PHP page.

Follow the code below:

<?php
include 'PhpSerial.php';

$serial = new PhpSerial;


$serial->deviceSet("COM7");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");


$serial->deviceOpen();

sleep (2);





var_dump (fgets ($serial));
if (!$serial)
{
    echo "Não foi possível abrir a porta serial";
}
else
{
    echo "Conectado a porta serial com sucesso";
}
sleep(1);
$serial->sendMessage("t");
sleep (1);
echo fgets ($serial);
sleep (2);
fclose($serial);
?>
    
asked by anonymous 01.12.2016 / 17:45

0 answers