All Projects → AntonTheDev → Extendable

AntonTheDev / Extendable

Licence: mit
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Extendable

Nimble Arduino
A fork of the NimBLE library structured for compilation with Ardruino, designed for use with ESP32.
Stars: ✭ 108 (+22.73%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le, bluetooth
ruuvitag-demo
Demo of reading Bluetooth Low Energy sensor measurements of RuuviTag environmental sensors and feeding them to MQTT, a database and dashboards
Stars: ✭ 14 (-84.09%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy, bluetooth-le
IOS-DFU-Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 400 (+354.55%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy, bluetooth-le
Ble.net
Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP
Stars: ✭ 137 (+55.68%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le, bluetooth
Easyble
Android BLE framework
Stars: ✭ 155 (+76.14%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le, bluetooth
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (-31.82%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy, bluetooth-le
Node Ble
Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
Stars: ✭ 159 (+80.68%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le, bluetooth
Ios Pods Dfu Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 349 (+296.59%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le, bluetooth
pirowflo
All-in-one data interface for your Waterrower S4 Monitor or Smartrow
Stars: ✭ 73 (-17.05%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
Rxbluetoothkotlin
Bluetooth low energy reactive framework for Android written in Kotlin
Stars: ✭ 68 (-22.73%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth
Ble Security Attack Defence
✨ Purpose only! The dangers of Bluetooth Low Energy(BLE)implementations: Unveiling zero day vulnerabilities and security flaws in modern Bluetooth LE stacks.
Stars: ✭ 88 (+0%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le
Rxbluetoothkit
iOS & OSX Bluetooth library for RxSwift
Stars: ✭ 1,213 (+1278.41%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth
BleLab
Bluetooth LE Lab - UWP application for interaction with BLE GATT devices
Stars: ✭ 68 (-22.73%)
Mutual labels:  bluetooth, bluetooth-low-energy, bluetooth-le
ESP32 BLE OTA Arduino
OTA update on ESP32 via BLE
Stars: ✭ 41 (-53.41%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le
ble-utilities-unreal
This is Unreal Engine plugin that allows to scan for BLE devices with Cycling Power service running, connect to one of them and subscribe for its notifications.
Stars: ✭ 48 (-45.45%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy
IoT-iBeacon
An Ionic app for indoor localization and navigation using BLE iBeacons.
Stars: ✭ 39 (-55.68%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy
Rxandroidble
An Android Bluetooth Low Energy (BLE) Library with RxJava2 interface
Stars: ✭ 3,025 (+3337.5%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le
JDY-08
JDY-08 Bluetooth transparent transmission module, with resource for KiCAD
Stars: ✭ 48 (-45.45%)
Mutual labels:  bluetooth, ble, bluetooth-low-energy
Bleu
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
Stars: ✭ 481 (+446.59%)
Mutual labels:  bluetooth-low-energy, bluetooth-le, bluetooth
Android Scanner Compat Library
A compat library for Bluetooth Low Energy scanning on Android.
Stars: ✭ 462 (+425%)
Mutual labels:  ble, bluetooth-low-energy, bluetooth-le

ExtendaBLE

Cocoapods Compatible Carthage compatible Build Status Platform License

alt tag

Introduction

ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder approach you can easily create centrals, peripherals, associated services, characteristics, and define callbacks to listen for characteristic changes accordingly.

One of the unique features of ExtendaBLE is that it allows to bypass the limitations of the MTU size in communicating between devices. The library negotiates a common MTU size, and allows breaks down the data to be sent between devices into packets, which are then reconstructed by the receiving entity.

An Android library is in the works with support for packet based communication between iOS /tvOs/OSX. ExtendaBLE-Android, a work in progress can be found here..

ExtendaBLE-Android

Features

  • [x] Blocks Syntax for Building Centrals and Peripherals
  • [x] Callbacks for responding to, read and write, characteristic changes
  • [x] Packet Based Payload transfer using negotiated MTU sizes
  • [x] Characteristic Update Callbacks
  • [x] Streamlined parsing for characteristic read operations

Installation

Communication

  • If you found a bug, or have a feature request, open an issue.
  • If you need help or a general question, use Stack Overflow. (tag 'extenda-ble')
  • If you want to contribute, review the Contribution Guidelines, and submit a pull request.

Basic Setup

In configuring BLE the first step is to configure a unique UUID for the shared a for the service(s) and characteristic(s) to intercommunicate between the peripheral & central.

For the purposes of documentation, the following constants will be shared across the configuration examples

let dataServiceUUIDKey                  = "3C215EBB-D3EF-4D7E-8E00-A700DFD6E9EF"
let dataServiceCharacteristicUUIDKey    = "830FEB83-C879-4B14-92E0-DF8CCDDD8D8F"

If you are not familiar with how BLE works, please review the Core Bluetooth Programming Guide before continuing.

Peripheral Manager

In it's simplest form, the following is an example of how to configure peripheral using a simple blocks based syntax.

peripheral = ExtendaBLE.newPeripheralManager { (manager) in

    manager.addService(dataServiceUUIDKey) { (service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write]).permissions([.readable, .writeable])
        }
    }
}

Begin Advertising

To start advertising services and their respective characteristics, just call on startAdvertising() on the peripheral created in the prior section.

peripheral?.startAdvertising()

Responding to Updates

If you would like to respond to characteristic updates on the peripheral when a central updates a value, define an onUpdate { (data, error) in } per characteristic accordingly. When the Central finishes updating the value, the callback will be triggered.

peripheral = ExtendaBLE.newPeripheralManager { (manager) in
    manager.addService(dataServiceUUIDKey) { (service) in

        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write, .notify]).permissions([.readable, .writeable])                

            characteristic.onUpdate { (data, error) in
                /* Called whenever the value is updated by the CENTRAL */
            }
        }
    }
}

Notifying Central

If you would like the peripheral to retain a connection for a specific characteristic, and notify the connected central manager when the value is updated, when configuring the properties, ensure to include the .notify CBCharacteristicProperty in the definition as follows.

peripheral = ExtendaBLE.newPeripheralManager { (manager) in

    manager.addService(dataServiceUUIDKey) { (service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write, .notify]).permissions([.readable, .writeable])
        }
    }
}

Central Manager

In it's simplest form, the following is an example of how to configure central manager using a simple blocks based syntax.

central = ExtendaBLE.newCentralManager { (manager) in

    manager.addService(dataServiceUUIDKey) {(service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write]).permissions([.readable, .writeable])
        }
    }
}

Begin Scanning

Start scanning for peripheral(s) defined with the services, and their respective characteristics, just call on startScan() on the central created in the prior section. The central will auto connect to the peripheral when found.

central?.startScan()

Responding to State Changes

Responding to stages of the scanning operation, the following callbacks can be defined for the manager.

central = ExtendaBLE.newCentralManager { (manager) in

    manager.addService(dataServiceUUIDKey) {(service) in
        /* Characteristic Definitions */
    }.onPeripheralConnectionChange{ (connected, peripheral, error) in
        /* Respond to Successful Connection */
    }.onDidDiscover { (central, advertisementData, rssi) in
        /* Respond to Discovered Services */
    }.onStateChange { (state) in
        /* Respond to State Changes */
    }
}

Respond to Successful Connection

To perform a Read/Write upon connecting to a peripheral, define a callback as follows to be notified of the successful connection.

central = ExtendaBLE.newCentralManager { (manager) in

    manager.addService(dataServiceUUIDKey) {(service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write]).permissions([.readable, .writeable])
        }
    }.onPeripheralConnectionChange{ (connected, peripheral, error) in
        /* Perform Read Transaction upon connecting */
    }
}

Responding to Update Notification

If you would like to retain a connection for a specific characteristic, and be notified by the peripheral when the value is updated, when configuring the properties, ensure to include the .notify CBCharacteristicProperty in the definition as follows, and create a call back to respond to the change.

central = ExtendaBLE.newCentralManager { (manager) in

    manager.addService(dataServiceUUIDKey) {(service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write, .notify]).permissions([.readable, .writeable])

            characteristic.onUpdate { (data, error) in
                /* Called whenever the value is updated by the PERIPHERAL */
            }
        }
    }
}

Perform Write

To perform a write for a specific characteristic for a connected peripheral, call the write(..) on the central, and with the content to write, and the characteristicUUID to write to. The callback will be triggered once the write is complete.

central?.write(data: stringData, toUUID: dataServiceCharacteristicUUIDKey) { (writtenData, error) in    

    /* Do something upon successful write operation */
}

Perform Read

To perform a read for a specific characteristic for a connected peripheral, call the read(..) on the central, and with the characteristicUUID to read. The callback will be triggered once the read is complete with the Data read, or an error if the operation failed.

central?.read(characteristicUUID: dataServiceCharacteristicUUIDKey) { (returnedData, error) in
    let valueString = String(data: returnedData!, encoding: .utf8)?

    /* Do something upon successful read operation */  
}

Packet Based Communication

BLE has a limitation as to how much data can be sent between devices relative to the MTU size. To enabled the ability for the central and peripheral to communicate characteristic data greater in size than this limitation, ExtendaBLE provides the ability to use packets to breakup and rebuild the data when communicating between devices.

To enable the ability to send data greater than the MTU limitation of BLE, set the packetsEnabled to true on both the peripheral and the central. This will ensure that when communications occurs, the data is broken up into individual packets which will be sent across and rebuilt once the operation is complete.

peripheral = ExtendaBLE.newPeripheralManager { (manager) in

    manager.addService(dataServiceUUIDKey) { (service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write])
            characteristic.permissions([.readable, .writeable])
            characteristic.packetsEnabled(true)
        }
    }
}

central = ExtendaBLE.newCentralManager { (manager) in

    manager.addService(dataServiceUUIDKey) {(service) in
        service.addCharacteristic(dataServiceCharacteristicUUIDKey) { (characteristic) in
            characteristic.properties([.read, .write])
            characteristic.permissions([.readable, .writeable])     
            characteristic.packetsEnabled(true)
        }
    }
}

Extracting Data from Byte Stream

When communicating reading from physical peripheral, generally the specifications will return a byte stream, and will identify where different types of data are located, and it is up to the developer to extract and covert specific parts of the returned data. With ExtendaBLE and extension is included to easily extract data from such streams. The following methods can be called on the returned Data instance with a specified start index to extract the following types of data.

public func int8Value(atIndex : Int) -> Int8?
public func int16Value(atIndex : Int) -> Int16?
public func int32Value(atIndex : Int) -> Int32?
public func int64Value(atIndex : Int) -> Int64?
public func uint8Value(atIndex : Int) -> UInt8?
public func uint16Value(atIndex : Int) -> UInt16?
public func uint32Value(atIndex : Int) -> UInt32?
public func uint64Value(atIndex : Int) -> UInt64?
public func stringValue(atIndex : Int) -> String?

If finer control is needed, ranges can be used to extract specific data from the stream as follows.

public func int8Value(inRange range : Range<Data.Index>) -> Int8?
public func int16Value(inRange range : Range<Data.Index>) -> Int16?
public func int32Value(inRange range : Range<Data.Index>) -> Int32?
public func int64Value(inRange range : Range<Data.Index>) -> Int64?
public func uint8Value(inRange range : Range<Data.Index>) -> UInt8?
public func uint16Value(inRange range : Range<Data.Index>) -> UInt16?
public func uint32Value(inRange range : Range<Data.Index>) -> UInt32?
public func uint64Value(inRange range : Range<Data.Index>) -> UInt64?
public func doubleValue(inRange range : Range<Data.Index>) -> Double?
public func floatValue(inRange range : Range<Data.Index>) -> Float?
public func stringValue(inRange range : Range<Data.Index>) -> String?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].