btleLastSeen (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

2.26.00

 


 

This function is used to determine how much time has passed since data was last received from the provided device.

This can e.g. be used to quickly detect when a BLE device that keeps sending advertising data has disappeared.

Note that scanning must be active to receive advertising data.

 

 

Input:

dev : STRING

The address of the device.

 

 

Returns: INT

>0

-



Number of seconds since the most recent data was received.

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.

 

 

 

Declaration:

FUNCTION btleLastSeen : INT;
VAR_INPUT
  dev      : STRING;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  address : STRING;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
BEGIN
  ...
  rc := btleLastSeen(dev:=address);
  IF rc > 30 THEN
    // No data has been received for over 30 seconds: The device must have gone.
    DebugFmt(message:="Lost "+address+": \1 s", v1:=rc);
  END_IF;
  ...
END;
 
END_PROGRAM;