WLAN - How to NTP time Server

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

WLAN - How to NTP time Server

Post by Jordy101091 »

HI all,

Since I have solved together with the matrix team my problem to get my wiz610wi to work, I was wondering for my next step to use a NTP server to provide the time and date for my system.
My question is how do I connect to a NTP time server and how do I receive the correct information.

Regard, Jordy
the will to learn, should not be stopped by any price

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: WLAN - How to NTP time Server

Post by Steve001 »

HI Jordy

I am not at home at the moment have a look on Microsoft site there is quite a bit of info on how to use there time server

Think the address it time.Microsoft.com

Or look for Kb262680

Steve
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: WLAN - How to NTP time Server

Post by Steve001 »

Hi Jordy,

Here is some example code from microchip forums

#include <time.h>

void RtcWriteTime(time_t t){
// write t (seconds since 1970) to rtc
UINT8 buf[7];
struct tm *pTimeStruct; // pointer to where to build rtc values
pTimeStruct=localtime(&t); // fill the structure with t values
buf[0]=DecByteToSwappedBcd(pTimeStruct->tm_year-100); // save year converting 2000 (saved as 100) to 0
buf[1]=DecByteToSwappedBcd(pTimeStruct->tm_mon+1); // save month converting 0..11 to 1..12
buf[2]=DecByteToSwappedBcd(pTimeStruct->tm_mday); // save day of month
buf[3]=DecByteToSwappedBcd(pTimeStruct->tm_wday); // save day of week (0-6)
buf[4]=DecByteToSwappedBcd(pTimeStruct->tm_hour); // save hour of day
buf[5]=DecByteToSwappedBcd(pTimeStruct->tm_min); // save minute
buf[6]=DecByteToSwappedBcd(pTimeStruct->tm_sec); // save seconds
RtcWriteCommand(2,buf,7);
}

time_t RtcReadTime(void){
// reads the time from the RTC and converts it to a time_t (seconds since 1970).
//struct tm TimeStruct; // put rtc values here
struct tm TimeStruct; // Build time here
UINT8 buf[7]; // get 7 bytes of rtc data here
time_t result;
RtcReadCommand(2,buf,7); // send rtc command 2 and read back 7 bytes
TimeStruct.tm_sec=SwappedBcdToDec(buf[6]); // set seconds
TimeStruct.tm_min=SwappedBcdToDec(buf[5]); // minutes
TimeStruct.tm_hour=SwappedBcdToDec(0xfc & buf[4]); // hours - mask out am/pm and undefined bit
TimeStruct.tm_mday=SwappedBcdToDec(buf[2]); // day of month
TimeStruct.tm_mon=SwappedBcdToDec(buf[1])-1; // month (convert 1-12 in rtc to 0-11 in TimeStruct)
TimeStruct.tm_year=SwappedBcdToDec(buf[0])+100; // convert years since 2000 in rtc to years since 1900 in TimeStruct
TimeStruct.tm_yday=0; // not used, but make valid
TimeStruct.tm_isdst=0;
TimeStruct.tm_zone=0;
result=mktime(&TimeStruct); // convert to time_t (seconds since 1970)
return(result);
}


forum post is here

I havent had chance to have a go with this code , it's on this of things to do :lol:

http://www.microchip.com/forums/m483869-print.asp

steve
Success always occurs in private and failure in full view.

Post Reply