AWTK 的低功耗蓝牙 (BLE) 插件

   日期:2021-02-17     浏览:178    评论:0    
核心提示:BLEAWTK 的低功耗蓝牙 (BLE) 插件包含头文件#include "ble/ble.h"调用方法创建 ble 对象。如: ble_t* ble = ble_create();扫描设备扫描前先要注册 on_device_found 回调函数,每扫描到一个设备就会调用该回调函数。static ret_t ble_main_on_device_found(void* ctx, ble_device_t* device) { ... return

BLE

AWTK 的低功耗蓝牙 (BLE) 插件

包含头文件

#include "ble/ble.h"

调用方法

    1. 创建 ble 对象。

如:

  ble_t* ble = ble_create();
    1. 扫描设备

扫描前先要注册 on_device_found 回调函数,每扫描到一个设备就会调用该回调函数。

static ret_t ble_main_on_device_found(void* ctx, ble_device_t* device) { 
  ...
  return RET_OK;
}

ble_set_on_device_found(ble, ble_main_on_device_found, win);
  ble_start_scan(ble);
    1. 连接设备

当 on_device_services_discovered 被调用时,设备才真正连接,之后才能收发数据。

注册回调函数:

static ret_t ble_deivce_on_device_services_discovered(void* ctx, ble_device_t* device) { 

  return RET_OK;
}

ble_set_on_device_services_discovered(device->ble, ble_deivce_on_device_services_discovered, win);
  ble_connect_to(ble, address);
    1. 收发数据。

收发数据是异步的,先注册相应的回调函数,再收发数据。


  ble_set_on_characteristic_write(device->ble, ble_on_characteristic_write, win);
  ble_set_on_characteristic_read(device->ble, ble_on_characteristic_read, win);
  ble_read_characteristic(device->ble, device->id, achar->id);
  ble_write_characteristic(device->ble, device->id, achar->id, data, FALSE);
    1. 主动上报的数据

注册 on_characteristic_changed 即可。

  ble_set_on_characteristic_changed(device->ble, ble_on_characteristic_changed, win);

完整示例请参考 demo。

API

BLE API

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服