LWIP and SNTP
Hi,
I am looking at:
STM32Cube_FW_H7_V1.7.0\Middlewares\Third_Party\LwIP\src\apps\sntp
How is it supposed to be used ?
What I did:
void SNTP_Thread(void const *arg)
{
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setserver(0, &sntp_addr);
printh(" (%d) %s: Server: %s (%u.%u.%u.%u)\r\n",
__LINE__,
__FUNCTION__,
SNTP_SERVER,
((u8_t *)&sntp_addr.addr)[0],
((u8_t *)&sntp_addr.addr)[1],
((u8_t *)&sntp_addr.addr)[2],
((u8_t *)&sntp_addr.addr)[3]);
while (1) {
sntp_init();
if (sntp_rxts() == 1) {
sntp_time(&tim); /* get seconds to time_t tim */
printh(" (%d) %s: SNTP ctime: %s\r",
__LINE__,
__FUNCTION__,
ctime(&tim));
}
}
}Modified sntp.c, to add the following:
extern time_t tim;
volatile int ts_status;
time_t sntp_time(time_t *t)
{
*t = tim;
return tim;
}
int sntp_rxts(void)
{
return ts_status;
}and
void sntp_init(void)
{
ts_status = 0;
..
}Modified sntp_opts.h to reflect a changed SNTP_UPDATE_DELAY to 30s
/** SNTP update delay - in milliseconds
* Default is 1 hour. Must not be beolw 15 seconds by specification (i.e. 15000)
*/
#if !defined SNTP_UPDATE_DELAY || defined __DOXYGEN__
#define SNTP_UPDATE_DELAY 30000 //3600000
#endifThe results that I do get:
SNTP Server : pool.ntp.org (162.159.200.1)
(1050) print_dhcp_state: Lookup Success!
(1081) SNTP_Thread: Server: pool.ntp.org (162.159.200.1)
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:31:42 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:31:54 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:32:13 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:33:16 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:33:46 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:34:46 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:35:45 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:36:03 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:36:55 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:37:13 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:37:26 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:37:45 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:38:17 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:38:56 2020
(1106) SNTP_Thread: SNTP ctime: Mon Jul 20 08:39:16 2020The deviation in between updates seem to be too wide.
I guess something is wrong ? The way I am using it, probably ?
Can someone comment, please ?
Thanks,
Manu
