setting time with /etc/init.d/iotkit-agent script

setting time with /etc/init.d/iotkit-agent script

You may have noticed that in the current IOT image date is set via timeapi. However, the date doesn't seem to be set correctly. With the change below it works for me (although timezone isn't taken into account):

 

--- /tmp/iotkit-agent      2014-03-11 16:19:05.790009204 +0000
+++ /etc/init.d/iotkit-agent         2014-03-11 16:21:41.000000000 +0000
@@ -1,9 +1,9 @@
#!/bin/sh

 # update local time to UTC
-TM=$(curl -s http://www.timeapi.org/utc/now?format=%25Y.%25m.%25d-%25H:%25M)
-echo $TM
-date "${TM}"
+TM=$(curl -s http://www.timeapi.org/utc/now?format=%25Y-%25m-%25d+%25H:%25M)
+#echo $TM
+date -s "${TM}"

 # start agent
NODEJS="/usr/lib/node_modules"

 

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

by accident I just found that /etc/init.d/udev script sets env variable TZ. Just wonder: is this the right place to set it?

I'd recommend using rdate to set the time, instead of the hack in that init script. For example (probably could find a better timeserver!)

rdate -s tick.greyware.com

To set TZ i'd recommend creating /etc/localtime and either linking to the correct tzdata file from the tzdata package from iotdk.intel.com/ipk/, or just copy it from another linux box that has your correct timezone. The file you mention will export the TZ env var as whatever the /etc/localtime is, if you don't have /etc/localtime it will instead use 'UTC'.

root@G:/etc/init.d# export TZ=/etc/localtime
root@G:/etc/init.d# echo $TZ
/etc/localtime
root@G:/etc/init.d# date
Wed Mar 12 18:12:01 GMT 2014

 

cool, thanks - I completely removed the time stuff from iotkit-agent and added following init script

# cat > /etc/rc5.d/S99setrdate <<EOF
echo "setting date via rdate"
rdate -s time.fu-berlin.de
EOF

seems to work as expected

 

... also commented out the "sanity check" part in /etc/rcS.d/S55bootmisc.sh which killed my timezone set in /etc/localtime before as follows:

#
# This is as good a place as any for a sanity check
#
# Set the system clock from hardware clock
# If the timestamp is more recent than the current time,
# use the timestamp instead.

#test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh start
#if test -e /etc/timestamp
#then
# SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M`
# read TIMESTAMP < /etc/timestamp
# if [ ${TIMESTAMP} -gt $SYSTEMDATE ]; then
#  date -u ${TIMESTAMP#????}${TIMESTAMP%????????}
#  test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh stop
# fi
#fi

now date, time and timezone work for me

 

Hi   matthias  and    brendan,

Just want to pop in and say hi. I've been following for a few days and see the changes being made to the NTP stuff.

Is this for the image ->  software.intel.com/sites/default/files/devkit-live-img-final.binblob.bz2 ?

I'm DL ing it now. Being the noob that I am, it took me a little bit to find it. hehe

The Dashboard was a little confusing to me as I want look for it but all the compilers and other tools have all weird names like a marketing guy came up to make it sound super-duper. System Studio 2014 and Studio everything else.

Now being an OSS kind-of guy, let me try and get this right. The Yocto will bake down an embedded image to load up to what ever device you want ? And the Wind River is another tool set that sits around the Yocto to help build things like ToR Switch image that fits into the ONP framework along with all the goodies you can build into it.  Right ?

I just want to throw all Thanks your way and to the rest of intel.  Enormous stuff here and unbelievable open door to create endless variety of solutions.

Chris 

 

 

 

 

 

 

Hi Chris,

@changes for devkit-live-img-final.binblob.bz2: Yes, this thread is around the SD card image. On this image date/time doesn't seem to be set correctly. With the rdate approach I tried out and described date/time is set correctly for me and timezone is picked up form /etc/localtime which I set (ln -s) to my timezone in /usr/share/timezone (after installing tzdata as mentioned by Brendan).

Quote:

Christopher M. wrote:

Is this for the image ->  software.intel.com/sites/default/files/devkit-live-img-final.binblob.bz2 ?

Yes, although I'd recommend you grab it form here : http://iotdk.intel.com/images/iot-devkit-201402201605-mmcblkp0.direct.bz2

Quote:

Christopher M. wrote:

The Dashboard was a little confusing to me as I want look for it but all the compilers and other tools have all weird names like a marketing guy came up to make it sound super-duper. System Studio 2014 and Studio everything else.

Yes we're working on trying to make the dashboard a bit easier to navigate - bear with us!

Quote:

Christopher M. wrote:

Now being an OSS kind-of guy, let me try and get this right. The Yocto will bake down an embedded image to load up to what ever device you want ? And the Wind River is another tool set that sits around the Yocto to help build things like ToR Switch image that fits into the ONP framework along with all the goodies you can build into it.  Right ?

Well right now we don't provide anything from Windriver. The aim is to do that in future releases and we demo'd the capability at MWC. Here's the way I'd put it, WR vxworks is a hard realtime OS whilst yocto allows you to build a custom linux. Here's a cute yocto linux commercial that tells the story nicely: http://vimeo.com/24743626

Quote:

Christopher M. wrote:

I just want to throw all Thanks your way and to the rest of intel.  Enormous stuff here and unbelievable open door to create endless variety of solutions.

Thanks for playing with our stuff!

playing around with the current development image (based on Yocto devkit-next on http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel-iot-devkit/) my workaround described above doesn't work any longer. As a new workaround based on rdate I use following


	# cat /etc/systemd/system/set_rdate.service

	[Unit]

	Description=runs rdate to set correct date/time

	After=connman.service

	Requires=connman.service

	 
[Service]

	ExecStart=/bin/bash /usr/sbin/set_rdate
[Install]

	WantedBy=multi-user.target

	

with


	# cat /usr/sbin/set_rdate

	while [ 1 ]; do

	a=$(rdate -s time.fu-berlin.de 2>&1)

	if ! `echo ${a} | grep "bad address" 2>&1 >/dev/null`; then exit; fi

	sleep 1

	done

	

This script will try every second to ntp sync date with in my case time.fu-berlin.de (put in whatever ntp server you prefer) until network is accessible (and hence "bad address" will not be printed) and will exit then.

Obviously you would need to enable the service with

systemctl enable set_rdate.service

 

Login to leave a comment.