Hello,
I would like to implement beacon feature with a periodic (each 10s) advertisement data update.
This is an extrapolation of my code:
uint8_t d[4] = {0x18 , 0x1a, 0x32, 0x32};
struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x18, 0x1a),
BT_DATA_BYTES(BT_DATA_SVC_DATA16, 0x18 , 0x1a , 0x34, 0x35),
};
struct bt_data ad1[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x18, 0x1a),
BT_DATA_BYTES(BT_DATA_SVC_DATA16, 0x18 , 0x1a , 0x37, 0x36),
};
/* Set Scan Response data */
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
static void bt_ready(int err)
{
char addr_s[BT_ADDR_LE_STR_LEN];
bt_addr_le_t addr = {0};
size_t count = 1;
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
/* Start advertising */
err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return;
}
uint8_t d[4] = {0x18 , 0x1a, 0x32, 0x32};
ad1[2].data = (const uint8_t *)(d);
/* Update advertising */
err = bt_le_adv_update_data(ad1, ARRAY_SIZE(ad1),
sd, ARRAY_SIZE(sd));
if (err) {
printk("Advertising update with (err %d)\n", err);
return;
}
/* For connectable advertising you would use
* bt_le_oob_get_local(). For non-connectable non-identity
* advertising an non-resolvable private address is used;
* there is no API to retrieve that.
*/
bt_id_get(&addr, &count);
bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
printk("Beacon started, advertising as %s\n", addr_s);
}
Is there some function that permit to update data periodicaly?
Could you provide more documentation?
Thank you in advance.
Marco