xl97
Posts: 12
Joined: Thu Jan 12, 2017 3:34 pm

PHP & Serial comm with RPi?

Wed Aug 08, 2018 9:20 pm

I have attempted serial comm via PHP to Arduono using a WAMP install on a PC...

serial comms seemed to work only one way.. and I was told that this was a PC issue, but on MAC/Linux, PHP serial comm works two ways without issue.

I have previously set up a RPi with Apache, MySQL and PHP...... (for some added support/features in an MQTT set-up/project)

I have never attempted to use PHP serial communication when things were on a Pi.

I will have an Arduino connected to the RPi.....
The RPi will have a webpage served up that I write.

What I would like to happen is upon clicking a link/hotspot in the hosted webpage it to send some serial data upon $_POST[] to the connected Arduino via PHP... have the webpage sit in an 'idle' state... and when the Arduino is done doing its task(s).. send out a serial message back to the RPi/PHP script.. and then change the display state/view of the hosted webpage.. (waiting for another 'user interaction' so to speak)


Re-cap:
Is 2-way serial communication possible with PHP when running on an RPi3?

Thanks

User avatar
DougieLawson
Posts: 33379
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP & Serial comm with RPi?

Thu Aug 09, 2018 3:49 pm

If it runs under Apache2, Lighttpd or NGinx then you'll need to add user www-data to the dialout group.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

xl97
Posts: 12
Joined: Thu Jan 12, 2017 3:34 pm

Re: PHP & Serial comm with RPi?

Thu Aug 09, 2018 9:37 pm

Thank you for the reply.

I have VERY LITTLE linux experience..... so once I get to that point of testing (in like 4 weeks I'm guessing).. I'll have to do some searching about this 'dial out group' stuff..

Clarification:

If sending OUT via PHP works normally under a default WAMP install..

using like so:

Code: Select all

<?PHP

     $pwmValue=$_POST["pwmValue"];

     exec("mode COM4 BAUD=9600 PARITY=N data=8 stop=1 xon=off");

     $fp = fopen("com4", "w");

     if (!$fp) {
        echo "Not open";
     }else {
        fwrite($fp, $pwmValue);
        fclose($fp);
     }

?>


and only the INCOMING data (from Arduino >> PHP) doesnt work...

is it still the 'dialout' group? (That allows for both incoming and outgoing data communication?


Its been a while since I installed MySQL/PHP...etc on a Raspberry Pi (and I've only done it tone time anyways).. I believe it was Apache.


Either way.. sounds like it wont be an issue (just need to 'do it')...

thanks!

User avatar
DougieLawson
Posts: 33379
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP & Serial comm with RPi?

Fri Aug 10, 2018 6:51 am

Open an LXTerminal window and enter these two commands
sudo usermod -a -G dialout www-data
sudo reboot
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “Other programming languages”

Who is online

Users browsing this forum: No registered users and 4 guests