0

In my current project with Rpi I am using two python scripts at the startup. One is the GUI script and the other one is the normal terminal script. It is actually a live graph update of various sensors. The problem that I am currently facing is with shutdown and reboot of Pi. When I do a reboot or the shut down my scripts runs good for like 20s or 30s and then the graph suddenly jumps to somewhere random on time axis skipping approximately 50s or something. But when I call the script with

sudo python3 Test.py

it just functions flawlessly.

What I comprehend is that when I reboot or shutdown my pi, somehow the script in the autorun doesn't kill itself. I'd be grateful if someone can help me with this bug.

Thank you in advance

0

When I do a reboot or the shut down my scripts runs good for like 20s or 30s and then the graph suddenly jumps to somewhere random on time axis skipping approximately 50s or something.

This is because the pi doesn't have a clock. It gets its time from the network.

When it first boots, it has no network connection, so it either uses the unix epoch or else a stamp from when the system shut down. If this is a reboot, that will probably be sometime < 1 minute ago.

Once the internet is accessible, the correct time can be acquired and the clock is immediately updated; this will cause to system time to jump forward.

A simple way to deal with this would be to just wait a period of time at boot to avoid the issue. Rather than starting it directly, use a shell wrapper like this:

#!/bin/sh

( 
  sleep 150
  exec /usr/bin/python /path/to/Test.py 
) &
exit 0

This will start a subshell in the background which sleeps for 150 seconds (2.5 minutes) before starting the the process.

You could also drop that code straight into /etc/rc.local (omitting the shebang line, #!/bin/sh).

  • I think you are right. I had shutdown my pi for over half an hr and then again started it, it worked good for 20sec and then again jumped to somewhere around 1800 secs. Is there a way to make this thing correct? I am also using time.time() and time.clock() in my script.. – Ajay Sep 20 '16 at 13:18
  • You could buy an RTC (clock) module. Or at boot you could start from a shell wrapper with a 2 or 3 minute sleep in it; I've added an example of this above. If you are confident about how long it takes to get online and get the time obviously you could shorten that. – goldilocks Sep 20 '16 at 13:26
  • Thank you so much for your help. Somehow it didn't work with etc/rc.local but then I added a time.sleep(60) in my script before the GUI is launched. Once again thank you. – Ajay Sep 20 '16 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.