Benjamin
Benjamin

Reputation: 1253

Trouble with custom PHP extension

A couple of months ago, I built a serial connection library in C for the Arduino Micro-controller. I was thinking about how awesome it would be if I could write a PHP wrapper for the library.

I wrote a PHP extension with just one function called "acm_get_door()," which should either return a -1, 0, or 1, depending upon the status of a certain pin on my Arduino. If it returns -1, then that means that the connection wasn't set.

So after loading up the custom extension and changing both of my php.ini files, and restarting everything else, I ran this test via the CLI:

$ php -r 'echo acm_get_door();'

It returned a '1'. I was excited, so I played with the circuitry to see if I could get a '0'. Well I did and I thought my extension was working perfectly.

I then went to a .php file in my test webserver (same computer) and tried to run the function. I got a '-1' result from it. The extension does load, but I can't seem to initiate a connection to the Arduino.

I am wondering if it might be a permissions thing regarding access to certain files. The function needs to get access to a file called "/dev/ttyACM0" which it is able to in the CLI version. It is possible that my Apache web server doesn't have the permissions to access that file, and if so, how would I be able to adjust stuff so that it does?

Thank you for your time.

Upvotes: 1

Views: 100

Answers (2)

John Jesus
John Jesus

Reputation: 2404

Probably the group has permissions to read/write the device.

Therefore, find out the group owner of the device using ls -l /dev/tty/ACM0. Then, add yourself to the group using:

sudo adduser <me> <the_group>

(where me is your username and the_group is the group of the device)

You might need to log out/in to gain the effect of the changed group permissions.

Upvotes: 1

Benjamin
Benjamin

Reputation: 1253

Okay, thanks to John Jesus, I just had to change the permissions of the file /dev/ttyACM0.

It was set to 660, 666 seems to work (though it it probably a bad idea).

Upvotes: 0

Related Questions