Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Defining 128Bit UUID's Feather Nrf52
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Defining 128Bit UUID's Feather Nrf52

by kaniada on Sat Nov 24, 2018 9:17 pm

Whats the correct way to define a new 128bit UUID?

In the dual roles example there's a line which utilizes bleuart.uuid. Where is that property of the bleuart class defined?

kaniada
 
Posts: 3
Joined: Sat Nov 24, 2018 9:10 pm

Re: Defining 128Bit UUID's Feather Nrf52

by kaniada on Sun Nov 25, 2018 6:10 pm

BLEuart.cpp seems to define 128bit UUIDs as follows

Code: Select all | TOGGLE FULL SIZE
const uint8_t BLEUART_UUID_SERVICE[] =
{
    0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
    0x93, 0xF3, 0xA3, 0xB5, 0x01, 0x00, 0x40, 0x6E
};


I've defined my own 128 bit UUID
Code: Select all | TOGGLE FULL SIZE
const uint8_t CUSTOM_SERVICE[] =
{
    0x85, 0x20, 0x51, 0x00, 0x26, 0xDD, 0x91, 0x3F,
    0x4B, 0x8F, 0xEE, 0x97, 0x79, 0x9E, 0x30, 0x4F
};


and in an attempt to detect that UUID in the central_Scan_advance example by adding the following bit of code:
Code: Select all | TOGGLE FULL SIZE
  if ( Bluefruit.Scanner.checkReportForUuid(report, CUSTOM_SERVICE) )
  {
    Serial.printf("%14s %s\n", "CUSTOM_SERVICE", "UUID Found!");
  }


The following packet is detected but "UUID Found!" is never printed in the console. Any thoughts on why that is?

[ADV 1749906] Packet received from 38:B5:BD:00:00:D3
PAYLOAD 29 bytes
02-01-06-07-09-4D-79-5F-48-6F-62-11-06-4F-30-9E-79-97-EE-8F-4B-3F-91-DD-26-00-51-20-85
RSSI -73 dBm
ADV TYPE Connectable undirected
COMPLETE NAME My_Hob
128-Bit UUID 85205100-26DD-913F-4B8F-EE97799E304F

kaniada
 
Posts: 3
Joined: Sat Nov 24, 2018 9:10 pm

Re: Defining 128Bit UUID's Feather Nrf52

by hathach on Mon Nov 26, 2018 12:50 am

you may enable one of the filter, post your full sketch will help other to analyze your problem.

hathach
 
Posts: 1172
Joined: Tue Apr 23, 2013 1:02 am

Re: Defining 128Bit UUID's Feather Nrf52

by kaniada on Mon Nov 26, 2018 7:20 pm

Code: Select all | TOGGLE FULL SIZE
#include <bluefruit.h>

/* For a list of EIR data types see:
 *    https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
 *    Matching enum: cores/nRF5/SDK/components/softdevice/s132/headers/ble_gap.h */

// Device Information 0x180A
// UUID16_SVC_DEVICE_INFORMATION

const uint8_t CUSTOM_SERVICE[] =
{
    0x85, 0x20, 0x51, 0x00, 0x26, 0xDD, 0x91, 0x3F,
    0x4B, 0x8F, 0xEE, 0x97, 0x79, 0x9E, 0x30, 0x4F
};

void setup()
{
 
  Serial.begin(115200);
  while ( !Serial ) delay(10);   // for nrf52840 with native usb

  Serial.println("Bluefruit52 Central ADV Scan Example");
  Serial.println("------------------------------------\n");

  // Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
  // SRAM usage required by SoftDevice will increase dramatically with number of connections
  Bluefruit.begin(0, 1);
 
  // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
  Bluefruit.setTxPower(4);

  /* Set the device name */
  Bluefruit.setName("Bluefruit52");

  /* Set the LED interval for blinky pattern on BLUE LED */
  Bluefruit.setConnLedInterval(250);

  /* Start Central Scanning
   * - Enable auto scan if disconnected
   * - Filter out packet with a min rssi
   * - Interval = 100 ms, window = 50 ms
   * - Use active scan (used to retrieve the optional scan response adv packet)
   * - Start(0) = will scan forever since no timeout is given
   */
  Bluefruit.Scanner.setRxCallback(scan_callback);
  Bluefruit.Scanner.restartOnDisconnect(true);
  Bluefruit.Scanner.filterRssi(-80);
  //Bluefruit.Scanner.filterUuid(BLEUART_UUID_SERVICE); // only invoke callback if detect bleuart service
  Bluefruit.Scanner.setInterval(160, 80);       // in units of 0.625 ms
  Bluefruit.Scanner.useActiveScan(true);        // Request scan response data
  Bluefruit.Scanner.start(0);                   // 0 = Don't stop scanning after n seconds

  Serial.println("Scanning ...");
}

void scan_callback(ble_gap_evt_adv_report_t* report)
{
  PRINT_LOCATION();
  uint8_t len = 0;
  uint8_t buffer[32];
  memset(buffer, 0, sizeof(buffer));
 
  /* Display the timestamp and device address */
  if (report->type.scan_response)
  {
    Serial.printf("[SR%10d] Packet received from ", millis());
  }
  else
  {
    Serial.printf("[ADV%9d] Packet received from ", millis());
  }
  // MAC is in little endian --> print reverse
  Serial.printBufferReverse(report->peer_addr.addr, 6, ':');
  Serial.print("\n");

  /* Raw buffer contents */
  Serial.printf("%14s %d bytes\n", "PAYLOAD", report->data.len);
  if (report->data.len)
  {
    Serial.printf("%15s", " ");
    Serial.printBuffer(report->data.p_data, report->data.len, '-');
    Serial.println();
  }

  /* RSSI value */
  Serial.printf("%14s %d dBm\n", "RSSI", report->rssi);

  /* Adv Type */
  Serial.printf("%14s ", "ADV TYPE");
  if ( report->type.connectable )
  {
    Serial.print("Connectable ");
  }else
  {
    Serial.print("Non-connectable ");
  }
 
  if ( report->type.directed )
  {
    Serial.println("directed");
  }else
  {
    Serial.println("undirected");
  }

  /* Shortened Local Name */
  if(Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, buffer, sizeof(buffer)))
  {
    Serial.printf("%14s %s\n", "SHORT NAME", buffer);
    memset(buffer, 0, sizeof(buffer));
  }

  /* Complete Local Name */
  if(Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, buffer, sizeof(buffer)))
  {
    Serial.printf("%14s %s\n", "COMPLETE NAME", buffer);
    memset(buffer, 0, sizeof(buffer));
  }

  /* TX Power Level */
  if (Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_TX_POWER_LEVEL, buffer, sizeof(buffer)))
  {
    Serial.printf("%14s %i\n", "TX PWR LEVEL", buffer[0]);
    memset(buffer, 0, sizeof(buffer));
  }

  /* Check for UUID16 Complete List */
  len = Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, buffer, sizeof(buffer));
  if ( len )
  {
    printUuid16List(buffer, len);
  }

  /* Check for UUID16 More Available List */
  len = Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, buffer, sizeof(buffer));
  if ( len )
  {
    printUuid16List(buffer, len);
  }

  /* Check for UUID128 Complete List */
  len = Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, buffer, sizeof(buffer));
  if ( len )
  {
    printUuid128List(buffer, len);
  }

  /* Check for UUID128 More Available List */
  len = Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, buffer, sizeof(buffer));
  if ( len )
  {
    printUuid128List(buffer, len);
  } 

  /* Check for BLE UART UUID */
  if ( Bluefruit.Scanner.checkReportForUuid(report, BLEUART_UUID_SERVICE) )
  {
    Serial.printf("%14s %s\n", "BLE UART", "UUID Found!");
  }

  /* Check for DIS UUID */
  if ( Bluefruit.Scanner.checkReportForUuid(report, UUID16_SVC_DEVICE_INFORMATION) )
  {
    Serial.printf("%14s %s\n", "DIS", "UUID Found!");
  }

  /* Check for CUSTOM SERVICE UUID */
  if ( Bluefruit.Scanner.checkReportForUuid(report, CUSTOM_SERVICE) )
  {
    Serial.printf("%14s %s\n", "CUSTOM_SERVICE", "UUID Found!");
  }

  /* Check for Manufacturer Specific Data */
  len = Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, buffer, sizeof(buffer));
  if (len)
  {
    Serial.printf("%14s ", "MAN SPEC DATA");
    Serial.printBuffer(buffer, len, '-');
    Serial.println();
    memset(buffer, 0, sizeof(buffer));
  } 

  Serial.println();

  // For Softdevice v6: after received a report, scanner will be paused
  // We need to call Scanner resume() to continue scanning
  Bluefruit.Scanner.resume();
}

void printUuid16List(uint8_t* buffer, uint8_t len)
{
  Serial.printf("%14s %s", "16-Bit UUID");
  for(int i=0; i<len; i+=2)
  {
    uint16_t uuid16;
    memcpy(&uuid16, buffer+i, 2);
    Serial.printf("%04X ", uuid16);
  }
  Serial.println();
}

void printUuid128List(uint8_t* buffer, uint8_t len)
{
  (void) len;
  Serial.printf("%14s %s", "128-Bit UUID");

  // Print reversed order
  for(int i=0; i<16; i++)
  {
    const char* fm = (i==4 || i==6 || i==8 || i==10) ? "-%02X" : "%02X";
    Serial.printf(fm, buffer[15-i]);
  }

  Serial.println(); 
}

void loop()
{
  // nothing to do
}


Above is the modified code from the central_scan_advanced.ino example. Despite the scanner seeing a report which contains the CUSTOM_SERVICE UUID, no indication is made that the UUID is found as you would expect from this code. I noticed that checkReportForUuid seems to expect a BLEUuid object as its second argument, but I've seen a uint8_t array passed into this function in other adafruit code.

kaniada
 
Posts: 3
Joined: Sat Nov 24, 2018 9:10 pm

Re: Defining 128Bit UUID's Feather Nrf52

by hathach on Tue Nov 27, 2018 1:17 am

the uuid declared must be in the little endian order e.g

UART Serivce: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E is defined as

const uint8_t BLEUART_UUID_SERVICE[] =
{
0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
0x93, 0xF3, 0xA3, 0xB5, 0x01, 0x00, 0x40, 0x6E
};

Can you check to make sure it is not endian issue. Maybe try to reverse the order of you declaration.

hathach
 
Posts: 1172
Joined: Tue Apr 23, 2013 1:02 am

Please be positive and constructive with your questions and comments.