Using RT-Thread Studio DIY mini desktop clock (three) | get NTP time (at_device package + netutils package)

1. Project Schedule

Mini Desktop clock project to demonstrate how to use the RT-Thread Stduio development project, the entire project structure is as follows:

In a previous blog post brief introduction to the RT-Thread Studio one-stop tool based on this chip STM32L431RCT6 create a project, and modify the clock to an external clock.

Using RT-Thread Studio DIY mini desktop clock (a) | STM32 chip is based on creating a project
to obtain temperature and humidity sensor data (I2C device driver package + SHT3x) | using RT-Thread Studio DIY mini desktop clock (B)

Took over we start adding at_device equipment ESP8266, add a package to acquire NTP time.

2. Add ESP8266 Device Drivers

2.1. Enabling libc components

Before using at_device package, you need to open the libc components:

2.2. Adding at_device package

It is used in this project ESP8266 device based on the driving example code provided in the frame AT at_device package.

Click the Add Packages button, search at_device, add the package:

added to the project after the set, right-click access to the package configuration page:

configure the actual message:

save the device, the software will automatically add at_device package to the project.

2.3. Turn lpuart1 serial devices

In the previous section, when the configuration package, serial device provided for lpuart1, but there is no device in the system lpuart1, need to manually board.hopen the file, the opening of the method has been described in the comment file, as shown:

按照图中注释的说明,首先添加使用lpuart1的宏定义,开启串口:

接下来修改具体lpuart1串口的引脚配置:

接下来为了后续方便操作控制台,将sht3x的测试线程先注释掉:

然后编译整个项目,下载,查看串口输出:

可以看到有一个警告,提示 RT_SERIAL_RB_BUFSZ 的值不够用了,解决方案就是在那设置中加大该缓冲区的值:

重新编译,下载,在串口控制台中查看网络是否成功配置:

两条串口日志打印暂且没有影响,是因为使用lpuart的原因,如果换为使用普通uart,在完全相同的配置下,没有这两条信息。

2.4. 测试网络

再进行进一步的测试,确保网络正常能连接外网:

ifconfig		//使用该命令查看当前网卡配置
ping www.baidu.com	//使用该命令测试外网是否可以ping通

测试结果如下:

3. 添加NTP对时功能

3.1. 添加netutils工具软件包

netutils软件包中汇集了 RT-Thread 可用的全部网络小工具集合,包括NTP工具。

NTP 是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机时间的协议,RT-Thread 上的 NTP 客户端连接上网络后,可以获取当前 UTC 时间,并更新至 RTC 中。

打开配置文件,添加软件包,搜索NTP之后添加:

右击软件包,修改该软件包的配置:

开启NTP服务器配置即可:

3.2. 开启软件模拟RTC

因为NTP工具在获取到网络时间后,需要同步到本地RTC,所以需要开启本地模拟RTC功能:

开启之后保存配置,重新编译工程,下载,在串口控制台查看是否可以正常工作。

3.3. 测试NTP工作是否正常


接收更多精彩文章及资源推送,欢迎订阅我的微信公众号:『mculover666』。

发布了217 篇原创文章 · 获赞 575 · 访问量 25万+

Guess you like

Origin blog.csdn.net/Mculover666/article/details/104418075