sntp(Simple Network Time Protocol)是一种网络时间协议,它是NTP(Network Time Protocol)的一个简化版本。
本项目是从LwIP中抽取的SNTP代码;
`Hi3861 SDK`中已经包含了一份预编译的lwip,但没有开启SNTP功能(静态库无法修改);
需要保证模块连接的热点能够访问网络的。
修改网络参数
在Hi3861开发板上运行上述四个测试程序之前,需要根据你的无线路由、Linux系统IP修改 net_params.h文件的相关代码:
- PARAM_HOTSPOT_SSID 修改为你的热点名称
- PARAM_HOTSPOT_PSK 修改为你的热点密码;
可能需要修改校时服务器的ip地址,修改如下代码
void SntpSetServers(void)
{
IP4_ADDR(&g_ntpServerList[0], 223, 113, 97, 98); // cn.ntp.org.cn
IP4_ADDR(&g_ntpServerList[1], 114, 118, 7, 163); // ntp.ntsc.ac.cn
IP4_ADDR(&g_ntpServerList[2], 120, 25, 108, 11); // time.pool.aliyun.com
IP4_ADDR(&g_ntpServerList[3], 119, 28, 206, 193); // cn.pool.ntp.org
for (size_t i = 0; i < SNTP_SERVERS; i++) {
sntp_setserver(i, (ip_addr_t*)&g_ntpServerList[i]);
}
}
方法就是用ping网址,通过返回的消息查看ip地址
代码编写
修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件
# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
lite_component("demo") {
features = [
#"base_00_helloworld:base_helloworld_example",
#"base_01_led:base_led_example",
#"base_02_loopkey:base_loopkey_example",
#"base_03_irqkey:base_irqkey_example",
#"base_04_adc:base_adc_example",
#"base_05_pwm:base_pw