Advertisement Event

Fired when an advertisement packet is received during scanning.

Syntax

public event OnAdvertisementHandler OnAdvertisement;

public delegate void OnAdvertisementHandler(object sender, BleclientAdvertisementEventArgs e);

public class BleclientAdvertisementEventArgs : EventArgs {
  public string ServerId { get; }
  public string Name { get; }
  public int RSSI { get; }
  public int TxPower { get; }
  public string ServiceUuids { get; }
  public string ServicesWithData { get; }
  public string SolicitedServiceUuids { get; }
  public int ManufacturerCompanyId { get; }
  public string ManufacturerData { get; }
public byte[] ManufacturerDataB { get; } public bool IsConnectable { get; } public bool IsScanResponse { get; } }
Public Event OnAdvertisement As OnAdvertisementHandler

Public Delegate Sub OnAdvertisementHandler(sender As Object, e As BleclientAdvertisementEventArgs)

Public Class BleclientAdvertisementEventArgs Inherits EventArgs
  Public ReadOnly Property ServerId As String
  Public ReadOnly Property Name As String
  Public ReadOnly Property RSSI As Integer
  Public ReadOnly Property TxPower As Integer
  Public ReadOnly Property ServiceUuids As String
  Public ReadOnly Property ServicesWithData As String
  Public ReadOnly Property SolicitedServiceUuids As String
  Public ReadOnly Property ManufacturerCompanyId As Integer
  Public ReadOnly Property ManufacturerData As String
Public ReadOnly Property ManufacturerDataB As Byte() Public ReadOnly Property IsConnectable As Boolean Public ReadOnly Property IsScanResponse As Boolean End Class

Remarks

The Advertisement event is fired each time an advertisement is received while the component is Scanning for servers to connect to. Based on the information in the advertisement, you can decide whether or not you wish to connect to the associated device (if it is connectable).

Not all of the parameters are relevant for all platforms. Additionally, since advertisement packets are somewhat flexible in their contents, it is not guaranteed that every parameter relevant to your platform will be populated for every advertisement. Please refer to the following table for descriptions of the parameters:

Parameter Description
ServerId Platform-specific server Id string
Name Server's local name, either shortened or complete
RSSI Server RSSI in dBm (.NET), or dB (macOS/iOS)
TxPower Server transmit power in dBm (Or integer's MinValue if not in advertisement)
ServiceUuids Comma-separated list of 128-bit service UUID strings
ServicesWithData Comma-separated list of 128-bit service UUID strings for services which the advertisement contained data for
SolicitedServiceUuids Comma-separated list of 128-bit solicited service UUID strings
ManufacturerCompanyId Company Id from the first manufacturer data section in the advertisement (Or -1 if there are none)
ManufacturerData Data from the first manufacturer data section in the advertisement (Or empty if there are none)
IsConnectable Whether the device which sent this advertisement is accepting connections
IsScanResponse Whether this is a scan response packet

Setting the ServiceData configuration setting to any of the service UUIDs in the ServicesWithData parameter will return the associated data.

You can use the ManufacturerDataCount configuration setting to determine whether the advertisement contains multiple manufacturer data sections; if it does, the ManufacturerData and ManufacturerCompanyId configuration settings can be used to iterate over them.

Note that all of the configuration settings mentioned above are only valid while you are within the Advertisement event handler.

Please refer to the following table to determine which parameters are relevant for your platform:

Parameter .NETmacOS/iOS
ServerId X X
Name X X
RSSI X X
TxPower X X
ServiceUuids X X
ServicesWithData X X
SolicitedServiceUuids X X
ManufacturerCompanyId X X
ManufacturerData X X
IsConnectable X X
IsScanResponse X

Note: IsConnectable will always be false when IsScanResponse is true.

Refer to the StartScanning method for more information.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks BLE 2020 .NET Edition - Version 20.0 [Build 8158]