Hi there,
I'm trying to advertise my changing sensor data over BLE, and according to my calculations it should fit without a scan response, but it isn't fitting--what am I missing? Is there a way to get it to compress to send the data in one packet? I'm really trying to accomplish this without a scan response. Here are the details:
This is where I define my manufacturer specific data. I need to send 7 floats, so 28 bytes of data of a supposed 31 byte limit.
typedef struct adv_mfg_data {
float cap_val_0; // 4 bytes
float cap_val_1;
float cap_val_2;
float w_scaled;
float x_scaled;
float y_scaled;
float z_scaled;
} adv_mfg_data_type;
and here is where I assemble the advertising packet:
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
BT_DATA(BT_DATA_MANUFACTURER_DATA,(unsigned char *)&adv_mfg_data, sizeof(adv_mfg_data)),
};
When I try to run the code, however, it gives me a packet "too big" error. Where's the extra space coming from? How can I make this work in one packet? Is there a different structure I could use?
Clarification: it works with one less float, but I think the flags and other members of the BT_DATA() structures send me one byte over to 32 bytes--is this correct? If so, is there a way to fit that one byte in there? Can I get rid of the company ID? Is there a 3-byte float? I don't need 4 bytes of precision on 3 of the floats, but I don't think there's another structure that would work. I roughly need to represent a double-digit decimal value with 2-3 decimal places: XX.XXX. What might this fit in?
Some other questions, too:
1. I'm using a sniffer (with Wireshark) to look at packets, but I'm not sure how to decode my data back to the floats I started with--do you have advice on this?
2. I need to configure a nRF52840 as a central device that retrieves the data from the adv packets of 20 of these BLE beacons, is there an example code using the nRF Connect SDK that I could start with? Or any advice you have?
3. To identify each of the 20 devices to the central, is there room for a random static address (or would something else be easier?) so I can know which peripheral I'm receiving data from? Would this add to the advertising packet or just change it?
4. The functions to start advertising and update advertising necessitate including a scan response--is there a way to remove the scanning feature? This is how I configured BT, and my functions to start and update advertisement.
static struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM(0, /* 0 = BT_LE_ADV_NCONN */ //want ADV_NONCONN_IND, but doesn't recognize
800, /*Min Advertising Interval 500ms (800*0.625ms) */
801, /*Max Advertising Interval 500.625ms (801*0.625ms)*/
NULL); /* Set to NULL for undirected advertising*/ //but I could set to peer
err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); //my changing variables will be in ad
If it would be useful for any of this, I can attach my whole main.c. Let me know, and thank you so much!