btleManufacturerDataGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.00

 


 

This function retrieves the manufacturer data from a remote device.

The manufacturer data is custom data that is part of the 30 custom bytes in the advertising data.

Note: The manufacturer data included in the Scan Response is currently not available.

 

There may be multiple sets of manufacturer data in the data, so the sets are concatenated in the buffer, using the following format for each set:

 


Field

Size


ID 1

2 bytes, Little Endian


Data Length 1

1 byte


Data 1

Data Length 1 bytes


ID 2

2 bytes, Little Endian


...



Data N

Data Length N bytes

 

 

The format means that if the wanted device is known to only have one set of manufacturer data, it is enough to check the ID and then just use the data directly.

 

Note: To be able to receive advertising data, the adapter must be scanning, using btScanStart.

 

Input:

dev : STRING

The address of the device to get the data from.

 

size : INT

The size of the buffer.

 

data : PTR

The buffer to store the data in. Must be at least 31 bytes long. If there are multiple sets of manufacturer data, it must be larger.

 

Output:

size : INT

The number of valid bytes in the buffer. If the buffer is too small, this will contain the needed size.

 

 

Returns: INT

1

-

_BT_OK


Success.

0

-

_BT_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BT_ERR_NOT_OPEN


The adapter is not powered(see btPower).

-4

-

_BT_ERR_NOT_FOUND


Could not find device.

-7

-

_BT_ERR_NO_RES


The buffer is not large enough for the data. The size parameter contains the needed size.

-8

-

_BT_ERR_INVAL


Buffer is smaller than 31 bytes.

-9

-

_BT_ERR_NODATA


The device has not manufacturer data

 

 

 

Declaration:

FUNCTION btleManufacturerDataGet : INT;
VAR_INPUT
  dev      : STRING;
  size     : ACCESS INT;
  data     : PTR;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  sz      : INT;
  address : STRING;
  data    : ARRAY [1..32] OF SINT;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
// Start scanning for BLE devices to receive advertising data.
btScanStart(transport:=2);
 
BEGIN
  ...
  // retrieve manufacturer data from the device
  sz := SIZEOF(data);
  rc := btleManufacturerDataGet(dev:=address, data:=ADDR(data), size := sz);
  DebugFmt(message:="btleManufacturerDataGet: \1, sz \2$N", v1:=rc, v2 := sz);
 ...
END;
 
END_PROGRAM;