User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Give PHP permission to open serial port

Tue Feb 18, 2014 3:05 pm

I've got a python script that sends characters over the serial port to an Arduino Mega. I can get the script to run from the command line but when I try to call it from PHP I get the following error message.

Code: Select all

Traceback (most recent call last):
  File "cgi-bin/serial-to-arduino.py", line 4, in <module>
    port = serial.Serial('/dev/ttyACM0', baudrate=9600, timeout=0)
  File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'
I'm guessing the most important part of this message is the last line

Code: Select all

serial.serialutil.SerialException: could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'
How can I give PHP permission to execute python scripts and access to the serial port?

Thanks
Rich

User avatar
0xFF
Posts: 202
Joined: Tue Nov 20, 2012 7:52 pm
Location: Poland

Re: Give PHP permission to open serial port

Tue Feb 18, 2014 5:38 pm

Can you post your code?
Is PHP code executed from CLI or Apache?

User avatar
DougieLawson
Posts: 39589
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Give PHP permission to open serial port

Tue Feb 18, 2014 5:58 pm

If it's running in a webserver you'll need to add www-data to the serial group.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Re: Give PHP permission to open serial port

Tue Feb 18, 2014 6:40 pm

Thanks Dougie! I've been struggling with this problem for many weeks and now I'm one step closer. Much appreciated!

Rich

Return to “Python”