I have a LAMP server set up on my Jetson Nano that can run webpages. I am trying to create a webpage in PHP that can run a python program that turns on an LED at a given duty cycle for a certain number of seconds. Here is the python code being run:
#!/usr/bin/env python
import Jetson.GPIO as GPIO
import sys
from time import sleep
print("hello")
if(len(sys.argv) > 2):
try:
dc = int(sys.argv[1])
delay = int(sys.argv[2])
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
my_pwm2=GPIO.PWM(33,60)
my_pwm2.start(dc)
sleep(delay)
GPIO.cleanup()
except Exception as e:
print(e)
The python code runs fine from the shell. However, when I run the php code, the webpage displays the following message:
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
I have determined that the problem must lie within the Jetson GPIO library, because when I disable all code relating to GPIO functions, the page displays the word ‘hello’ as I intended.
Any help into this matter would be greatly appreciated
just wondering why you need to control LED by webpage.
according to the error messages, it needs root permission for running GPIO controls.
you may try to grant root permission for your webpage implementation.
thanks
I’m trying to create a product where the user can run programs without having to log directly into the Jetson, hence why I want to try and control the GPIO through a webpage.
I tried adding www-data (the user running the server) to the ‘gpio’ group, but that didn’t work.
since there’s default pin configuration, please check developer guide, Configuring the 40-Pin Expansion Header.
please have a try with Jetson-IO tool to simplify the configuration of the I/Os exposed by the 40‑pin expansion header.
after that, you might alter the pin from user-space.
thanks
are you able to execute the command, $ python3 programs/pwm_cmd.py 30 4; via a shell without root permissions?
if not, you should also expect that’s not works by PHP either.
BTW,
since it needs root permission for running GPIO controls.
it’s not a good idea to allow anyone to control GPIO pins from a webpage.
thanks