Running a python script on a raspberry pi
-
@daproduct, this worked for me:
su - pi -c 'export DISPLAY=:0.0; /usr/bin/chromium https://google.com'
-
@Russ Thank you kindly Russ. Everything is running properly and I have been able to program in what I wanted. Thank you and I apologize for the trouble. I don't know how many times you have dealt with these issues specifically
-
@daproduct , no problem. Thanks for sharing your TRIGGERcmd use cases.
-
-
Hello Russ,
I hope you are doing well! I had an issue arise with "xhost +". Previously, my scripts would run using xdotool without issue. I would simply say the particular command (through assistant or wherever) and the xdotool command would be executed. Now, I can only get the xdotool commands executed after I type "xhost +" in the linux command terminal, but not after the initial startup of the Raspberry Pi.
I am curently running a Raspberry Pi 4 with debian (i can't recall which version but can provide the specifics if necessary). I recently updated through apt-get etc and that is when the issue arose. Thank you in advance and any help would be much appreciated.
-
@daproduct, please try this:
Add this line to your /etc/profile file:
xhost +
I think that will make it persist.
-
@Russ
Thank you Russell. I had xhost + in that location (ie. etc/profile and at the end of the file) and I believe I had it there based on your previous instructions. I tinkered around further this evening and I found that problem only occurs after an initial startup. If the command is started again after occurring a start-up (ie. run again after startup) then it works without issue. I tried to circumvent the issue with a delay and that did not work. I found a workaround of commanding the script to run again, but I wanted to get the script working as it previously was and if it was possible. I was wondering if you happen to know why this might be the case. Thank you in advance -
@daproduct, I'm not sure why that didn't work. I thought what's in /etc/profile runs for every user, so when your pi user logs in it should run. Have you tried adding it to pi's ~/.bashrc file? That's another thing you could try.
If it still doesn't work, let me know. I'll setup one of my Pi's with XWindows and see if I can figure it out.
-
@Russ
Thank you again Russ. Unfortunately, that did not work either. The script only executes after run it again. -
@daproduct, can you share your scripts and commands.json entry? I'll see if I can reproduce the problem and solve it this weekend.
-
@Russ
Hello again Russ. I have the command simply running from the commands.json. The command is just the one you had helped me with previously. The command opens a website, waits for a few seconds, and then its a xdotool command.The command I am trying to run is:
"su - pi -c 'export DISPLAY=0.0; /usr/bin/chromium-browser https://www.yt.com/subscriptions/; sleep 5; xdotool mousemove 300 400; xdotool click 1;'"The first its run after startup, nothing happens. If I run the same command again, it executes without issue. I tried to tinker with it this weekend to save some time on diagnostics, but the same issue continues to persist.
-
I tested it on my Raspberry Pi, except I used DISPLAY=:0 instead of DISPLAY=0.0.
"su - pi -c 'export DISPLAY=:0; /usr/bin/chromium-browser https://www.yt.com/subscriptions/; sleep 5; xdotool mousemove 300 400; xdotool click 1;'"
It worked every time after I ran triggercmdagent as root on my Raspberry Pi.
You wrote, "The first its run after startup, ..." What's startup? Do you mean startup of the triggercmd agent, or startup of the Raspberry Pi?
Edit: I just realized you're probably having your RPi login automatically as pi, and you've installed the background agent. I'll try that next.
I tried it and it works every time for me. I installed the background agent with this command:
/usr/share/triggercmdagent/app/src/installdaemon.sh
I switched the "ground" field to "background" of course, so my entry looks like this:
{ "trigger": "Test", "command": "su - pi -c 'export DISPLAY=:0; /usr/bin/chromium-browser https://www.yt.com/subscriptions/; sleep 5; xdotool mousemove 300 400; xdotool click 1'", "ground": "background", "voice": "test", "allowParams": "false" }
I also added xhost + to the end of my /etc/profile so it's enabled during boot.
-
@Russ
Thank you Russ for looking into it.With the startup, I was referring to the RPI starting / booting up from being turned off. I noticed that the issue only happens from the RPI starting up and on the first instance a command is run. The next time a command is run, the command executes without issue. The main problem is the xdotool command not being executed on this first instance. However, the page is loaded.
Also, I do have TriggerCMD installed as a background agent using that command and I do have xhost+ addeed to the end of the /etc/profile