相較于WiFi技術,低功耗藍牙BLE技術具有搜索連接速度快、超低功耗等特點,BLE搭配mesh技術所延伸的藍牙mesh技術因其支持多點對多點連接、物理覆蓋區域廣闊,也被廣泛用于智能家居中控、智能安防、智慧樓宇等物聯網設備上。
XR806是一款支持BLE 5.0、支持完整低功耗藍牙服務GATT、支持SIG mesh完整協議棧的無線芯片,同樣適配物聯網設備的使用場景需求,在通過官方文檔的指引下配置好XR806的RTOS環境后,可按文章介紹步驟進行后續的藍牙mesh互傳及藍牙單向穿透的功能測試。
藍牙mesh互傳
最新的藍牙mesh1.1引入了定向轉發路由功能,擴大射頻覆蓋范圍,使信號一級級中繼下去,手頭有nRF52840開發板,不妨和全志XR806進行組網,測試兼容性和互操作性,也驗證XR806 mesh協議棧的完成度。先看效果:

nRF52840用Segger Embedded Studio打開工程:
nrf5SDKforMeshv320srcexampleslight_switchserver
同時燒錄協議棧和APP;XR806為觀察到現象,將mesh例程的收到mesh opcode的回調接口加個指示信號,具體為:
static void gpio_output_init(void) { GPIO_InitParam param; param.driving = GPIO_DRIVING_LEVEL_1; param.mode = GPIOx_Pn_F1_OUTPUT; param.pull = GPIO_PULL_NONE; HAL_GPIO_Init(GPIO_OUTPUT_PORT, GPIO_OUTPUT_PIN, ¶m);//PA21 } /***************Onoff Configuration Declaration*******************/ static void app_onoff_srv_set_cb(const struct bt_mesh_model *model, uint8_t onoff, uint8_t target_onoff, const struct bt_mesh_transition_status *opt) { g_onoff_value = onoff; HAL_GPIO_WritePin(GPIO_OUTPUT_PORT, GPIO_OUTPUT_PIN, onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); printf("[app] onoff set(%d)", onoff); if (opt) { printf("target onoff(%d), total_steps(%d), steps(%d)", target_onoff, opt->total_steps, opt->present_steps); } printf(" "); }
編譯完后將mesh_demo燒錄進XR806中,將XR806的GenericOnOff Server訂閱到publisher的發布地址,就能實現同一網絡(具備同一網絡密鑰可以正確解析出mesh消息)內的消息傳遞。
此時用nRF Mesh去給nRF52840和XR806分別入網和設置訂閱地址,本次將他們訂閱到0xC000。

由于入網過程沒有錄制下來,且XR806無法退網,且入網信息暫時沒找到擦除方法,這樣重新燒錄還是保持入網狀態而無法回到unprovisioned狀態。
nRF52840接到JlinkRTT Viewer,XR806接到putty,可以看到XR806的Controller/host協議棧的版本信息,手機發布一條開關(由GernericOnOff元素統屬)消息,泛洪給兩臺射頻設備,可以在各自控制臺看到都有收到set opcode網絡消息。

藍牙穿透(單向)
有時無線透傳在無法布線時有很方便的效用,不妨試試藍牙透傳,效果如下:

具體是無線數據->串口數據,串口數據->無線數據,目前前者實現了,后者還有些問題未解決,

實現過程如下,基于工程:
demo/Bluetooth/peripheral_demo改成peripheral_uart_demo
同時目錄下文件里工程名也進行修改:
peripheral_uart_demo/gcc/defconfig改成peripheral_uart_demo
然后引入串口讀寫獨立接口即把demo/at_demo下的serial.c、serial.h、serial_debug.h復制到剛才peripheral_uart_demo工程下,由于要無線寫以及串口寫轉無線,所以profile涉及到write_without_rsp和notify,具體配置為:
static struct bt_gatt_attr vnd_attrs[] = {
/* Vendor Primary Service Declaration */
BT_GATT_PRIMARY_SERVICE(&vnd_uuid),
BT_GATT_CHARACTERISTIC(&vnd_enc_uuid.uuid,
BT_GATT_CHRC_WRITE_WITHOUT_RESP | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_WRITE,
NULL, write_without_rsp_vnd, &vnd_value),
BT_GATT_CCC(vnd_ccc_notify_changed, BT_GATT_PERM_READ|BT_GATT_PERM_WRITE),
};
寫回調接口為:
/**********************vnd_write_cmd_uuid*****************************/
static ssize_t write_without_rsp_vnd(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
uint8_t *value = attr->user_data;
/* Write request received. Reject it since this char only accepts
* Write Commands.
*/
if (!(flags & BT_GATT_WRITE_FLAG_CMD)) {
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
}
if (offset + len > sizeof(vnd_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}
memset(value, 0, sizeof(vnd_value));
memcpy(value + offset, buf, len);
serial_write(value + offset, len);
*(value + offset + len) = '?';
printf("
write_without_rsp_vnd");
return len;
}
串口轉無線回調(有問題):
static void vnd_notify(void)
{
static uint8_t vnd[MAX_LONG_DATA];
uint16_t len=0;
if (!vnd_notif_enabled)
return;
printf("
notify
");
serial_read(vnd_notify_value,len);
if(len>MAX_LONG_DATA || len==0)
return;
memcpy(vnd, vnd_notify_value, len);
printf("
vnd_notify
");
bt_gatt_notify(NULL, &vnd_svc.attrs[1], vnd, sizeof(vnd));
}
然后在bt_app_init函數里加入透傳口UART1的初始化代碼即可:
serial_init(SERIAL_UART_ID, 115200, UART_DATA_BITS_8, UART_PARITY_NONE, UART_STOP_BITS_1, 0); serial_start();
審核編輯:湯梓紅
-
藍牙
+關注
關注
119文章
6312瀏覽量
178685 -
物聯網
+關注
關注
2945文章
47818瀏覽量
414797 -
WIFI
+關注
關注
82文章
5509瀏覽量
213508 -
Mesh
+關注
關注
5文章
230瀏覽量
31337 -
無線芯片
+關注
關注
2文章
87瀏覽量
24778
原文標題:物聯網設備人柱力,XR806藍牙mesh互傳及單向穿透功能測試
文章出處:【微信號:gh_79acfa3aa3e3,微信公眾號:全志在線】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
藍牙mesh互傳及藍牙單向穿透的功能測試
評論