CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

NIST Daytime Protocol
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

NIST Daytime Protocol
PostPosted: Sat Jun 23, 2012 9:08 pm     Reply with quote

I'm looking for some example code for reading the Daytime string from one of the NIST servers. I will be using the CCS (Microchip) TCP/IP stack. I understand the string format is variable by server and will figure that out later. Right now, I just need to send a command and get the string back from a specific server.

Any leads would be appreciated. Thanks
_________________
Al Testani
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 24, 2012 5:41 am     Reply with quote

Google found a few hits for me....the trick is to enter in keywords like nist time rfc....the 3rd or 4th hit had code that could be used.
Please don't ask for a link...I did this 10 minutes ago...and was only interested in the quest.
I only care what day of the week it is, not how many microseconds past the hour !
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Sun Jun 24, 2012 8:23 am     Reply with quote

temtronic wrote:
Google found a few hits for me....the trick is to enter in keywords like nist time rfc....the 3rd or 4th hit had code that could be used.
Please don't ask for a link...I did this 10 minutes ago...and was only interested in the quest.
I only care what day of the week it is, not how many microseconds past the hour !


Thanks for the lesson on how to use Google and for taking the time to type in all the lines of your post instead of a simple link.

I never post to this forum without having done searching in general and on the CCS forums specifically (including the code library). I had already done a significant amount of searching and when I put in your search words, I found that I had already visited most of the links in the list and none had any useful code. There is PHP code and PC code (based on frameworks such as .NET, Delphi VCL, etc.) but none specific to PIC's.

Hopefully someone will reply to my post with some useful information.
_________________
Al Testani
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 24, 2012 9:55 am     Reply with quote

I had assumed you wanted the 'NIST server side' of the code (commands to access the server date/time etc.) as opposed to PIC based software to access the net.
It should be easy to translate the code from say Delphi into CCS C code assuming you've already got the PIC to access the net.
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Sun Jun 24, 2012 10:11 am     Reply with quote

temtronic wrote:
I had assumed you wanted the 'NIST server side' of the code( commands to access the server date/time etc.) as opposed to PIC based software to access the net.
It should be easy to translate the code from say Delphi into CCS C code assuming you've already got the PIC to access the net.


I should have been more specific on my application. I need to transmit weather data to PHP scripts at Weather Underground and another website I created and wrote the PHP code for. The request string to be sent must include the UTC time. So a PIC queries the weather station for data, gets the UTC time from an NIST server (instead of using onboard RTC hardware), and formats and sends the requests to the two servers with the PHP scripts.

I can easily do this from a PC using Delphi 2010 and the supplied INDY components, for example, but need to do it from a PIC. I have a CCS Embedded Internet Kit on the way to use as a platform for this. I have been studying the stack code, examples, and manual, and am looking for an example on the NIST code since one doesn't exist.

I think I see how to conceptually do it using TCP or UDP on port 13 but don't get what the contents of the datagram sent to one of the NIST servers is or the timeouts, etc. involved. That's why I was looking for some sample code.

Thanks
_________________
Al Testani
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Jun 24, 2012 11:56 pm     Reply with quote

The microchip application library's TCPIP stack has library code to do what you want for SNTP.

The name of the file is SNMP.C

Consider downloading the MAL. It's free from MCHP's website.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jun 25, 2012 1:31 am     Reply with quote

It's SNTP.C
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Mon Jun 25, 2012 8:32 am     Reply with quote

bkamen wrote:
The microchip application library's TCPIP stack has library code to do what you want for SNTP.

The name of the file is SNMP.C

Consider downloading the MAL. It's free from MCHP's website.

-Ben


FvM wrote:
It's SNTP.C


Thanks for the leads

I have the MAL and there is no example SNTP.c. Searching thru the files in the TCPIP folder for the text "SNTP", I do find an example of getting a timestamp from an NTP server. I could use this if it is all that is available but there are two issues. It is written in other than CCS C and also is SNTP whereas I want to use the much simpler DAYTIME protocol implemented on the NIST servers.

I finally found some code (C#) that shows the method to do this and it is dirt simple. You basically only need to open a connection to the NIST server and it returns 51 bytes of day & time information as ASCII.

Here is the C# code snippet:

Code:
using (Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) {
                    IPEndPoint hostEndPoint = new IPEndPoint (timeServerIpAddress, 13);

                    stopWatch.Reset ();
                    stopWatch.Start ();
                    socket.Connect (hostEndPoint);
                    int numberOfBytes = socket.Receive (buffer);
                    stopWatch.Stop ();

                    if (numberOfBytes == 51) {
                        roundTripTime = stopWatch.Elapsed;
                        string daytimeString = System.Text.ASCIIEncoding.ASCII.GetString (buffer, 0, numberOfBytes).Trim ();
                        return daytimeString;

What you get back is in the form:
56103 12-06-25 14:28:06 50 1 0 209.9 UTC(NIST) *
or
JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM.

There are many descriptions of the above coding available such as:
http://www.nist.gov/pml/div688/grp40/its.cfm
_________________
Al Testani
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Jun 25, 2012 8:48 am     Reply with quote

Only 'caveat' (shouldn't apply if the calls are infrequent), is that some of the servers will start to block you if you call very often. Typically the 'nominal' limit is perhaps 1/hour, but most don't do anything unless you make a lot more calls. If this is something that is itself interrogated, and the frequency is variable, and might go much higher, then 'beware'.
Obvious solution, especially given the need to have multiple servers in case one fails, is to 'walk' a list of servers, so calls to each one are fairly infrequent.

Best Wishes
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Mon Jun 25, 2012 9:10 am     Reply with quote

Ttelmah wrote:
Only 'caveat' (shouldn't apply if the calls are infrequent), is that some of the servers will start to block you if you call very often.


Thanks, good point. I have already seen the block with some Delphi code I wrote to try to understand this. (Didn't learn much since the code is encapsulated in a component). I have read that the minimum time between requests can be as little as 4 seconds. My cycle time is 10 seconds and I will only get an NIST update every few minutes or so and use the stack's timing system to "keep time" during the interval.
_________________
Al Testani
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jun 26, 2012 12:22 am     Reply with quote

FvM wrote:
It's SNTP.C


Oops. my bad. I'm so used to typing SNMP, I autopiloted that one.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jun 26, 2012 12:25 am     Reply with quote

ajt wrote:


I have the MAL and there is no example SNTP.c.


It's not a demo. It's a library file in \path-to-App-Lib\Microchip\tcpip stack\sntp.c

Don't search for a word in the file... search for a FILE called SNTP.C


-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Tue Jun 26, 2012 8:31 am     Reply with quote

bkamen wrote:


It's not a demo. It's a library file in \path-to-App-Lib\Microchip\tcpip stack\sntp.c

Don't search for a word in the file... search for a FILE called SNTP.C


-Ben


I had done the search for the file but not in the TCPIP Stack folder. That is why I used a keyword search. I have found it now... thanks.
_________________
Al Testani
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jun 26, 2012 10:53 pm     Reply with quote

don't forget to change the subject of your initial post to include "[SOLVED]" to help others...

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jun 26, 2012 11:27 pm     Reply with quote

Quote:
I want to use the much simpler DAYTIME protocol implemented on the NIST servers.

I doubt that it's simpler at all. DAYTIME (RFC 867) is first of all legacy and the lack of a defined syntax is reason enough to avoid it. Everyone is using SNTP (RFC 1305) these days. The basic implementation doesn't involve more than UDP port open and the states UDP_SEND, UDP_RECEIVE and wait for intervall expiration. By reading binary numbers directly, you save a lot of sscanf() string decoding effort.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group