Question about autostart program in LXDE

General programming chat and advice for beginners

9 posts
by hzhwang » Fri Jan 04, 2013 12:17 am
Hi everybody,

I wrote a python script using Tkinter and GPIO, so far it works fine.
I hope to start it in a more simple way: Just connect power, RaspberryPi will boot, start LXDE and run my python script automatically.

But I have no idea how to start python script with sudo(or run as root , because it uses GPIO)
I tried add them ~/.config/autostart/auto.desktop or .xsession but not working, maybe I mistake something..

Any ideas or suggestions would be greatly appreciated
==
My RaspberryPi playground http://ezzep.blogspot.com
Posts: 19
Joined: Mon Oct 22, 2012 4:44 pm
by -rst- » Fri Jan 04, 2013 12:43 pm
Shouldn't that be ~/.config/autostart/.desktop (not auto.desktop)? http://wiki.lxde.org/en/Autostart
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 895
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by hzhwang » Fri Jan 04, 2013 2:28 pm
-rst- wrote:Shouldn't that be ~/.config/autostart/.desktop (not auto.desktop)? http://wiki.lxde.org/en/Autostart


Thanks for reply, much appreciated


I had tried setting them in ~/.config/autostart/.desktop before, but still not working.
Maybe I am setting wrong command, here is my .desktop (autostart.desktop) file:

Code: Select all

[Desktop Entry]
Name=Timer
Comment=Start Timer script
Exec="gksu python /home/pi/timer.py" (I tried '/usr/bin/sudo /usr/bin/python /home/py/timer.py' too, still the same)

==
My RaspberryPi playground http://ezzep.blogspot.com
Posts: 19
Joined: Mon Oct 22, 2012 4:44 pm
by Ph1lj2 » Fri Jan 04, 2013 3:43 pm
hzhwang wrote:Hi everybody,

I wrote a python script using Tkinter and GPIO, so far it works fine.
I hope to start it in a more simple way: Just connect power, RaspberryPi will boot, start LXDE and run my python script automatically.

But I have no idea how to start python script with sudo(or run as root , because it uses GPIO)
I tried add them ~/.config/autostart/auto.desktop or .xsession but not working, maybe I mistake something..

Any ideas or suggestions would be greatly appreciated

Hi
Did you ever get this to work - like you I'm trying to fire-up a python script that uses Tkinter and GPIO
so far not getting anywhere

I've tried Crontab - seems to have no effect
Any help would be appreciated
Posts: 35
Joined: Sat Oct 20, 2012 9:21 pm
by hzhwang » Fri Jan 04, 2013 10:36 pm
Ph1lj2 wrote:
hzhwang wrote:Hi everybody,

I wrote a python script using Tkinter and GPIO, so far it works fine.
I hope to start it in a more simple way: Just connect power, RaspberryPi will boot, start LXDE and run my python script automatically.

But I have no idea how to start python script with sudo(or run as root , because it uses GPIO)
I tried add them ~/.config/autostart/auto.desktop or .xsession but not working, maybe I mistake something..

Any ideas or suggestions would be greatly appreciated

Hi
Did you ever get this to work - like you I'm trying to fire-up a python script that uses Tkinter and GPIO
so far not getting anywhere

I've tried Crontab - seems to have no effect
Any help would be appreciated


Hi,
Finally I found the answer, use LXSession
http://wiki.lxde.org/en/LXSession#Automatically_start_some_applications_on_login

First, add
Code: Select all
#!/usr/bin/env python

in the first line of python script, and make the file executable with it, like
Code: Select all
chmod +x timer.py


Second, edit(or create) LXSession file in path
~/.config/lxsession/LXDE/autostart
and add this line:
Code: Select all
/usr/bin/sudo ~/timer.py


if python script not start successfully, you can check the ~/.xsession-errors file

Below video link shows how it works
http://www.youtube.com/watch?v=7yTRxifqIdQ
==
My RaspberryPi playground http://ezzep.blogspot.com
Posts: 19
Joined: Mon Oct 22, 2012 4:44 pm
by Ph1lj2 » Mon Jan 07, 2013 5:28 pm
hzhwang wrote:
Ph1lj2 wrote:
hzhwang wrote:Hi everybody,

I wrote a python script using Tkinter and GPIO, so far it works fine.
I hope to start it in a more simple way: Just connect power, RaspberryPi will boot, start LXDE and run my python script automatically.

But I have no idea how to start python script with sudo(or run as root , because it uses GPIO)
I tried add them ~/.config/autostart/auto.desktop or .xsession but not working, maybe I mistake something..

Any ideas or suggestions would be greatly appreciated

Hi
Did you ever get this to work - like you I'm trying to fire-up a python script that uses Tkinter and GPIO
so far not getting anywhere

I've tried Crontab - seems to have no effect
Any help would be appreciated


Hi,
Finally I found the answer, use LXSession
http://wiki.lxde.org/en/LXSession#Automatically_start_some_applications_on_login

First, add
Code: Select all
#!/usr/bin/env python

in the first line of python script, and make the file executable with it, like
Code: Select all
chmod +x timer.py


Second, edit(or create) LXSession file in path
~/.config/lxsession/LXDE/autostart
and add this line:
Code: Select all
/usr/bin/sudo ~/timer.py


if python script not start successfully, you can check the ~/.xsession-errors file

Below video link shows how it works
http://www.youtube.com/watch?v=7yTRxifqIdQ


Hi

thanks for the suggestions, I tried it today :-

firstly I could not find the appropiate folder "~/.config/lxsession/LXDE/autostart", so after reviewing the link I put my autostart file in the /usr/share/lxsession and created a new folder LXDE
- no joy

The contents of my autostart file was
" sudo /home/pi/mcp3008/ python b1g.py"

Unfortunately this achieved nothing

Any ideas ?
Posts: 35
Joined: Sat Oct 20, 2012 9:21 pm
by hzhwang » Mon Jan 07, 2013 10:39 pm
Ph1lj2 wrote:
Hi

thanks for the suggestions, I tried it today :-

firstly I could not find the appropiate folder "~/.config/lxsession/LXDE/autostart", so after reviewing the link I put my autostart file in the /usr/share/lxsession and created a new folder LXDE
- no joy

The contents of my autostart file was
" sudo /home/pi/mcp3008/ python b1g.py"

Unfortunately this achieved nothing

Any ideas ?


Hi,
My environment is Raspbian “wheezy” (2012-12-16), not sure it will be some different or not

Here is my runtrought

0.write a simple python script(like 'boottest.py'). when execute it,it will generate a file 'working'. (Remember setting it executable and add #!/usr/bin/env python in file)

1.find ~/.config/lxsession/LXDE/autostart
cd /home/pi
cd .config
cd lxsession
cd LXDE


2.
vi autostart

and add this line:
Code: Select all
/usr/bin/sudo ~/boottest.py


Reboot system.
If lxsession setting is correct, a file 'working' would appear in your home directory, if not appear, check the ~/.xsession-errors log file

3.replace boottest.py with what python script you want execute (like b1g.py) and check it working correctly or not.(In this step you have better test it with RaspberryPi connects monitor directly.)
==
My RaspberryPi playground http://ezzep.blogspot.com
Posts: 19
Joined: Mon Oct 22, 2012 4:44 pm
by -rst- » Tue Jan 08, 2013 12:18 pm
hzhwang wrote:1.find ~/.config/lxsession/LXDE/autostart
cd /home/pi
cd .config
cd lxsession
cd LXDE


To make that more generic (= to work for other users than 'pi' as well):
Code: Select all
# instead of cd /home/pi
cd  ~

(~ is a 'shortcut' to the current user's home dir - usually '/home/<username>')

In addition, if some of those directories is missing, just create then before cd'ing into... f.eg. 'mkdir .config'
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 895
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by Nexus12 » Fri Jan 11, 2013 1:46 am
-rst- wrote:
hzhwang wrote:1.find ~/.config/lxsession/LXDE/autostart
cd /home/pi
cd .config
cd lxsession
cd LXDE


To make that more generic (= to work for other users than 'pi' as well):
Code: Select all
# instead of cd /home/pi
cd  ~



(~ is a 'shortcut' to the current user's home dir - usually '/home/<username>')

In addition, if some of those directories is missing, just create then before cd'ing into... f.eg. 'mkdir .config'


Cool managed to get it to work - thanks for your help

Will continue testing soon

Cheers
Posts: 10
Joined: Sat Jan 05, 2013 10:37 pm