PHP - Arduino communication - the best way?

HI,

i've tried to communicate between arduino and php. I used the php_serial class and it works great (linux server) with a simple instructions.

My goal is to control two or more output pins and read the input pins using php.
And now how i want to do this:

I send a string to arduino:'1;0;0;1' to set pin1:HIGH, pin2:LOW, pin3LOW, pin4:HIGH.
As response send arduino to php a string '1;1;0' what means pin5 is HIGH, pin6 is HIGH and pin7 is LOW.

Do you think it is a good idea?
In php i will use the explode function to get an array from the string.
In Arduino i have to do the same, but c has no explode function, do you have any idea how to do this?

Thanks for help!

On the arduino, strings are an array of chars. You can get the individual characters using stringName[0] for the first, stringName[1] is the second, etc.

Something you might also want to consider (depending on your needs, of course, and the environment the system will be used in) is to add a beginning and termination character to the data packet being sent to the Arduino. When you do your reading for data on the Arduino, you can check for these characters, and if you don't see them, or the count (size) of the packet is wrong, you reject the packet and do nothing.

This is useful, for instance, if your design is to be used in a potentially electrically noisy environment (say within the electrical system of a vehicle), or your application needs the robustness from a safety or operations standpoint (perhaps in an autonomous robot, in which you are communicating with the Arduino via a PC, sending and received commands and telemetry data).

Just something to consider.

:slight_smile: