Demo:smartconfig ble
Demo介绍:
该Demo使用BLE 蓝牙通讯 技术实现从手机端操控目标设备进行WIFI配网。
该Demo 保存在SDK下的:bouffalo_sdk/examples/wifi/sta/smartconfig_ble 路经下。
其中,手机 APK 放在该目录下的blsync 目录中。
主要功能分析
1. BLE 配网与同步
- 通过 BLE 广播和连接,实现手机等设备与目标设备的配对和通信。
- BLE 端通过
blsync_ble_app.c管理 BLE 广播、连接、数据同步、Wi-Fi 配网等流程。 - 支持 BLE 端发起 Wi-Fi 扫描、连接、断开、状态查询等操作,并通过 BLE 通道将结果回传给上位机或手机。
2. Wi-Fi 智能配网
- 通过 BLE 通道下发 Wi-Fi SSID、密码等信息,设备自动连接到指定的 Wi-Fi 路由器。
- 支持 Wi-Fi 扫描,获取周围可用的 Wi-Fi 列表,并通过 BLE 返回给手机端。
- 支持 Wi-Fi 连接状态、IP 地址、网关、掩码等信息的查询和回传。
另外:payload.c、transfer.c、encrypt_layer.c 等文件实现了 BLE 配网协议的数据封装、分包、加密、解密、校验、ACK 等机制,保证 BLE 通信过程中的数据完整性和安全性。
当配网正确时的输出:
[I][MAIN] Starting wifi ...
[I][MAIN] Starting fhost ...
Read slot:0
get sta mac: b4:0e:cf:2e:90:fb
Read slot:0
get ap mac: b4:0e:cf:2e:90:fb
fhost_cntrl_start:3489
fhost_cntrl_start:3492
[I][MAIN] [APP] [EVT] wifi_event_handler, CODE_WIFI_ON_INIT_DONE
wifi_mgmr_set_country_code:code = CN, channel24G_num:13, channel5G_num:0
[I][MAIN] [APP] [EVT] wifi_event_handler, CODE_WIFI_ON_MGMR_DONE
SIGTERM is NOT supported yet!
SIGHUP is NOT supported yet!
blsync_connected
Exchange mtu size pending.
Exchange successful //代表蓝牙连接成功
event type 0, id 9
Recevied indication to wifi scan
...........
=================================================================
[I][MAIN] [APP] [EVT] wifi_event_handler, CODE_WIFI_ON_CONNECTED
========================== Keyram Config ========================
start 08 -->> end 11; nVAP 02; max 31
========================== Keyram Dump =========================
[id] MAC Address Key Len VLan ID Default Key Hexdump(16Bytes MAX)
[00] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[01] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[02] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[03] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[04] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[05] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[06] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[07] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[08] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[09] 58:41:20:A8:4F:FC 64-Bit 01 1 00000000 00000000 00000000 00000000
[10] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
[11] FF:FF:FF:FF:FF:FF 64-Bit 00 0 00000000 00000000 00000000 00000000
========================== MAC Address =========================
MAC B4:0E:CF:2E:90:FB Mask 00:00:00:00:00:00
BSSID 58:41:20:A8:4F:FC Mask 00:00:00:00:00:00
start dhcping ...
wpa_supplicant_ctrl_iface_msg_cb: cmd send succeded, txt is State### ASSOCIATED -> COMPLETED
[WPA] CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
event type 0, id 13
Recevied indication to wifi state get
Connected
APK操作:
注意保证你的WIFI是打开的,点击对应设备 blsync 进行连接。
进入后连接成功的界面:
点击扫描配网后: