davetedd
Posts: 10
Joined: Sat Nov 04, 2017 2:21 pm

Extra time mystery with time.strftime

Mon May 14, 2018 11:07 am

I have created a python program for recording the time at which a warning signal is given and the start signal 5 minutes later using the command in the title for a dinghy racing starting procedure.. This works fine when run using the python command with the system up and running and the RTC in the system operational.
If however I put this program into rc.local so it loads on boot up then when it is run the warning signal time records ok but the start signal is shown as 5 mins 23 secs later rather than the actual 5 mins. The system time and RTC time give the same time when checked. Does anyone have any ideas? Any suggestions would be appreciated.

gordon77
Posts: 3269
Joined: Sun Aug 05, 2012 3:12 pm

Re: Extra time mystery with time.strftime

Mon May 14, 2018 11:59 am

Can you upload your code so we can see it?

davetedd
Posts: 10
Joined: Sat Nov 04, 2017 2:21 pm

Re: Extra time mystery with time.strftime

Mon May 14, 2018 4:44 pm

How do I add code to my reply? I have not been able to find an answer to that query. There is no "insert" function, such as is used in emails?

User avatar
DougieLawson
Posts: 33308
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Extra time mystery with time.strftime

Mon May 14, 2018 5:16 pm

Cut'n'paste is your friend.

Wrap the code in code tags [code]... paste your stuff here ...[/code]
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

davetedd
Posts: 10
Joined: Sat Nov 04, 2017 2:21 pm

Re: Extra time mystery with time.strftime

Tue May 15, 2018 8:12 am

Thanks for that help - will post it later.

davetedd
Posts: 10
Joined: Sat Nov 04, 2017 2:21 pm

Re: Extra time mystery with time.strftime

Wed May 16, 2018 8:59 am

This is testusb.sh

Code: Select all

#!/bin/bash
test -e /media/usb?/raceflag?.py
if [ $? -eq 0 ]
then 
sudo python /media/usb?/raceflag?.py
else
sudo python /home/pi/programs/race/insmem.py
fi
exit 0
and this is rc.local

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
printf "\n testline" &
./bin/testusb.sh &
exit 0
The actual race program is raceflag1.py. If the unit is turned on without the right usb stick inserted a warning is given.

User avatar
DougieLawson
Posts: 33308
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Extra time mystery with time.strftime

Wed May 16, 2018 6:06 pm

What are all of sudos doing there? DO NOT use sudo unless you need to elevate privileges. BTW, /etc/rc.local runs as root anyway so nothing in it needs sudo anyway.

Also please post your python code.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

davetedd
Posts: 10
Joined: Sat Nov 04, 2017 2:21 pm

Re: Extra time mystery with time.strftime

Fri May 18, 2018 7:27 am

The problem was caused by the system time taking some time to update from the rtc after bootup. Once that was done the timing was correct.
So a solution will be to force an update before the program can be run.
On the sudo issue the commands are in a bash script which runs inside rc.local. If I leave them out then the usb memory stick detection feature does not work. I had to do that because the test command does not function if put directly into rc.local. The latter aborts if any command in it gives a false answer, so any test which can give a true or false answer does not operate. I tried some work arrounds but no result.
Anyway ok now thanks for your comments.

User avatar
DougieLawson
Posts: 33308
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Extra time mystery with time.strftime

Fri May 18, 2018 7:48 am

Add uid=pi,gid=pi to the options on the mount command for the USB stick and it won't need sudo if you're running as the pi user.

mount -o uid=pi,gid=pi /dev/sda1 /mount/point/here
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “Advanced users”

Who is online

Users browsing this forum: droleary and 16 guests