Giter Site home page Giter Site logo

victorqiu / bluetoothle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aritchie/bluetoothle

0.0 2.0 0.0 3.26 MB

Easy to use, cross platform, REACTIVE BluetoothLE Plugin for Xamarin (Windows UWP COMING SOON)

License: MIT License

C# 99.85% Batchfile 0.15%

bluetoothle's Introduction

ACR Reactive BluetoothLE Plugin for Xamarin

Easy to use, cross platform, REACTIVE BluetoothLE Plugin for iOS, Android, macOS & tvOS

Please note that v2.0 of this plugin has had its namespace and assembly renamed to Plugin.BluetoothLE. If you are having any difficulties with the install, uninstall Acr.Ble and continue with the Plugin.BluetoothLE nuget package

NuGet

Change Log - Jan 19, 2017

PLATFORMS

  • Android 4.3+
  • iOS 7+
  • macOS
  • tvOS
  • Windows UWP (COMING SOON)

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
  • 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

SETUP

Be sure to install the Acr.Ble nuget package in all of your main platform projects as well as your core/PCL project

NuGet

Android

Add the following to your AndroidManifest.xml

<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_COARSE_LOCATION" />

iOS

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

<array>
<string>bluetooth-central</string>
</array>

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

HOW TO USE BASICS

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

// Once finding the device/scanresult you want
await 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.SubscribeToNotifications(result => {
    	//result.Data to get at response
    });
});

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

bluetoothle's People

Contributors

aritchie avatar ajay-chacko avatar ndazeo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.