I'm trying to send instructions from the computer to the Arduino Mega 2560 through PHP and when I open the webpage the Arduino is reseted.
This is the php code:
The communication between the computer and the Arduino is right because Arduino receive the instruction, but I think that when 'fopen' is executed, it reset the Arduino.
I use Ubuntu as operating system, Mozilla Firefox as navigator and Xampp as virtual server.
What is the problem? How could I solve it?
What other way could I use to communicate both systems?
When you open the serial port for communication your Arduino automatically gets reset by the DTR line changing state.
You need to disable this feature to do what you wish to do.
This is the easier solution which disable auto-reset, but I continue having the same problem.
Where '-hupcl' is supossed disables auto-reset (this is the easier solution told in the link you have written which disable auto-reset). But, I am wodering if Firefox sends this signal in spite of I have disabled it.
If the communication works fine through monitor serial of Arduino IDE is because is possible to avoid auto-reset through software.
In the link you have written there is another solution using PERL, but I don't know anything about this language, so I don't know how to use it.
O maybe I should do the communication through php in another way not using fopen().
Without any doubt the reset happens when fopen() is executed because the reset happens and a little bit later the variable is increased. This delay is due to the sleep() instruction.
Without any doubt the reset happens when fopen() is executed
Yes, it does. And again then fclose() is executed.
but I want to solve it through software.
You won't solve it on the Arduino side with software alone. You might solve it on the PC side by making sure that fopen() does not do whatever explicitly causes the reset, but that would affect the entire kernel, so I don't think that's a good idea.
Without any doubt the reset happens when fopen() is executed
Yes, it does. And again then fclose() is executed.
but I want to solve it through software.
You won't solve it on the Arduino side with software alone. You might solve it on the PC side by making sure that fopen() does not do whatever explicitly causes the reset, but that would affect the entire kernel, so I don't think that's a good idea.
My idea is solve it with software on the pc.
What could I do to communicate the pc with Arduino? I don't mind to use other language.
What could I do to communicate the pc with Arduino? I don't mind to use other language.
Typically, you'd open the serial port, letting the Arduino reset. Then, you'd read from and write to the port. When the application on the PC ends, you'd close the serial port, letting the Arduino reset.
Opening the serial port, writing one message, and closing the serial port is what is killing you.
Why did you choose PHP? Perhaps if we knew that we could suggest alternatives.
What could I do to communicate the pc with Arduino? I don't mind to use other language.
Typically, you'd open the serial port, letting the Arduino reset. Then, you'd read from and write to the port. When the application on the PC ends, you'd close the serial port, letting the Arduino reset.
Opening the serial port, writing one message, and closing the serial port is what is killing you.
Why did you choose PHP? Perhaps if we knew that we could suggest alternatives.
I'll try to open the port, write and read from this and close at the end.
This communication is to control a oven (change the temperature, what resistor will be on, put on and off the oven,....)
I use PHP because is the language that I know a bit.
Or maybe you can use php_serial.class.php class file. I used for couple project off my without any problem.
R.
I am trying using this clas but I have the same problem; when i open the connection, the Arduino is reset so I am trying toopen the connection only once but I don't know how to do it. I have tried using a session, but it doesn't works.
This is the code:
When I have oppened the session and I try to send an instruction, I get this error:
Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "phpSerial" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /opt/lampp/htdocs/Arduino/prueba2.php on line 28
So I think the object is destroyed when I reload the page.
I don't have any idea to solve it :(.
iceman_f5:
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.
require("php_serial.class.php");
session_start();
iceman_f5:
If you're running Linux: remember to give permissions to www-data to access usbport ($ sudo chmod 777 /dev/ttyACM0)
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.
iceman_f5:
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.
require("php_serial.class.php");
session_start();
> iceman_f5:
> <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
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.
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
Undefined variable: msg, the $msg = new phpSerial(); never run, since it at an other if block.
break code to one inline code, remove all the session code, html link. if, else if. then test it again.
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
Undefined variable: msg, the $msg = new phpSerial(); never run, since it at an other if block.
break code to one inline code, remove all the session code, html link. if, else if. then test it again.
> So the next time that I turn on the computer, I will have to give permissions again
U might need write udev rule to persistant device node name.
Using your code (activating 'sleep(3)') the program works, but with the problem that each time that I reload the page, Arduino is reseted. I need to avoid to reset Arduino each time that I send an instruction, and due to this I tried to avoid to open the connection each time that I need to send an instruction.
I think that I won't be able to do it using PHP.
I will try to do the communication using Processing. In fact I am doing a simple interface and later I will do the communication.
I think that this will be better than PHP. Better interface and more posibilities.
Thank you for your help. Sincerely, I think I won't be able to do the communication using PHP.