# Automatic time sync

**URL:** <https://forum.legato.io/t/automatic-time-sync/5185>\
**Category:** Legato Application Framework\
**Created:** [May 5, 2020, 2:33pm UTC](https://forum.legato.io/t/automatic-time-sync/5185 "2020-05-05T14:33:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 5, 2020, 2:33pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/1 "2020-05-05T14:33:22Z")

</div>

Hi,  
Can anyone clearly explain how date/time sync should to work in legato framework?  
From my understanding it should automatically sync date with network, but for me it doesn’t happen.

Ideally device time also should be synced when data connections is established (i am connecting to airvantage). According to logs system tries to do this but fails (incorrect time set intentionally):

> Apr 20 18:17:04 fx30 user.warn Legato: -WRN- | dcsDaemon[26811]/dcsDaemon T=main | dcsServer.c GetTimeServer() 881 | No server configured, use the default one  
> Apr 20 18:17:14 fx30 user.err Legato: =ERR= | dcsDaemon[26811] | rdate: timeout connecting to time server  
> Apr 20 18:17:14 fx30 user.err Legato: =ERR= | dcsDaemon[26811]/dcsDaemon T=main | dcsServer.c RetrieveTimeFromServer() 2077 | Unable to retrieve time from server  
> Apr 20 18:17:14 fx30 user.err Legato: =ERR= | avcDaemon[27360]/avcDaemon T=main | avcClient.c CheckDateTimeValidity() 223 | Unable to retrieve date or time from server

but where the time server is configured? is it an ntpd server from /etc/time\_service.conf?  
running ntpd -p doesn’t work for me as well…

My device: Sierra FX30 (WP7702). Mobile network connection only.  
Worth to mentions that this device is not intended to work in Europe (Ireland) so it falls to 2G connection. This may be causing issues with network time sync but why time is not synced over data connection?

Am i missing something?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 5, 2020, 2:56pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/2 "2020-05-05T14:56:50Z")

</div>

Does this help?

> [@How to change NTP server](https://forum.legato.io/t/how-to-change-ntp-server/3124/14):
>
> Application that has a call to system(“/usr/sbin/ntpd -p \<your ntp server here\>”); has to be UNSANDBOXED otherwise it wont work. I can confirm also that: TIME\_SERVICES=“ntpd\_time” works only if I connect to internet via eth cable.

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 5, 2020, 3:00pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/3 "2020-05-05T15:00:11Z")

</div>

If it’s the same as running (/usr/sbin/ntpd -p ntpserver) in terminal with root privileges - no it doesn’t work.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 5, 2020, 3:36pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/4 "2020-05-05T15:36:14Z")

</div>

How about setting it to qualcomm time to receive time from network?  
You can also check at+cclk?

---

<div class="post-metadata">

**Author:** ![lazzox](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@lazzox](https://forum.legato.io/u/lazzox)\
**Post date:** [May 5, 2020, 3:45pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/5 "2020-05-05T15:45:04Z")

</div>

When we had a problem like this our issue was that not all cellular network providers would have this option to get time from them so we switched to using some ntpd servers and edited the init.d script that updates time.  
We edited it in a way that it triggers contacting ntdp server only when there is internet connectivity. So what we do, we ping ntpd servers until internet connectivity is available, then we obtain time from ntpd and we don’t even use cellular network time.

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 5, 2020, 4:08pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/6 "2020-05-05T16:08:56Z")

</div>

Thanks for the reply @lazzox  
Yes it looks like my issue. I would write script but the problem is ntpd -p also doesn’t work. Did you have such issues? Would you mind sharing the script?

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 5, 2020, 4:21pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/7 "2020-05-05T16:21:11Z")

</div>

@jyijyi,  
As @lazzox mentioned it may not be a reliable way to sync date.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 6, 2020, 2:55am UTC](https://forum.legato.io/t/automatic-time-sync/5185/8 "2020-05-06T02:55:29Z")

</div>

I don’t see problem, please see below:

root@swi-mdm9x28-wp:~# date  
Thu Jan 1 08:08:44 +08 1970  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# /etc/init.d/ntpd\_time\_service start  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# date  
Wed May 6 10:54:21 +08 2020  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# cm info  
Device: WP7607  
IMEI: 359779081234565  
IMEISV: 6  
FSN: VN730485080103  
[199.814275] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:1 cur:0 tx) bc(rx:0 tx:2) mode:FIFO slv\_addr:0x3a MSTR\_STS:0x0c1300c8 OPER:0x00000090  
Firmware Version: SWI9X07Y\_02.28.03.03 000000 jenki[199.831380] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:1 cur:0 tx) bc(rx:0 tx:2) mode:FIFO slv\_addr:0x3a MSTR\_STS:0x0c1300c8 OPER:0x00000090  
ns 2019/05/21 03:33:04  
Bootloader Version: SWI9X07Y\_02.28.03.03 000000 jenkins 2019/05/21 03:33:04  
MCU Version: 002.011  
PRI Part Number (PN): 9908958  
PRI Revision: 001.000  
Carrier PRI Name: GENERIC  
Carrier PRI Revision: 002.068\_000  
SKU: 1104301  
Last Reset Cause: Reset, User Requested  
Resets Count: Expected: 112 Unexpected: 5  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# cat /etc/time\_service.conf  
#TIME\_SERVICES=“qcom\_time ntpd\_time”  
TIME\_SERVICES=“ntpd\_time”  
NTPD\_SERVERS=“[pool.ntp.org](http://pool.ntp.org)”  
NTPD\_USE\_DNS\_SERVERS=“n”  
NTPD\_USE\_GATEWAY=“n”  
NTPD\_ONESHOT=“y”  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# cm data  
Index: 1  
APN: hkcsl  
PDP Type: IPV4V6  
Connected: yes  
Interface: rmnet\_data0  
Family[IPv4]: inet  
IP[IPv4]: 10.165.58.134  
Gateway[IPv4]: 10.165.58.133  
Dns1[IPv4]: 10.144.148.129  
Dns2[IPv4]: 10.144.148.5  
root@swi-mdm9x28-wp:~#  
root@swi-mdm9x28-wp:~# ping [pool.ntp.org](http://pool.ntp.org)  
PING [pool.ntp.org](http://pool.ntp.org) (81.2.248.189): 56 data bytes  
64 bytes from 81.2.248.189: seq=0 ttl=47 time=433.913 ms  
64 bytes from 81.2.248.189: seq=1 ttl=47 time=392.103 ms  
^C  
— [pool.ntp.org](http://pool.ntp.org) ping statistics —  
2 packets transmitted, 2 packets received, 0% packet loss  
round-trip min/avg/max = 392.103/413.008/433.913 ms  
root@swi-mdm9x28-wp:~#

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 6, 2020, 1:26pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/9 "2020-05-06T13:26:39Z")

</div>

Thanks, @jyijyi  
Unfortunately this doesn’t work for me. Ntpd doesn’t return any error but date also remains incorrect.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 6, 2020, 1:46pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/10 "2020-05-06T13:46:06Z")

</div>

Then probably you need to capture wireshark to investigate what happen during " /etc/init.d/ntpd\_time\_service start"

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 6, 2020, 10:53pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/11 "2020-05-06T22:53:58Z")

</div>

FYI @jyijyi  
I got the trace…  
If i am getting this correctly - server does not respond… Maybe because of incorrect configuration on client side. Request looks pretty weird. Any tips?  
[fx30\_time\_sync.pcap](https://forum.legato.io/uploads/short-url/cWRM8T3j4bkjDJtWGX9WiCEXjVP.pcap) (611 Bytes)

Update:  
It actually returns a valid date (i stopped utility too soon first time)

 ![fx30_time_sync](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/1X/3d571f46031952031f226e77d8c848b6e570da86.jpeg)  
Still… date is not updated.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 6, 2020, 11:15pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/12 "2020-05-06T23:15:25Z")

</div>

Then can you try my ntp server above?

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 6, 2020, 11:23pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/13 "2020-05-06T23:23:40Z")

</div>

it is configured to:

> [@jyijyi](#):
>
> [pool.ntp.org](http://pool.ntp.org)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 6, 2020, 11:30pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/14 "2020-05-06T23:30:41Z")

</div>

But the ip address is not the same

81.2.248.189

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 6, 2020, 11:57pm UTC](https://forum.legato.io/t/automatic-time-sync/5185/15 "2020-05-06T23:57:50Z")

</div>

Ping gives me different address, but it doesn’t matter i guess.  
a - it doesn’t work anyway.  
b - pool gives you different time server address (best for you)  
i can see correct time coming from the server, i don’t understand why system does not accept it

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 7, 2020, 12:04am UTC](https://forum.legato.io/t/automatic-time-sync/5185/16 "2020-05-07T00:04:16Z")

</div>

Can you try the qcom time?  
TIME\_SERVICES=“qcom\_time

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 7, 2020, 12:11am UTC](https://forum.legato.io/t/automatic-time-sync/5185/17 "2020-05-07T00:11:04Z")

</div>

I started with qcom\_time. In some cases it may sync time, but it’s very inconsistent. I cant rely on it.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 7, 2020, 12:20am UTC](https://forum.legato.io/t/automatic-time-sync/5185/18 "2020-05-07T00:20:27Z")

</div>

As i cannot reproduce the issue, i can only give suggestion like shutting down firewall

iptables -I INPUT -j ACCEPT

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 7, 2020, 12:39am UTC](https://forum.legato.io/t/automatic-time-sync/5185/19 "2020-05-07T00:39:39Z")

</div>

heh…  
it worked  
now i feel myself an idiot, that i didn’t try it before, haha  
Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![damir](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@damir](https://forum.legato.io/u/damir)\
**Post date:** [May 7, 2020, 1:36am UTC](https://forum.legato.io/t/automatic-time-sync/5185/20 "2020-05-07T01:36:23Z")

</div>

I accepted the solution, but it doesn’t mean i’d recommend using it (it’s terribly insecure).  
However it solves my initial issue.

> [@jyijyi](#):
>
> iptables -I INPUT -j ACCEPT
