libgpiod with python html armv7

86 Views Asked by At

python script return no matter what

I installed python along with php apache to a armv7 (using linux kernel 6.5-rc6 with buildroot 2023.02.3). I included python extension. I can execute php script without problems but when the php script execute python script like this:

   #!/usr/bin/pytho
   import gpiod
   import time`


    def id_btn():
            line_index=32
            chip=gpiod.Chip('gpiochip0')
            pin=chip.get_line(line_index)
            pin.request(consumer="id0",type=gpiod.LINE_REQ_DIR_IN, default_val=0)
           state=pin.get_value()
           if(state==1):
                    #pin.set_value(0)
                    return 'red'
           else:
                    #pin.set_value(1)
                    return 'lightblue'
    color=id_btn()
    print(f'{color}')

in the html console I receive and it should return red or lightblue. But if i use this other python script:

       #!/usr/bin/env python 
       print('lightblue')

just for testing if the python script is being executed i get the correct output. The gpiod library is not being imported or something else is happening. the php script who is executing the pythons script is this:

    <?php
    $cmd=escapeshellcmd('python /usr/htdocs/html/id0.py');
    $status=shell_exec($cmd);
    echo $status;
    ?>

If I do ./id0.py in the console i got the correct output. I tried many things but don't know why the id0.py is returning empty string in html code. I configure apache to run CGI script like python. The gpiod library is installed because I can execute gpiodetect in console and get gpiochip0 as output. Also I already print the output of this script: import sys print(sys.path) and I get the same for php and python in console output. My guess, import gpiod is not working but why? why the libgpiod is not being executed? Gastón

0

There are 0 best solutions below