All Projects → aritchie → Bluetoothle

aritchie / Bluetoothle

Licence: mit
Easy to use, cross platform, REACTIVE BluetoothLE Plugin for Xamarin

Projects that are alternatives of or similar to Bluetoothle

Ble.net
Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP
Stars: ✭ 137 (-61.62%)
Mutual labels:  ble, bluetooth-le, xamarin
Ble
Connect to and interact with Bluetooth LE peripherals.
Stars: ✭ 156 (-56.3%)
Mutual labels:  ble, bluetooth-le
Ios Pods Dfu Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 349 (-2.24%)
Mutual labels:  ble, bluetooth-le
Node Ble
Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
Stars: ✭ 159 (-55.46%)
Mutual labels:  ble, bluetooth-le
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 (-75.35%)
Mutual labels:  ble, bluetooth-le
Extendable
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Stars: ✭ 88 (-75.35%)
Mutual labels:  ble, bluetooth-le
Easyble
Android BLE framework
Stars: ✭ 155 (-56.58%)
Mutual labels:  ble, bluetooth-le
ESP32 BLE OTA Arduino
OTA update on ESP32 via BLE
Stars: ✭ 41 (-88.52%)
Mutual labels:  ble, bluetooth-le
bluetooth
Android Bluetooth examples
Stars: ✭ 80 (-77.59%)
Mutual labels:  ble, bluetooth-le
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (-83.19%)
Mutual labels:  ble, bluetooth-le
Shiny
A Xamarin Framework for Backgrounding & Device Hardware Services (iOS, Android, UWP, Tizen, tvOS, watchOS, & more coming soon)
Stars: ✭ 763 (+113.73%)
Mutual labels:  ble, xamarin
IOS-DFU-Library
OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
Stars: ✭ 400 (+12.04%)
Mutual labels:  ble, bluetooth-le
Esp32 Ble Keyboard
Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 533 (+49.3%)
Mutual labels:  ble, bluetooth-le
Nimble Arduino
A fork of the NimBLE library structured for compilation with Ardruino, designed for use with ESP32.
Stars: ✭ 108 (-69.75%)
Mutual labels:  ble, bluetooth-le
Android Dfu Library
A library with DFU feature for Android 4.3+.
Stars: ✭ 532 (+49.02%)
Mutual labels:  ble, bluetooth-le
Android Scanner Compat Library
A compat library for Bluetooth Low Energy scanning on Android.
Stars: ✭ 462 (+29.41%)
Mutual labels:  ble, bluetooth-le
Xamarin Bluetooth Le
Bluetooth LE plugin for Xamarin
Stars: ✭ 419 (+17.37%)
Mutual labels:  ble, xamarin
Esp32 Ble Mouse
Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 180 (-49.58%)
Mutual labels:  ble, bluetooth-le
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 (-96.08%)
Mutual labels:  ble, bluetooth-le
Rxandroidble
An Android Bluetooth Low Energy (BLE) Library with RxJava2 interface
Stars: ✭ 3,025 (+747.34%)
Mutual labels:  ble, bluetooth-le

UPDATE - This library is moving to the Shiny Framework at https://github.com/shinyorg/shiny Support will remain until Shiny is out of beta

ACR Reactive BluetoothLE Plugin

Easy to use, cross platform, REACTIVE BluetoothLE Plugin for ALL platforms!

SUPPORT THIS PROJECT

Change Log - November 17, 2018

NuGet Build status

PLATFORMS

Platform Version
Android 4.3+
iOS 7+
macOS Latest
tvOS Latest
Windows UWP 16299+

UWP is still in beta!

  • Client cannot disconnect
  • Server WIP
  • PRs only during beta please!

FEATURES

  • Scan for advertisement packets and devices (with full control of the scanning features)
  • Monitor adapter status (and control it on android)
  • Open Bluetooth settings screen
  • Persistent connections
  • Deals with the Android threading and defect headaches
  • Discover services, characteristics, & descriptors
  • Read, write, & receive notifications for characteristics
  • Support for reliable write transactions
  • Read & write descriptors
  • Request & monitor MTU changes
  • Connect to heart rate monitors
  • Deals with most of the Android fubars
  • Manages iOS backgrounding by allowing hooks to WhenWillRestoreState
  • Control the adapter state on Android
  • Pair with devices
  • GATT Server and Advertising Support
    • Advertising
      • Manufactuer Data
      • Service UUIDs
    • Charactertistics
      • Read
      • Write
      • Notify & Broadcast
      • Manage Subscribers
      • Status Replies
  • Android Issues
    • We manage the GATT 133 (mostly, hopefully)
    • Don't like the serial way you have to work with BLE, don't worry, we cover that too. Read/Write away!
    • Don't know what thread to run a method on? Don't worry - we got that covered.... just make the read/write call and relax

SETUP

Be sure to install the Plugin.BluetoothLE nuget package in all of your main platform projects as well as your core/NETStandard project

NuGet

Android

Add the following to your AndroidManifest.xml PLEASE NOTE THAT YOU HAVE TO REQUEST THESE PERMISSIONS USING Activity.RequestPermission or a Plugin

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<!--this is necessary for Android v6+ to get the device name and address-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

iOS

If you want to use background BLE periperhals, add the following to your Info.plist

<key>UIBackgroundModes</key>
<array>
    <!--for connecting to devices (client)-->
	<string>bluetooth-central</string>

    <!--for server configurations if needed-->
	<string>bluetooth-peripheral</string>
</array>

<!--To add a description to the Bluetooth request message (on iOS 10 this is required!)-->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string>

HOW TO USE - CLIENT BASICS

// discover some devices
CrossBleAdapter.Current.Scan().Subscribe(scanResult => {});

// Once finding the device/scanresult you want
scanResult.Device.Connect();

Device.WhenAnyCharacteristicDiscovered().Subscribe(characteristic => {
    // read, write, or subscribe to notifications here
    var result = await characteristic.Read(); // use result.Data to see response
    await characteristic.Write(bytes);

    characteristic.EnableNotifications();
    characteristic.WhenNotificationReceived().Subscribe(result => {
    	//result.Data to get at response
    });
});

HOW TO USE - SERVER BASICS

Most important things - you should setup all of your services and characteristics BEFORE you Start() the server!

var server = CrossBleAdapter.Current.CreateGattServer();
var service = server.AddService(Guid.NewGuid(), true);

var characteristic = service.AddCharacteristic(
    Guid.NewGuid(),
    CharacteristicProperties.Read | CharacteristicProperties.Write | CharacteristicProperties.WriteWithoutResponse,
    GattPermissions.Read | GattPermissions.Write
);

var notifyCharacteristic = service.AddCharacteristic
(
    Guid.NewGuid(),
    CharacteristicProperties.Indicate | CharacteristicProperties.Notify,
    GattPermissions.Read | GattPermissions.Write
);

IDisposable notifyBroadcast = null;
notifyCharacteristic.WhenDeviceSubscriptionChanged().Subscribe(e =>
{
    var @event = e.IsSubscribed ? "Subscribed" : "Unsubcribed";

    if (notifyBroadcast == null)
    {
        this.notifyBroadcast = Observable
            .Interval(TimeSpan.FromSeconds(1))
            .Where(x => notifyCharacteristic.SubscribedDevices.Count > 0)
            .Subscribe(_ =>
            {
                Debug.WriteLine("Sending Broadcast");
                var dt = DateTime.Now.ToString("g");
                var bytes = Encoding.UTF8.GetBytes(dt);
                notifyCharacteristic.Broadcast(bytes);
            });
    }
});

characteristic.WhenReadReceived().Subscribe(x =>
{
    var write = "HELLO";

    // you must set a reply value
    x.Value = Encoding.UTF8.GetBytes(write);

    x.Status = GattStatus.Success; // you can optionally set a status, but it defaults to Success
});
characteristic.WhenWriteReceived().Subscribe(x =>
{
    var write = Encoding.UTF8.GetString(x.Value, 0, x.Value.Length);
    // do something value
});

await server.Start(new AdvertisementData
{
    LocalName = "TestServer"
});

DOCUMENTATION

FAQ

Q. Why is everything reactive instead of events/async

I wanted event streams as I was scanning devices. I also wanted to throttle things like characteristic notification feeds. Lastly, was the proper cleanup of events and resources.

Q. Why are Device.Connect, Characteristic.Read, and Descriptor.Read observable when async would do just fine?

True, but observables with RX are actually awaitable as well and far easier to chain into other things.

Q. Why are devices cleared on a new scan?

Some platforms yield a "new" device and therefore new hooks. This was observed on some android devices.

Q. My characteristic read/writes/notifications are not working

If you store your discovered characteristics in your own variables, make sure to refresh them with each (re)connect

Q. I cannot see the device name in Android 6+

You need to enable permissions for android.permission.ACCESS_COARSE_LOCATION

Q. I cannot see the device name when scanning in the background on iOS

This is the work of iOS. The library cannot fix this. You should scan by service UUIDs instead

Q. Does this support Bluetooth v2?

No - please read about bluetooth specifications before using this library. LE (Low Energy) is part of the v4.0 specification.

Q. Why can't I disconnect devices selectively in the GATT server?

On android, you can, but exposing this functionality in xplat proves challenging since iOS does not support A LOT of things

Q. Why can't I configure the device name on Android?

Please read the advertising docs on this

GENERAL RULES TO FOLLOW

  • DO NOT reuse services, characteristics, and descriptors between connnections
  • DO catch errors in your subscriptions (ie. Reads/Writes)
  • DO set timeouts on all connected operations using Observable.Timeout(TimeSpan). Timeout throws errors that you must also manage!
  • DO NOT manage reconnection yourself
  • DO NOT scan with the adapter while you have an open GATT connection
  • If you have a TX/RX setup using Notify/Write, use 2 characteristics, not one

CONTRIBUTORS

Thank you for all your help

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].