Telit Cinterion IoT Developer Community
NTP - How to use net time protocol on J2ME
Showcase, February 18, 2015 - 10:43am, 5061 views
Attached an example how to get the time form a NTP server.
Find source attached, comments are included.
If you want to run the code please modify the APN in regards to the used SIM/MNO
sntpclient.setApn("apn of your mobile operator"); (IMlet.java - line 22)
If needed setters for username and password are available in the SntpClient.java object as well.
Log file of the debug session:
Registering ip address "192.168.244.1" of remote debugging device...
Waiting for debug device registration of "IMP_NG_EHS5_REMOTE"...
Passing control to external device emulator...
Installing suite from: http://192.168.244.2:51968/NTPExample.jad
Connection state: CONNECTING
Connection state: UP
HTTP response: Found
datagram://185.8.237.27:123;dns=0.0.0.0;bearer_type=gprs;access_point=internet.cxn;
NTP request sent, waiting for response...
NTP server: 185.8.237.27
Leap indicator: 0
Version: 3
Mode: 4
Stratum: 3
Poll: 3
Precision: -22
Root delay: 5.8746337890625 ms
Root dispersion: 66.4520263671875 ms
Reference identifier: 46.243.48.4
Reference timestamp: Wed Feb 18 07:35:48 GMT+00:00 2015, fraction 0.8753509521484375
Originate timestamp: Thu Jan 08 21:17:09 GMT+00:00 2004, fraction 0.694000244140625
Receive timestamp: Wed Feb 18 08:08:37 GMT+00:00 2015, fraction 0.010018348693847656
Transmit timestamp: Wed Feb 18 08:08:37 GMT+00:00 2015, fraction 0.010127067565917969
Dest. timestamp: Thu Jan 08 21:17:10 GMT+00:00 2004, fraction 0.21899986267089844
Round-trip delay: 524.8908996582031 ms
Local clock offset: 3.5065028705357263E11 ms
Local time 3.50650287E8sec late
97402h 51m 27s
End of debug session. Emulator is closed!
Hello!
Thank you for this code.
A little remark: I think it is better not to use additional parameters (dns, bearer,access_point) in the string "datagram://" + serverName + ":123"....
because these parameters are not described for UDPDatagramConnection interface.
Using these additional parameters caused haning my midlet (EHS5 module)..