Advertise and scan simultaneously

5 posts / 0 new
Last post
saleem145
Offline
Last seen:5 years 7 months ago
加入:2015-03-19 00:49
Advertise and scan simultaneously

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

RvA
Offline
Last seen:2 weeks 23 hours ago
工作人员
加入:2014-02-07 14:10
Hi 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

VesaN
Offline
Last seen:5 years 4 months ago
Guru Master
加入:2014-06-26 08:49
Hello saleem145,

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 useGAPM_SCAN_PASSIVEandGAPM_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 inapp_adv_funcfunction:

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。我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.

saleem145
Offline
Last seen:5 years 7 months ago
加入:2015-03-19 00:49
Couiple of questions --

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

VesaN
Offline
Last seen:5 years 4 months ago
Guru Master
加入:2014-06-26 08:49
Hi saleem,

Hi saleem,

  • What is meant by a "one way repeater"
    I guess it would be a retransmitter that only allows messages to delivered from A => B => C; A <=> B <=> C is not allowed. You are right in that there will be communication to both directions, but it is only "meta communication" to make sure the actual information payload is not delivered (temperature reading). There are no packets that are sent from C => A, only from A => C (the temperature reading).
  • What are the disadvantages of this approach compared to setting up a connection
    Probably there will be less traffic. And it is faster since connection doesn't need to be initialized. But advertising is not so handy if there is much data to transfer.
  • What is the maximum packet size. Is it 4 bytes or can it be changed to some other value
    It can be more than 4 octets. I don't remember the exactly the maximum packet size, but it is around 30 octets (maybe 31 at max?). It will be less than that depending on what else you have in the adv packet (e.g. device name)