bianca
Posts: 18
Joined: Sun Apr 28, 2013 6:04 am

Problem starting script python at boot raspberry pi.

Wed May 22, 2013 6:08 pm

Hello erveryone,

I'am stuck with the folowing problem.
I've made a python script that sends data to a external mysql on another pc.
If i start that script in RC.Local at boot i get a error that he can't connect to the external mysqldb.
But if i login on remote and start it then in the console after loading the desktop there is no problem.
So i think that the internet connection is loaded at the end of eveything and before loading the desktop.

So i tryed to load the script of interfaces earlyer by adding cat /etc/network/interfaces in RC.Local.
But that also did'nt the trick.
So my questing is if somebody has another option/solution?
Hopefully is my question clear enouth.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Problem starting script python at boot raspberry pi.

Wed May 22, 2013 6:55 pm

Try using crontab

Code: Select all

sudo crontab -e
Then add line :

Code: Select all

@reboot python /home/pi/myscript.py
Where myscript.py is your Python script in your /home/pi directory.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

bianca
Posts: 18
Joined: Sun Apr 28, 2013 6:04 am

Re: Problem starting script python at boot raspberry pi.

Wed May 22, 2013 8:44 pm

Sorry but that dos'nt do the trick.
If i bootup the raspberry pi i start some scripts in the RC.Local file.
The file looks at the moment like this.:

Image

You see that my Mainunitscript i've comment in, but that script i want to run , but there comes the problem that then the error comes with no cennection to external sql server.
But if i login to the desktop and start then that script it works greate.

So somehow there goes something wrong with the internet connection, i think the access to internet comes after that loading script rc.load but i don't know if there is a solution to it.

bianca
Posts: 18
Joined: Sun Apr 28, 2013 6:04 am

Re: Problem starting script python at boot raspberry pi.

Thu May 23, 2013 3:45 am

Solved it.
It seems like after loading the rc file some files are loaded after it for example the internet connections.
So i placed in my script before starting the mysql conenction a delay of 20 sec.
Now everything is fine and working perfect.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Problem starting script python at boot raspberry pi.

Thu May 23, 2013 7:28 am

I think you're solving the wrong problem.

The connection to the MySQL server could fail at any time, not just at boot.

Rather than delaying the startup of your application until after the connection should be up, re-write the application to re-try on failed connection attempts.

Return to “Python”