BLE 31 byte payload, extract and publish

Tags: #<Tag:0x00007fe21eafa200>


Goodday. Im trying to extract the 31 byte payload from i-beacons and particle.publish them. Using a central example I manage to only publish the “scanResults[i].advertisingData.deviceName();” correctly.

In Segger with the Nordic libs I use the following snipit to get the 31 byte payload

  memmove(RX_Data, p_gap_evt->, p_gap_evt->;

 //use this to check and print all
            /*   NRF_LOG_RAW_INFO("%02x%02x%02x%02x%02x%02x", RX_Data[0], RX_Data[1], RX_Data[2], RX_Data[3], RX_Data[4], RX_Data[5]);
                  NRF_LOG_RAW_INFO("%02x%02x%02x%02x%02x%02x", RX_Data[6], RX_Data[7], RX_Data[8], RX_Data[9], RX_Data[10], RX_Data[11]);
                   NRF_LOG_RAW_INFO("%02X%02x%02x%02x%02x%02x", RX_Data[12], RX_Data[13], RX_Data[14], RX_Data[15], RX_Data[16], RX_Data[17]);
                    NRF_LOG_RAW_INFO("%02x%02x%02x%02x%02x%02x", RX_Data[18], RX_Data[19], RX_Data[20], RX_Data[21], RX_Data[22], RX_Data[23]);
                     NRF_LOG_RAW_INFO("%02x%02x%02x%02x%02x%02x", RX_Data[24], RX_Data[25], RX_Data[25], RX_Data[26], RX_Data[27], RX_Data[28]);
                      NRF_LOG_RAW_INFO("%02x%02x%02x%02x%02x%02x\r\n", RX_Data[29], RX_Data[30], RX_Data[31], RX_Data[32], RX_Data[33], RX_Data[34]);

Im having trouble figuring out how to extract it from the code below. I presume the payload is the buf string. I would then like to particle.publish the entire string or sections of it. Any guidance would be appreciated.

#include "Particle.h"

// This example does not require the cloud so you can run it in manual mode or
// normal cloud-connected mode

const size_t SCAN_RESULT_MAX = 30;

BleScanResult scanResults[SCAN_RESULT_MAX];

uint8_t buf[BLE_MAX_ADV_DATA_LEN]; // buffer that hold the 30 characters
const char *EVENT_NAME = "test";
void subscriptionHandler(const char *event, const char *data);

void setup()
    //selectExternalMeshAntenna(); // set the external antenna
    while (!Serial.available()) delay(10);

void loop()

    // Only scan for 500 milliseconds
    int count = BLE.scan(scanResults, SCAN_RESULT_MAX);

    for (int i = 0; i < count; i++)
        size_t len;

        len = scanResults[i].advertisingData.get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, buf, BLE_MAX_ADV_DATA_LEN);
        // We have manufacturer-specific advertising data (0xff) and it's 7 bytes (without the AD type)

        // 16-bit: Company ID
        // Byte: Internal packet identifier

        Serial.printf("\nindex: %2i RSSI: %d len: %i MANUF: %02X:%02X  %02X:%02X  MAC: %02X:%02X:%02X:%02X:%02X:%02X ",
                               i,scanResults[i].rssi,len,buf[1], buf[0], buf[2], buf[3],        
        scanResults[i].address[0], scanResults[i].address[1], scanResults[i].address[2],
        scanResults[i].address[3], scanResults[i].address[4], scanResults[i].address[5]);
        String name = scanResults[i].advertisingData.deviceName();

        if (name.length() > 0)
             {Serial.printlnf("Name: %s", name.c_str());
             Particle.publish(EVENT_NAME, name , PRIVATE);
        else {Serial.println();}

          /*   Serial.printf("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X ",


//applies to BT as well as mesh
void selectExternalMeshAntenna()
	digitalWrite(ANTSW1, 1);
	digitalWrite(ANTSW2, 0);
	digitalWrite(ANTSW1, 0);
	digitalWrite(ANTSW1, 0);
	digitalWrite(ANTSW2, 1);

void subscriptionHandler(const char *event, const char *data) 
{"received %s", data);


Not to worry I came right

using the below

#include "Particle.h"

#define SCAN_RESULT_COUNT       30
#define BLE_ADV_DATA_MAX        31


SerialLogHandler log(115200, LOG_LEVEL_ALL);

BleScanResult results[SCAN_RESULT_COUNT];

void setup() {


void loop() {
    int count = BLE.scan(results, SCAN_RESULT_COUNT); // scan how many beacons are around

    if (count > 0) {
        uint8_t buf[BLE_MAX_ADV_DATA_LEN];
        size_t len;

        Serial.printf("%d devices are found:", count);// how many beacons were found
        for (int i = 0; i < count; i++) {
            BleAddress address = results[i].address;  // mac address
            Serial.printf("MAC: %s\r\n", address.toString().c_str());

            len = results[i].advertisingData(buf, sizeof(buf));
            if (len > 0) {
                Serial.printf("Advertising data length: %02d\r\n", results[i].advertisingData.length());
                for (size_t j = 0; j < len; j++) {
                    Serial.printf("%02x,", buf[j]);
                 String name = results[i].advertisingData.deviceName(); // check if the results have an name
                if (name.length() > 0) {Serial.printlnf("Name: %s", name.c_str());}

            len = results[i].scanResponse(buf, sizeof(buf));
            if (len > 0) {
                Serial.printf("Scan response data length: %02d\r\n", results[i].scanResponse.length());
                for (size_t j = 0; j < len; j++) {
                    Serial.printf("%02x,", buf[j]);