I'm having a CGI script in C language, which open the serial port ttyUSB0 in my Raspberry pi, send a data at my device and get it response.
This script perform correctly when i'm launch it manually in the terminal but my web page can't access to this port to open it.
My code :
int main (void) {
printf("Content-type: text/html\n\n");
const int fd = open ("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_SYNC);
if (fd == -1)
{
printf ("error %d opening %s: %s", errno, "ttyUSB0", strerror (errno));
return 0;
}
And the response in the web page : "error 13 opening ttyUSB0: Permission denied"
And below the output of the command "id -Gn pi" : pi adm tty uucp dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin
Thanks.
The command below solved my problem :
sudo adduser www-data dialout