2020-05-20 08:37 AM
I am looking in to implimenting a SNTP client on an embedded board, I am using the STM32CubeIDE so its a checkbox to enable SNTP, but I can find no documentation or examples on what you do from there.
I can see functions to enable/disable SNTP, but not to read anything or write anything....
Does anyone have some pointers about what/how it works? or even an example?
I have hunted the web, lots say how easy it is, just look at RFC4330 (which I have) etc, but I can only presume I am missing something completely.
2022-06-24 06:13 AM
yes please.
2022-06-24 06:25 AM
This one uses the RTC : https://blog.csdn.net/hxj0323/article/details/108304576
And this one uses some tcp echo server : https://blog.csdn.net/zhanglifu3601881/article/details/90145016
Hope you can find a lead !
2023-06-01 06:19 AM
Edited:
Is this still open ?
Please guide me to get more info or a straight forward example.
Thanks in advance.
2023-06-01 10:40 AM
2023-06-08 07:41 AM
Hi all,
First of all thanks to all of you and a big one to @Piranha. I am able to make it work.
But still I have issues.
I am able to get correct MM:SS and Month.
HH and Date I adjusted.
Year not able to fix.
See below,
/**
* @brief set time from STNP
*/
void ethernet_task_SetTimestamp(uint32_t seconds, uint32_t fractional)
{
ethernet_task_timestamp = seconds;
ethernet_task_timestampValid = 1;
ethernet_task_timestampOffset = HAL_GetTick();
ethernet_task_timestampms = 1000 * (uint64_t)seconds + fractional / 4294967;
ethernet_task_timestampCount++;
common_TimeDateClass timeDate;
time_t unixTimestamp = (time_t)(ethernet_task_timestampms / 1000);
struct tm* timeinfo = gmtime(&unixTimestamp); // or localtime(&unixTimestamp) for local time
timeDate.date.year = timeinfo->tm_year + 1900; // Years since 1900
timeDate.date.month = static_cast<common_DateMonthEnum>(timeinfo->tm_mon + 1); // Months since January (0-11)
timeDate.date.date = timeinfo->tm_mday + 1; // Day of the month (1-31)
timeDate.time.hour = timeinfo->tm_hour + 1; // Hours since midnight (0-23)
timeDate.time.minute = timeinfo->tm_min; // Minutes after the hour (0-59)
timeDate.time.second = timeinfo->tm_sec; // Seconds after the minute (0-61)
commonAPI_SetTime_SNTP(&timeDate.time); // RTC write time
commonAPI_SetDate_SNTP(&timeDate.date); // RTC write date
}
above is my
SNTP_SET_SYSTEM_TIME_NTP()
function. But it has following adjustments.
timeDate.date.year = timeinfo->tm_year + 1900; // Years since 1900
timeDate.date.date = timeinfo->tm_mday + 1; // Day of the month (1-31)
timeDate.time.hour = timeinfo->tm_hour + 1; // Hours since midnight (0-23)
As I mentioned already, for 'date' and 'HH' I added addtional value '1' to the orginal value. and for year I am getting '2065' for '2023'.
Kindly advice what am doing wrong.
Thanks in advance.