So I think the object is destroyed when I reload the page.
I don’t have any idea to solve it :(.
You answer yourself, you need put “require(“php_serial.class.php”);” before you call session_start(), otherwise the object will not be deserialized correctly.
> <h3>If you're running Linux: remember to give permissions to www-data to access usbport ($ sudo chmod 777 /dev/ttyACM0)</h3>
No, No, No!!! unless you want open arduino port access for every one under the sun.
For Apache to access /dev/ttyACM0 www-data must be in the dialout or whatever group.
sudo adduser www-data dialout, restart Apache is the way to go.
BWT. did you prove your code run well without put it into session variable?
I saw your PM today, sorry and hope this answer is not too later.
The way that I give permissions to access to the port, last only until I turn off the computer. So the next time that I turn on the computer, I will have to give permissions again. But that text is because was written in a example that I saw in a blog.
I don’t know much about linux and PHP, so more or less I do what I see in other places or the people say here. Sometimes I don’t know exactly what I am doing.
If I don’t put it using session variables, I get this error:
Notice: Undefined variable: msg in /opt/lampp/htdocs/Arduino/prueba2.php on line 30
Fatal error: Call to a member function sendMessage() on a non-object in /opt/lampp/htdocs/Arduino/prueba2.php on line 30
And this is the code:
if($_GET['message'] == "iniciar")
// echo ($msg);
$msg = new phpSerial();
$msg->deviceSet("/dev/ttyACM0"); // Arduino usb-port
$msg->confBaudRate(9600); //baud rate
$msg->confCharacterLength(8); //Character length
$msg->confStopBits(1); //Stop bits
$msg->deviceOpen(); // open connection
else if($_GET['message'] == "cerrar")
$msg->sendMessage($mensaje); //send the message
<a href="prueba2.php?message=mas">Send instruction "mas"</a>
<a href="prueba2.php?message=menos">Send instruction "menos"</a>
<a href="prueba2.php?message=iniciar">Open session</a>
<a href="prueba2.php?message=cerrar">Close session</a>
This is because when I click on send any instruction, the page is reloaded and the object is destroyed. That is the reason because I thought of use session variables, but I think that the session variables don’t save objects.