Giter Club home page Giter Club logo

xamarin.bluetoothle's People

Contributors

centrolutions avatar rlingineni avatar tbrushwyler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xamarin.bluetoothle's Issues

Android Device Mac Adress

Hi,
I have looked your repo but I have searched bluetooth devices and write to console device's ids. But this id is not equal bluetooth device's mac id. How can I know it ?

Thanks...

Unhandled exceptions

03-07 09:10:49.677 I/MonoDroid(23827): System.NullReferenceException: Object reference not set to an instance of an object.
03-07 09:10:49.677 I/MonoDroid(23827): at BluetoothLE.Droid.Adapter.PerformConnectToDevice (BluetoothLE.Core.IDevice device) [0x00044] in <86b8b586902b43919ef4ac9afb698628>:0
03-07 09:10:49.677 I/MonoDroid(23827): at BluetoothLE.Droid.Adapter+c__AnonStorey1.<>m__0 () [0x00000] in <86b8b586902b43919ef4ac9afb698628>:0
03-07 09:10:49.677 I/MonoDroid(23827): at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/9578cdcd/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
03-07 09:10:49.677 I/MonoDroid(23827): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.IRunnable.cs:81
03-07 09:10:49.677 I/MonoDroid(23827): at (wrapper dynamic-method) System.Object:d24b8eca-219c-4236-a49c-7f1db546a4b5 (intptr,intptr)

This is when attempting to connect to a device.

try { App.BluetoothAdapter.ConnectToDevice(device); } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); }

Is there at least some way to handle the exception? It is not caught by that try/catch block.

How to set Connection parameters for BLE device

Can we specify connection parameters like connection interval, connection event, etc to increase the throughput of the BLE device, using Xamarin.BluetoothLE library? CharacteristicPropertyType do not have these properties.

[feature request] Manufacturer raw advertising data

Thanks for this library. Its been very helpful.

Have you thought of exposing the raw manufacturer advertising data? Devices can send up to around 30 bytes of data in the end of the advertising packet which it useful for beacons or sensors and allows streaming data to many devices without making a connection. If I get back onto this in the future I'll have a go at implementing it but I'm currently without a Mac so would be android only initially.

No devices discovered

My project works but when i call App.BluetoothAdapter.StartScanningForDevices(); never discover a device. i have a ScanTimeoutElapsed event this works
`using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Xamarin.Forms;
using BluetoothLE.Core;
using BluetoothLE.Core.Events;
using System.Collections.ObjectModel;

namespace diagnostic_xam
{
public partial class diagnostic_xamPage : ContentPage
{
Button actionButton;
String status = "Waiting";

	public ObservableCollection<IDevice> DiscoveredDevices { get; private set; }

	public diagnostic_xamPage()
	{
		InitializeComponent();

	}

	protected override void OnAppearing()
	{
		base.OnAppearing();
		//initBluetoothSearch();
	}

	public void OnButtonClicked(object sender, EventArgs args)
	{

		actionButton = (Button)sender;
		switch (status)
		{
			case "Waiting":
				actionButton.Text = "Cancelar";
				status = "Searching";
				initBluetoothSearch();
				break;
			case "Searching":
				actionButton.Text = "Buscar";
				status = "Waiting";
				break;
			case "Finish":
				actionButton.Text = "Cancelar";
				status = "Searching";
				initBluetoothSearch();
				break;
				
		}
	}

	public void initBluetoothSearch()
	{
		
		DiscoveredDevices = new ObservableCollection<IDevice>();
		deviceListView.ItemsSource = DiscoveredDevices;
		deviceListView.ItemSelected += DeviceSelected;

		App.BluetoothAdapter.DeviceDiscovered += DeviceDiscovered;
		App.BluetoothAdapter.DeviceConnected += DeviceConnected;
		App.BluetoothAdapter.DeviceDisconnected += DeviceDisconnected;
		App.BluetoothAdapter.ScanTimeoutElapsed += ScanTimeoutElapsed;

		App.BluetoothAdapter.StartScanningForDevices();
	}

	void DeviceSelected(object sender, SelectedItemChangedEventArgs e)
	{
		var device = e.SelectedItem as IDevice;
		if (device != null)
		{
			App.BluetoothAdapter.ConnectToDevice(device);
		}
	}

	#region BluetoothAdapter callbacks

	void DeviceDiscovered(object sender, DeviceDiscoveredEventArgs e)
	{
		DiscoveredDevices.Add(e.Device);
		actionButton.Text = "Actualizar";
		status = "Finish";
		DisplayAlert("Dispositivo decubierto", "nuevo dispositivo decubierto: "+e.Device.Name, "Aceptar");
	}

	void DeviceConnected(object sender, DeviceConnectionEventArgs e)
	{
		DisplayAlert("Dispositivo conectado", "conectado a: " + e.Device.Name, "Aceptar");
		App.currentDevice = e.Device;
		Navigation.PushModalAsync(new MasterDetail());
	}

	void DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
	{
		//disconected device
	}

	void ScanTimeoutElapsed(object sender, EventArgs e)
	{
		actionButton.Text = "Buscar";
		status = "Waiting";
	}

	#endregion
}

}`

crash selecting device

Hello, trying the sample with a bluetooth hearth rate strap (Polar H7) the sample crash selecting the device, with this exception:
Loaded assembly: System.Diagnostics.Debug.dll [External]
01-20 19:02:37.319 D/BluetoothAdapter(21755): stopLeScan()
01-20 19:02:37.321 D/BluetoothAdapter(21755): STATE_ON
01-20 19:02:45.314 D/BluetoothGatt(21755): discoverServices() - device: 00:22:D0:E1:A2:C6
01-20 19:02:47.665 W/art (21755): JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.Platform_DefaultRenderer
01-20 19:02:47.675 W/art (21755): JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.LabelRenderer
01-20 19:02:54.388 D/BluetoothGatt(21755): onSearchComplete() = Device=00:22:D0:E1:A2:C6 Status=0
01-20 19:02:54.419 D/Mono (21755): DllImport searching in: '__Internal' ('(null)').
01-20 19:02:54.419 D/Mono (21755): Searching for 'java_interop_jnienv_call_boolean_method'.
01-20 19:02:54.419 D/Mono (21755): Probing 'java_interop_jnienv_call_boolean_method'.
01-20 19:02:54.419 D/Mono (21755): Found as 'java_interop_jnienv_call_boolean_method'.
Unhandled Exception:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

01-20 19:02:57.667 E/mono-rt (21755): Stacktrace:
01-20 19:02:57.667 E/mono-rt (21755):
01-20 19:02:57.667 E/mono-rt (21755): /proc/self/maps:
01-20 19:02:57.667 E/mono-rt (21755): 12c00000-12cfa000 rw-p 00000000 00:01 22867 /dev/ashmem/dalvik-main space (deleted)
01-20 19:02:57.667 E/mono-rt (21755): 12cfa000-12d7e000 rw-p 000fa000 00:01 22867 /dev/ashmem/dalvik-main space (deleted)
...

Can you help me?

Send Message to Bluetooth device

I am having issues with sending to the device to receive data. I believe this is the equivalent of writing a value to a characteristic and then updating the value. I have the following code and output but still can not seem to send the byte[] data to the device.

`static void CharacteristicDiscovered(object sender, CharacteristicDiscoveredEventArgs e)
{
var characteristic = e.Characteristic;
if (characteristic.CanWrite)
{
byte[] testData = Encoding.UTF8.GetBytes("U");
characteristic.Write(testData);

        }
        if(characteristic.CanRead)
        {
            characteristic.Read();
        }
        if (characteristic.CanUpdate)
        {
            byte[] testData = Encoding.UTF8.GetBytes("U");
            characteristic.Write(testData);
            characteristic.StartUpdates();
            characteristic.ValueUpdated += CharacteristicValueUpdated;
        }

    }`

This all seems to hit and i get this in output
12-02 12:43:29.007 D/BluetoothGatt(27258): setCharacteristicNotification() - uuid: 2456e1b9-26e2-8f83-e744-f34f01e9d703 enable: true
12-02 12:43:29.708 D/BluetoothGatt(27258): setCharacteristicNotification() - uuid: 2456e1b9-26e2-8f83-e744-f34f01e9d703 enable: true
12-02 12:43:41.920 D/BluetoothGatt(27258): setCharacteristicNotification() - uuid: 2456e1b9-26e2-8f83-e744-f34f01e9d704 enable: true
12-02 12:43:43.051 D/BluetoothGatt(27258): setCharacteristicNotification() - uuid: 2456e1b9-26e2-8f83-e744-f34f01e9d704 enable: true
12-02 12:43:43.922 D/BluetoothGatt(27258): onSearchComplete() = Device=D4:CA:6E:B0:46:3E Status=0

But the
static void CharacteristicValueUpdated(object sender, CharacteristicReadEventArgs e) { }
is never hit. Am I missing a piece or doing this wrong? Again I am trying to send a "U" message from my app to the Bluetooth device in order for the device to send the app a string message

Android read queue

I'm finding BT on Android predictably terrible. Reading a characteristic is an asynchronous operation, but you can't have more than one in-flight at once. So if you rapidly request multiple characteristics be read, only one will succeed.

The accepted workaround for this is a queue that is drained only as OnCharacteristicRead is called on the GATT callback. Unfortunately, knowing when this occurs is difficult with Xamarin.BluetoothLE because it forwards that call onto all characteristics and only the relevant characteristic propagates the call as an event.

Would it make sense to have an IDevice.CharacteristicRead event that fires for all characteristics for that device? That way, I could hook into that event to know when to request the next read.

Programmatic Pairing

Hi,

Is there any way to programatically implement pairing with this module?

Regards

uuid does not match

The debug output said "uuids does not match" on my xiaomi note 4 (Android 6.0)
while it runs smooth without problems on xiami note 1 (Android 4.4)

D/BluetoothAdapter(30617): uuids does not match

Exception: Index was out of range.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

I got the above exception when i am trying to run the sample app on Android 4.4.2. Ans not able to track it.

Difference from xamarin-bluetooth-le?

First of all, cool that you're extending Xamarin!

Since there are different projects on BLE for Xamarin now, I'm wondering how you see your own project compared to https://github.com/xabre/xamarin-bluetooth-le?

Why did you choose to create your own library / why should people choose this library over another library?

It would be helpful for newcomers to see the differences to choose more easily.

Notification subscription

notifications doesn't write back

change line 183 of BluetoothLE.droid.Charicteristics.cs
if (descriptor == null || !descriptor.SetValue(value.ToArray()) || !_gatt.WriteDescriptor(descriptor))

DiscoverServices() giving null pointer

Once I am calling the function: DiscoverServices(); My app, automatically breaks giving a Null Pointer Exception.
I've made sure that the variable device is not null.

My problem is that I cannot debug through the code of the function, so I don't know what is the object that returns null.

I can connect to the device and disconnect, but I cannot find its services.
My device is an HC-05 Bluetooth device and I am working with Windows 10 and Android API 23.

This is my code:

using BluetoothLE.Core;
using BluetoothLE.Core.Events;
using Xamarin.Forms;

{...}
    public partial class DeviceTerminal : ContentPage
    {
        IDevice device;
        IAdapter adapter;
        public ObservableCollection<Grouping<IService, ICharacteristic>> DiscoveredServices { get; private set; }

        public DeviceTerminal(IAdapter adap, IDevice dev)
        {
            this.device = dev;
            this.adapter = adap;

            Debug.WriteLine("State of the device: " + (string)device.Name + " is: " + device.State.ToString());
            InitializeComponent();

            device.ServiceDiscovered += ServiceDiscovered;

// --------- It crashes here -------------
            **device.DiscoverServices();**

            //Device disconnects for X reason
            adapter.DeviceDisconnected += DeviceDisconnected;

        }

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.