我试图读取使用LWIP的时间和使用STM32Cube的Nucleo-F429ZI开发板上的SNTP应用程序,以及用于LWIP的初始化方法的文档等等,但没有给出实际读取时间的方法。我猜想在后台的线程上运行了一些东西,但是没有阅读和理解LWIP堆栈,这是我无法理解的。
关于如何简单地阅读时间有什么建议吗?然后,我可以简单地存储在RTC每天一次。
发布于 2020-11-12 17:13:22
LwIP SNTP应用程序的工作方式是定期从服务器获取时间,并将其保存到用户提供的系统时间,在您的示例中是RTC。
1.要做到这一点,首先需要向SNTP应用程序提供自己的函数来设置RTC时间,这可以类似于sntp.c中的以下操作:
.
.
#include "your_rtc_driver.h"
.
.
/* Provide your function declaration */
static void sntp_set_system_time_us(u32_t t, u32_t us);
.
.
/* This is the macro that will be used by the SNTP app to set the time every time it contacts the server */
#define SNTP_SET_SYSTEM_TIME_NTP(sec, us) sntp_set_system_time_us(sec, us)
.
.
/* Provide your function definition */
static void sntp_set_system_time_us(sec, us)
{
your_rtc_driver_set_time(sec, us);
}2.现在要在应用程序中使用SNTP,请确保在lwipopts.h文件中启用以下SNTP定义,如下所示:
#define SNTP_SUPPORT 1
#define SNTP_SERVER_DNS 1
#define SNTP_UPDATE_DELAY 864003.然后在用户代码中使用:
#include "lwip/apps/sntp.h"
.
.
.
/* Configure and start the SNTP client */
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_init();
.
.
.
/* Now if you read the RTC you'll find the date and time set by the SNTP client */
read_date_time_from_rtc();就是这样,现在每个SNTP_UPDATE_DELAY ms,SNTP应用程序都将从服务器读取时间并将其保存到RTC,您需要做的就是在代码中启动SNTP应用程序并从RTC读取。
https://stackoverflow.com/questions/61932743
复制相似问题