a little background as it might be the cause to the problem. I'm running Armbian legacy Jessie on a Orange Pi Zero. It does not include an desktop so I've installed X, lightdm and xfce. I havn't managed to start X on boot so I have a @reboot line in crontab that executes a script that includes this:
#!/bin/bash while ! ping -c 1 -W 1 192.168.1.100; do sleep 1 done /usr/bin/startx
everything works perfectly (I have autologin enabled and it starts the Mumble client on 1:0). I then have a python script that monitors my GPIO (a push to talk button) and send "CTRL + 1" if the button is pressed. Mumble is listening to that combination and starts broadcasting when it is pressed.
I must run run my python script as root to be able to access the GPIO so I have added these lines to /etc/profile (so that root can access X):
export DISPLAY=:1.0 export XAUTHORITY=/home/icuser/.Xauthority
As said this works perfectly when executed with sudo:
sudo python /home/icuser/sendptt_zero.py
but when I execute my script with (@reboot in crontab):
sudo /usr/bin/python /home/icuser/sendptt_zero.py >> /home/hallgren/ic.log 2>&1 &
I get this in my ic.log file (when I press the gpio button that starts the emulate keybord key function in python (I'm using http://www.autopy.org/)):
No protocol specified Could not open main display
My python script also has this line (won't work without it):
os.environ['DISPLAY'] = ':1.0'
Any ideas on how to get it to start X automatically and why it works from command line with sudo but not when started from crontab?