Arduino and PHP communication via serial

Asked

Viewed 250 times

0

Friends, forgive me for the post, but I don’t understand PHP. I’ve even read some other posts here on the site, applied some things but it’s become a mess. The idea is to have PHP send a letter that will serve as a trigger for Arduino to return a value (in my case the temperature of a thermometer) via serial port (Comx) Arduino is returning the temperature right at its internal prompt, the only difficulty is to export this data to 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);
?>
  • I don’t know much about Angola, but I suppose I have to make this data available by writing the script inside the Arduino written in C.

  • I thought so too. But I saw some examples that people only ask for PHP to read the serial port and print the results on the screen. Arduino only sends the sensor readout result. Thanks for helping Guilherme

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.