BluetoothCentral


super: DataSet

The BluetoothCentral class enables you to discover, connect to and communicate with Bluetooth 4.0 low-energy devices.

Events

  • Load() This event is called when the object becames available in the current runtime system.

  • NewValue(value: Map) Event raised when a new value becomes available. The value parameter is map.

  • UpdatedState(state: BluetoothState) Event raised when the blueetooth central changes its state

  • ShouldConnect(peripheralName: String, peripheralUUID: String, RSSI: Int): Bool The bluetooth central has discovered a peripheral that are advertising one of the configured services. Return true if the central should connect to this peripheral. If not implemented, the central will connect to any discovered peripheral.

  • DidStart() Event raised when DataSet started retrieving data.

  • DidFinish() Event raised when DataSet finished retrieving data.

  • DidFail() Event raised in case of DataSet error.

  • Unload() This event is called when the object has been removed from the current runtime system (but not yet deallocated).

Properties

  • var state: BluetoothState Returns the current state of the central manager. The PoweredOn state indicates that the central device (your iPhone or iPad, for instance) supports Bluetooth low energy and that Bluetooth is on and available to use.

  • var data: Data Returs the row data of the last value received from a pheripheral. (read-only)

  • var characteristicUUID: String Returs the characteristic UUID of the last value received from a pheripheral. (read-only)

  • var characteristicName: String Returs the characteristic name of the last value received from a pheripheral. (read-only)

  • var serviceUUID: String Returs the service UUID of the last value received from a pheripheral. (read-only)

  • var serviceName: String Returs the service name of the last value received from a pheripheral. (read-only)

  • var peripheralId: String Returs the peripheral ID of the last value received from a pheripheral. (read-only)

  • var peripheralName: String Returs the peripheral name of the last value received from a pheripheral. (read-only)

  • var decodedValue: Object Returs the decoded value of the last value received from a pheripheral. (read-only)

Methods

  • func scanForPeripherals() Scans for peripherals that are advertising the configured services.

  • func stopScan() Stops scanning for peripherals.

  • func readValue(peripheral: String, service: String, characteristic: String): Bool Retrieves the value of a specified characteristic. Return true if the peripheral, service and characteristic are valid, false otherwise. If the value of the characteristic is successfully retrieved, you will be notified with a NewValue event.

  • func writeValue(value: Object, peripheral: String, service: String, characteristic: String, type: CharacteristicWriteType): Bool Writes the value of a characteristic. If the value is a Data object it is written as is, otherwise (Number, String, etc.) the BluetoothCentral tries to encode the value for known characteristis. Return true if the peripheral, service and characteristic are valid, false otherwise. If the WriteWithResponse type is specified, NewValue event is called with the result of the write request.

  • func setNotifyValue(enabled: Bool, peripheral: String, service: String, characteristic: String): Bool Enables or disables notifications/indications for the characteristic. If characteristic allows both, notifications will be used. When notifications/indications are enabled, updates to the characteristic value will be received via NewValue event.

Enumeration

BluetoothState

  • .PoweredOff
  • .PoweredOn
  • .Resetting
  • .Unauthorized
  • .Unknown
  • .Unsupported

CharacteristicWriteType

  • .WriteWithResponse
  • .WriteWithoutResponse