Hi
I'm making a program to connect iPhone apps
I'm using the ncs zephyr
This is the part, I made the cords
static struct bt_conn *my_connection;
tatic ssize_t on_receive(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf,
uint16_t len,
uint16_t offset,
uint8_t flags);
void on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value);
BT_GATT_SERVICE_DEFINE(my_service,
BT_GATT_PRIMARY_SERVICE(BT_UUID_MY_SERVICE),
BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERVICE_RX,
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
NULL, on_receive, NULL),
BT_GATT_CCC(on_cccd_changed,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERVICE_TX,
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ,
NULL, NULL, NULL),
BT_GATT_CCC(on_cccd_changed,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
);
void on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value)
{
ARG_UNUSED(attr);
printk("Error, CCCD has been set to an invalid value");
switch(value)
{
case BT_GATT_CCC_NOTIFY:
// Start sending stuff!
if (my_connection) {
on_receive(my_connection, attr, NULL, 0, 0, 0);
}
break;
case BT_GATT_CCC_INDICATE:
// Start sending stuff via indications
if (my_connection) {
on_receive(my_connection, attr, NULL, 0, 0, 0);
}
break;
case 0:
// Stop sending stuff
break;
default:
printk("Error, CCCD has been set to an invalid value");
}
}
static ssize_t on_receive(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf,
uint16_t len,
uint16_t offset,
uint8_t flags)
{
const uint8_t * p_buff = buf;
return len;
}
static void connected(struct bt_conn *conn, uint8_t err) {
char addr[BT_ADDR_LE_STR_LEN];
// struct bt_conn_info info;
my_connection = conn;
BLE.conn_flag = true;
}
static void disconnected(struct bt_conn *conn, uint8_t reason) {
char addr[BT_ADDR_LE_STR_LEN];
// bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected (reason %u)\n", reason);
if (my_connection != conn) {
return;
}
}static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.le_param_req = NULL,
.le_param_updated = NULL
};
void main(void)
{
err = bt_enable(NULL);
if (err) {
// printk("Bluetooth init failed (err %d)\n", err);
return;
bt_conn_cb_register(&conn_callbacks);
}
I am connecting using iPhone app and connected function is debugged
However, the on_receive function receiving the data is not debugged
As far as I know, it goes to the on_receive function through the on_ccd_changed function, so please check if my code is correct!
However, the on_receive function receiving the data is not debugged
As far as I know, it goes to the on_receive function through the on_ccd_changed function, so please check if my code is correct!