zoukankan      html  css  js  c++  java
  • W800 蓝牙配网并使用NTP获取网络时间

    本节使用蓝牙为w800配网连接路由器,并使用NTP来获取网络时间。
    下载蓝牙配网软件:https://pan.baidu.com/s/18Wox5lCUAU29nyLhingYLw
    提取码:6666
    在主程序中建立蓝牙配网的任务:

    在任务中调用APIble_oneshot(4)配置模式为蓝牙配网:
    void ble_task(void)
    {
    u32 cnt=0;
    u32 i=0;
    struct tls_ethif *ethif;

    LED_Init();
    bt_enable(uart_1,TLS_BT_LOG_NONE);
    tls_os_time_delay(HZ);//enable之后扫描需要做一点延迟,否则会出现not ready情形
    ethif=tls_netif_get_ethif();
    init_wifi_config();//用于配置wifi相关设置如自动连接等
    printf("onshoot in progress
    ");
    ble_oneshot(4);//demo_connect_net中关于oneshoot模式
    printf("configing...");//等待配置过程中
    while(tls_wifi_get_oneshot_flag())//0 oneshot close 1 oneshotopen
    tls_os_time_delay(HZ);//当oneshot打开时延时1s
    while(1)
    {
    
    
        if(ethif->status)
    	{
    
    		ntp_updata_time();//获取ntp服务器函数,参照ntp.c demo拿取ntp服务器数据
    		tls_os_time_delay(HZ);
    		printf("更新第 %d 次time
    ",++i);
    	}
    
    	else
    	{
    		printf("press key 3s...
    ");
    		tls_os_time_delay(3*HZ);
    	}
    }
    

    }

    程序编译下载到开发板运行后使用蓝牙配网软件(WMBleWiFi)进行一键配网出现蓝牙名称为WM-*********开头的蓝牙,
    配置好wifi名字和密码即可联网。注意此时需要连接的wifi为2.4GHZ.配网成功后,无需每次上电配网,
    重启后自动联网获取ntp时间。配网完成后,串口会一直获取ntp时间。

  • 相关阅读:
    python-44-初识队列
    python-43-进程锁/信号量/事件
    python-42-Process多进程
    python-41-初识hmac与socketserver模块
    python-40-初识socket与struct
    python-39-hashlib与logging模块
    python-38-用于面向对象的内置函数
    python-37-各种反射
    python-36-封装与面向对象函数
    python-35-多态与初识封装
  • 原文地址:https://www.cnblogs.com/doiting/p/13937637.html
Copyright © 2011-2022 走看看