Hello,
Wondering if it is possible to have a node do both -- advertise and scan for advertisements. Also I would like to piggyback some data in the advertisement.
The advertisements themselves would be used for sending messages. No connections would ever be established. Thus no slave and masters.
Do people do this? Can it be done? Thanks,
Saleem
Hi Saleem,
Yes this would be possible by doing a scan request and capture the required data from the advertisement. Subsequently you can advertise yourself using this data. So it can be done however you cannot connect as you are more or less a one-way repeater.
Best regards, RvA
Hello saleem145,
you can't advertise and scan at the same time, but, as far as I know, what you can do is toggle between advertising and scanning modes. You can use
GAPM_SCAN_PASSIVE
andGAPM_ADV_NON_CONN
. You can, e.g., append manufacturer specific data to your ADV packet. I have found that it is easier to form a structure for appending the data to the packet:#define MS_DATA_SIZE 4
struct __attribute__((packed)) manufacturer_specific_data_s
{
uint8_t length;
const uint8_t type;
const uint16_t company_identifier;
uint8_t data[MS_DATA_SIZE];
};
Then you create instance from the structure
struct manufacturer_specific_data_s ms_data =
{
1 + 2 + MS_DATA_SIZE, // Size = type + company_identifier + MS_DATA_SIZE
GAP_AD_TYPE_MANU_SPECIFIC_DATA,
0x00d2, // Company identifier for Dialog
{0x01, 0x02, 0x03, 0x04} // Some data, length is MS_DATA_SIZE
}
Then you can finally append it to the adv packet in
app_adv_func
function:cmd->info.host.adv_data_len = sizeof(struct manufacturer_specific_data_s);
memcpy(&cmd->info.host.adv_data[0], &ms_data, cmd->info.host.adv_data_len);
Don't exceed the allowed adv packet size
PS. I didn't test it, so there might be errors!
PSS. You need to pack the struct with __attribute__((packed)) attribute to prevent additional padding in the structure.
Couiple of questions --
1. What is meant by a "one way repeater"?? I don't see why this is --
Node A:
Advertisement: Node C I would like to know the temperature??
Node B: scans and sees this question is for Node C so does nothing
Node C: scans and advertises Node A: the temperature is 23C
Node A: scans and reads the temperature and perhaps acks it by saying "Thank you Node C"
Looks like two way communication to me??
2. My second question is what are the disadvantages of this approach compared to setting up a connection??
3. What is the maximum packet size. Is it 4 bytes or can it be changed to some other value??
Thanks,
Saleem
Hi saleem,