一、BLE开发包支持
瑞芯微SDK开发包中buildroot配置bluez5:
Target packages --->
Networking applications --->
Target packages --->
rockchip BSP packages --->
rkwifibt --->
二、使用gatt服务实现WIFI配网
蓝牙BLE基于GATT协议传输数据,提供了Serivice和Characteristic进行设备之间的通讯。
蓝牙里面有多个Service,一个Service里面又包括多个Characteristic,使用UUID来区分每个服务,如下图所示:
GATT可以配置为如下两种角色(Role):
- Client : 命令、请求发起方
- Server : 命令、请求接收方
如手机为客服端,语音开发板为服务端,手机端主动向语音开发板发起BLE连接请求。
- Gatt服务的Demo程序
demo程序:bluez-5.50/tools/gatt-service.c
2、添加WIFI配网服务
定义WIFI服务uuid和对应的特征值uuid
/* Immediate wifi Service UUID */
#define WIFI_SERVICES_UUID "1B7E8251-2877-41C3-B46E-CF057C562023"
#define SECURITY_UUID "CAC2ABA4-EDBB-4C4A-BBAF-0A84A5CD93A1"
#define SSID_UUID "ACA0EF7C-EEAA-48AD-9508-19A6CEF6B356"
#define PASSWORD_UUID "40B7DE33-93E4-4C8B-A876-D833B415A6CE"
#define CONFIG_NOTIFY_UUID "8AC32D3f-5CB9-4D44-BEC2-EE689169F626"
#define CONFIG_UUID "00002902-0000-1000-8000-00805f9b34fb"
创建和注册该服务:
int main(int argc, char *argv[])
{
GDBusClient *client;
guint signal;
signal = setup_signalfd();
if (signal == 0)
return -errno;
connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
main_loop = g_main_loop_new(NULL, FALSE);
g_dbus_attach_object_manager(connection);
printf("gatt-service unique name: %s\n",
dbus_bus_get_unique_name(connection));
//create_services_one();
//create_services_two();
//create_services_three();
create_wifi_services();
client = g_dbus_client_new(connection, "org.bluez", "/");
g_dbus_client_set_proxy_handlers(client, proxy_added_cb, NULL, NULL,
NULL);
g_main_loop_run(main_loop);
g_dbus_client_unref(client);
g_source_remove(signal);
g_slist_fr