网站开发工作好吗,网站建设陆金手指谷哥7,客户管理系统入口,昆明做网站优化评测三 蓝牙透传(单向) 有时无线透传在无法布线时有很方便的效用#xff0c;不妨试试蓝牙透传#xff0c;效果如下#xff1a;
具体是无线数据-串口数据#xff0c;串口数据-无线数据#xff0c;目前前者实现了#xff0c;后者还有些问题未解决#xff0c; 实现…评测三 蓝牙透传(单向) 有时无线透传在无法布线时有很方便的效用不妨试试蓝牙透传效果如下
具体是无线数据-串口数据串口数据-无线数据目前前者实现了后者还有些问题未解决 实现过程如下基于工程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具体配置为 服务 特征 UUID 12345678-1234-5678-56789abcdef0 12345678-1234-5678-56789abcdef1 Properties Write no response/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) \0;printf(\r\nwrite_without_rsp_vnd);return len;
}串口转无线回调有问题
static void vnd_notify(void)
{static uint8_t vnd[MAX_LONG_DATA];uint16_t len0;if (!vnd_notif_enabled)return;printf(\r\nnotify\r\n);serial_read(vnd_notify_value,len);if(lenMAX_LONG_DATA || len0)return;memcpy(vnd, vnd_notify_value, len);printf(\r\nvnd_notify\r\n);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();