Advertising two services at the same time for nrf52832

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Pratyusha_duvvi
 
Posts: 10
Joined: Tue Aug 02, 2022 6:56 am

Advertising two services at the same time for nrf52832

Post by Pratyusha_duvvi »

Hi,

We are trying to advertise 2 different payload - one after the other - Service Data and Manufacturer Specific Data.
Also swaped the data we are passing(Manufaturer Data then Service Data).
But only the first payload which we are passing is getting advertised, the second one not.

Is it possible to advertise 2 payload at the same time using bluefruit.h library? We are using nRF Connect to check the advertised payload,also checked with BLE Sniffer.
Am I doing correctly?
Thanks in Advance.

Code: Select all

#include <Arduino.h>
#include <bluefruit.h>
void serviceDataAdv()
{
   uint8_t Adv_DATA[] = {0xfe,0xac,0x14,0x11,0x0f,0xc5,0xb2,0xe0,0x73,0xf2,0x76,0xb3,0x82,0x0f,0x42,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

    Bluefruit.ScanResponse.addName();
    Bluefruit.Advertising.restartOnDisconnect(false);
    Bluefruit.Advertising.setInterval(400, 425);    // in unit of 0.625 ms
    Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
    Bluefruit.Advertising.stop();
    Bluefruit.Advertising.addData(BLE_GAP_AD_TYPE_SERVICE_DATA_128BIT_UUID, Adv_DATA,   sizeof(Adv_DATA));
    Bluefruit.Advertising.start(2);   // 0 = Don't stop advertising after n seconds
    delay(2000);
    
    Bluefruit.ScanResponse.clearData();
    Bluefruit.Advertising.clearData();
}
void manDataAdv()
{
uint8_t AdvGen_Data[] = {0x2a,0x00,0x01,(temppp >> 8),(temppp & 0xFF),0x02,(hummm >> 8),(hummm & 0xff),0x0b,batttt,0x0c,(ullCo2 >> 8),(ullCo2 & 0xff)};
Bluefruit.Advertising.stop();
Bluefruit.Advertising.addData(BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, AdvGen_Data, sizeof(AdvGen_Data));
Bluefruit.Advertising.start(2);   // 0 = Don't stop advertising after n seconds
delay(2000);
Bluefruit.ScanResponse.clearData();
Bluefruit.Advertising.clearData();    
}
void setup()
{
 Bluefruit.begin();
 Bluefruit.autoConnLed(false);
 Bluefruit.setName("bleadv");
 Bluefruit.setTxPower(0);
}
void loop()
{
serviceDataAdv();
delay(5000);
manDataAdv();

}
board : adafruit feather nrf52832
IDE : Platform IO
SoftDevice : S132 6.1.1


platform.ini file
[env:adafruit_feather_nrf52832]
platform = nordicnrf52
board = adafruit_feather_nrf52832
framework = arduino
upload_protocol = jlink
debug_tool = jlink

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Advertising two services at the same time for nrf52832

Post by adafruit_support_mike »

Pratyusha_duvvi wrote: Fri Sep 30, 2022 1:29 am Is it possible to advertise 2 payload at the same time
It depends on what you mean by 'payloads'.

A BLE ADV_IND Advertising packet has:

- a 2-byte header
- a 6-byte device address
- a 1-byte length field
- a 1-byte type code (defined by the BLE Working Group for specific devices)
- and 0-29 bytes of user data

The user data can be anything you want, so in theory you could put two 'payloads' worth of data in the same packet as long as the total length is 29 bytes or less.

More generally, if you want to send additional advertising data you should use SCAN_RSP packets:

https://learn.adafruit.com/bluefruit-nr ... dvertising

Only the ADV_IND packet is transmitted automatically though. SCAN_RSP packets are sent in reply when a central device asks for them.

User avatar
Pratyusha_duvvi
 
Posts: 10
Joined: Tue Aug 02, 2022 6:56 am

Re: Advertising two services at the same time for nrf52832

Post by Pratyusha_duvvi »

@adafruit_support_mike

thanks for reply!
Here im advertising two different packets one with manufacturer specific data and another service data. im advertising this packets one after the other with some delay as u seen in the code. In manufacturer specific data im transmitting 16bytes of data (user data) and in service data 24 bytes of data (user data).
The problem is only the first data is advertising, the second one is not advertising

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Advertising two services at the same time for nrf52832

Post by adafruit_support_mike »

You can't fit 16+24=40 bytes of data in an advertising packet. 29 bytes is the maximum.

You can't send more than one kind of advertising packet at a time. The protocol doesn't allow it.

You can change the advertising message.. sending one, changing the message, then sending again. To do that you have to stop advertising, change the message, then start advertising again.

User avatar
Pratyusha_duvvi
 
Posts: 10
Joined: Tue Aug 02, 2022 6:56 am

Re: Advertising two services at the same time for nrf52832

Post by Pratyusha_duvvi »

@adafruit_support_mike what is this advertising message means? i used that Bluefruit.Advertising.stop(); then also only first advertisement is coming.
Here i am advertising two different data with 5seconds delay.

Code: Select all

#include <Arduino.h>
#include <bluefruit.h>
void serviceDataAdv()
{
   uint8_t Adv_DATA[] = {0xfe,0xac,0x14,0x11,0x0f,0xc5,0xb2,0xe0,0x73,0xf2,0x76,0xb3,0x82,0x0f,0x42,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

    Bluefruit.ScanResponse.addName();
    Bluefruit.Advertising.restartOnDisconnect(false);
    Bluefruit.Advertising.setInterval(400, 425);    // in unit of 0.625 ms
    Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
    Bluefruit.Advertising.addData(BLE_GAP_AD_TYPE_SERVICE_DATA_128BIT_UUID, Adv_DATA,   sizeof(Adv_DATA));
    Bluefruit.Advertising.start(2);   // 0 = Don't stop advertising after n seconds
    delay(2000);
    Bluefruit.Advertising.stop();
    
    Bluefruit.ScanResponse.clearData();
    Bluefruit.Advertising.clearData();
}
void manDataAdv()
{
uint8_t AdvGen_Data[] = {0x2a,0x00,0x01,(temppp >> 8),(temppp & 0xFF),0x02,(hummm >> 8),(hummm & 0xff),0x0b,batttt,0x0c,(ullCo2 >> 8),(ullCo2 & 0xff)};
Bluefruit.Advertising.addData(BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, AdvGen_Data, sizeof(AdvGen_Data));
Bluefruit.Advertising.start(2);   // 0 = Don't stop advertising after n seconds
delay(2000);
Bluefruit.Advertising.stop();
Bluefruit.ScanResponse.clearData();
Bluefruit.Advertising.clearData();    
}
void setup()
{
 Bluefruit.begin();
 Bluefruit.autoConnLed(false);
 Bluefruit.setName("bleadv");
 Bluefruit.setTxPower(0);
}
void loop()
{
serviceDataAdv();
delay(5000);
manDataAdv();
}

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”