Giter Site home page Giter Site logo

nexussays / ble.net Goto Github PK

View Code? Open in Web Editor NEW
180.0 180.0 51.0 413 KB

Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP

License: Mozilla Public License 2.0

C# 100.00%
android ble bluetooth bluetooth-le bluetooth-low-energy csharp dotnet dotnet-standard ios uwp xamarin

ble.net's People

Contributors

nexussays 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

ble.net's Issues

Can't connect to Gatt server on Raspberry Pi from Android

I am running a sample Gatt server on my Raspberry Pi 3 (built from this advertisement python and this gatt server python. I have found that I can successfully connect from my Android 7.0 device to the Gatt server and inspect the characteristics using Nordic Semiconductor's nRF Connect app (from the Google Play Store). I can write values and even receive notifications.

When I use ble.net, my device does appear in the scan list, only I can't connect to it. I've included debug text from my VS2015 showing the scan process and the failed connection. Have you ever had any luck connecting to a RPi?

debug.txt

NexusUtils.build not found BLE.net UWP

I can't install the UWP package due to Nexus.utils.build not being found, i've got the BLE.net core and the Nexus.core NuGet packages installed.

When manually searching for the package in NuGet i end up on a 404'd page.

  • install-package ble.net-uwp
  •   + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
      + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
    
    

install-package : Unable to resolve 'nexus.utils.build (>= 0.1.15)' for 'UAP,Version=v10.0.10586 (win10-x86-aot)'.
At line:1 char:1

  • install-package ble.net-uwp
  •   + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
      + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
    
    

install-package : Package restore failed. Rolling back package changes for 'bluetooth TestApplet'.
At line:1 char:1

Problem with Scanning on iOS

I am trying to get this to work with iOS on a PCL library. I use dependency injection to get a reference to the Bluetooth adapter. However, my scan never produces any results. I have a BLE device that I can easily ask to send notifications, and it shows up on other BLE scanning apps. However, my code reports no successes. Here is my code:

await BLEAdapter.ScanForBroadcasts((IBlePeripheral peripheral) => {
                // peripheral.Advertisement. // Services // DeviceName
                Debug.WriteLine($"Scan Result: {peripheral.DeviceId} / {peripheral.Advertisement.DeviceName}");
});
Debug.WriteLine("Finished scanning");

I put a breakpoint on the Debug.WriteLine but it never gets called. The ScanForBroadcasts gets called, and I get "Finished Scanning" after about 10-15 seconds. But it seems to never pick up my devices.

I have added in my plist file:

<key>UIBackgroundModes</key>
	<array>
		<string>location</string>
		<string>bluetooth-central</string>
		<string>fetch</string>
	</array>

But this does not seem to help, either. Any ideas? I'm not getting any errors, just no connections.

NSBluetoothPeripheralUsageDescription

Question:

Do you need to add this in info.plist file for iOS? I have not been using it and never go any problems? If i use it, when does the user get the question and how do you check the answer (if no i guess you need to handle it)?

NSBluetoothPeripheralUsageDescription
[MyAppNameHere] would like to use bluetooth.

Rssi measurement

In IBlePeripheral.cs you mention RSSI is measured in decibels (dB). Is this true? or is it measured in dBm?

/// Received signal strenth indicator, in decibels

Support for Profile24 PCL

Beeing new to this I fail to install bel.net into a new project in VS2017.
From NuGet package manager I get the following message:

Could not install package 'ble.net 1.0.0-beta0007'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile24', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Any hints how to fix this?

btw: Loading, compiling, running and modifying the sample project works fine for me!

Problem to connect or discover services

Hi!
I have som trouble with connect to a device, both on iOS and Android. It usaly will work well for a period but then just stop working. Its two diffrent problem, i cant connect at all (have 30 sek timeout) or i can connect but it seems that phone cant discover services/characteristics. On Android this problem wont stop until i restart phone or device (or bluetooth). On iOS it usally work after one failed atempt. Also on iOS i only get problem nr one. On Androids it is both of the problem above.

I have the feeling that the problems start after switching and try to connect with a diffrent phone. Like first i connect with a Android and it work, but then i try to connect with iOS and after that i cant connect with android.
But sometimes it happens even if i dont switch phones.

Can it be some problem with disconnecting? To disconnect i do a Dispose() on the connection. Do i also need to reset the bleadapter in some way? Like Set the bleadapter to null and get the default adapter again?
Also, i have read that to disconnect you need to both do .disconnect() and the after a delay do .close(). Is this being done in the lib?

Also i have activated notifyes, do i need to dispose these when disconecting?

I have nuget 1.0 beta installed and have tested on iPhone 7 ios 11.x. On android i have tested on Sony z5 7.1, a HTC 4.3 and a Huawei 7.1

I am very glad for this lib and i need it for a comersial app that we build so i hope that i can get it to work without connect-problems.

Open source

Hi!
Is the the iOS- and Android-code for this lib open source? If not, is it possible to make it open source?

Repeatedly Scan a single Beacon

Hi @nexussays ,

I am trying to scan for a single beacon repeatedly as the AdvertisementData keeps changing on an interval. How can this be achieved?

I am doing this but scanning occurs only once.
var a = new ScanFilter.Factory { IgnoreRepeatBroadcasts = false };
await adapter.ScanForBroadcasts(a,(IBlePeripheral peripheral) =>

Support characteristic Indicate

I am trying to integrate with a device that provides updates on a service's characteristic. The characteristic has properties 0x22 (Read, Indicate). When I call

gattServer.NotifyCharacteristicValue(TemperatureServiceUuid, asciiTempCharacteristicGuid,  
  bytes => {
  string asText = System.Text.Encoding.UTF7.GetString(bytes);
  }

I get no errors, exceptions or callbacks. I am guessing this is because you don't currently support Indications. Is there any way to work around this or add a quick implementation?

Help building from source

Help help help....I know prob something wrongly setup on my side but please anyone can help on me being able to compile form fresh install and get smoothly to the next stage? I cannot get through the full rebuilt solution, many errors like as per the following:

Thanks/Florent

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0115	'BleGattServerPage.OnBackButtonPressed()': no suitable method found to override	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\BleGattServerPage.xaml.cs	25	Active
Error	CS0115	'FormsApp.OnStart()': no suitable method found to override	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\FormsApp.xaml.cs	65	Active
Error	CS0115	'LogsPage.OnBindingContextChanged()': no suitable method found to override	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\LogsPage.xaml.cs	23	Active
Error	CS1729	'object' does not contain a constructor that takes 0 arguments	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	8	Active
Error		Build action 'EmbeddedResource' is not supported by one or more of the project's targets.	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\FormsApp.xaml	0	
Error		Build action 'EmbeddedResource' is not supported by one or more of the project's targets.	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\BleDeviceScannerPage.xaml	0	
Error		Build action 'EmbeddedResource' is not supported by one or more of the project's targets.	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\BleGattServerPage.xaml	0	
Error		Build action 'EmbeddedResource' is not supported by one or more of the project's targets.	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\BleGattServicePage.xaml	0	
Error		Build action 'EmbeddedResource' is not supported by one or more of the project's targets.	ble.net.sampleapp	C:\Test\ble.net-master\src\ble.net.sampleapp\view\LogsPage.xaml	0	
Error		Cannot resolve Assembly or Windows Metadata file 'System.Runtime.dll'	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\ble.net.sampleapp-uwp.csproj		
Error	CS0006	Metadata file 'C:\Test\ble.net-master\artifacts\bin\ble.net.sampleapp\Debug\AnyCPU\ble.net.sampleapp.dll' could not be found	ble.net.sampleapp-ios	C:\Test\ble.net-master\src\ble.net.sampleapp-ios\CSC	1	Active
Error	CS0518	Predefined type 'System.Boolean' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	14	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	6	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	10	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0518	Predefined type 'System.Object' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	4	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	5	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	6	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	7	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	8	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	9	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	10	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	11	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	12	Active
Error	CS0518	Predefined type 'System.String' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	13	Active
Error	CS0518	Predefined type 'System.Void' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	8	Active
Error	CS0518	Predefined type 'System.Void' is not defined or imported	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error		The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'ble.net.sampleapp, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'ble.net.sampleapp.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	ble.net.sampleapp-android			
Error		The name "WindowsPage" does not exist in the namespace "using:Xamarin.Forms.Platform.UWP".	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml	1	
Error	CS0103	The name 'BluetoothLowEnergyAdapter' does not exist in the current context	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0103	The name 'InitializeComponent' does not exist in the current context	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	10	Active
Error	CS0103	The name 'LoadApplication' does not exist in the current context	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0103	The name 'UserDialogs' does not exist in the current context	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	12	Active
Error	CS0246	The type or namespace name 'Acr' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	1	Active
Error	CS0246	The type or namespace name 'AssemblyCompany' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	7	Active
Error	CS0246	The type or namespace name 'AssemblyCompanyAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	7	Active
Error	CS0246	The type or namespace name 'AssemblyConfiguration' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	6	Active
Error	CS0246	The type or namespace name 'AssemblyConfigurationAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	6	Active
Error	CS0246	The type or namespace name 'AssemblyCopyright' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	9	Active
Error	CS0246	The type or namespace name 'AssemblyCopyrightAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	9	Active
Error	CS0246	The type or namespace name 'AssemblyCulture' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	11	Active
Error	CS0246	The type or namespace name 'AssemblyCultureAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	11	Active
Error	CS0246	The type or namespace name 'AssemblyDescription' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	5	Active
Error	CS0246	The type or namespace name 'AssemblyDescriptionAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	5	Active
Error	CS0246	The type or namespace name 'AssemblyFileVersion' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	13	Active
Error	CS0246	The type or namespace name 'AssemblyFileVersionAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	13	Active
Error	CS0246	The type or namespace name 'AssemblyProduct' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	8	Active
Error	CS0246	The type or namespace name 'AssemblyProductAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	8	Active
Error	CS0246	The type or namespace name 'AssemblyTitle' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	4	Active
Error	CS0246	The type or namespace name 'AssemblyTitleAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	4	Active
Error	CS0246	The type or namespace name 'AssemblyTrademark' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	10	Active
Error	CS0246	The type or namespace name 'AssemblyTrademarkAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	10	Active
Error	CS0246	The type or namespace name 'AssemblyVersion' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	12	Active
Error	CS0246	The type or namespace name 'AssemblyVersionAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	12	Active
Error	CS0246	The type or namespace name 'ComVisible' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	14	Active
Error	CS0246	The type or namespace name 'ComVisibleAttribute' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	14	Active
Error	CS0246	The type or namespace name 'nexus' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\MainPage.xaml.cs	2	Active
Error	CS0246	The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	1	Active
Error	CS0246	The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)	ble.net.sampleapp-uwp	C:\Test\ble.net-master\src\ble.net.sampleapp-uwp\Properties\AssemblyInfo.cs	2	Active
Error		Type universe cannot resolve assembly: System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.	ble.net.sampleapp-uwp			

What's unique about these libraries?

There are already a few cross-platform BLE libraries, with Xabre's being the most popular. What makes this one special?
I notice you're using a different license (MPL rather than Apache), but is that all?

Can't connect to device on Android

Hi,
I just tried your sample application for Android and it is not able to connect to the beacon. I also changed connection timeout, but no improvement. Connecting to the same beacon via sample iOS application is working fine. Can you check it pls?

Roadmap on Windows support?

@nexussays This library looks very promising, but I need it for Windows. Do you plan on digging into the "incredibly obtuse" APIs for Win10 BLE support at any point in the near future?

Is it possible to use SPP profile?

Hi,
I'd like to develop an app, that would be able to send and receive data from arduino through serial Bluetooth communication. Does this plugin allow that?

Continuous Scanning of BLE devices

@nexussays ,

Is it possible to scan ble devices continuously without any scan timeout?

One way to achieve this is by putting the adapter.ScanForBroadcasts method inside a Device.Timer action. Is there any other way to achieve this?

how to auto connect with my ble device

hello,

i am using hmsoft ble sensor in my project, so far i can use the library to manually show and connect & communicate to and fro device. now i want to do is since its a fixed device, once app scans it, it doesnt show list of devices to user instead auto connect in background and get data and show stats sent from my ble sensor.

regards

Advertisement package is not receiving updates in IOS

Hi,
I'm trying to use your library, but I've got a problem in IOS.
While I receive broadcasts from my device BLE, I need to check for changes in a specific byte of Advertisement package. The firmware of my device changes this byte value when the user click in a button.
In Android works perfect, if I click on button of my device, I can see the new value on the Advertisement package, but the same code in IOS is not working, the value of this specific byte never changes.
I'm using your sample project and did a small change to check if the problem ocours in fact, and I'm sure this is a bug. I've changed your code sample just with the following:
(BleDeviceScannerViewModel.cs) Line 75

await m_bleAdapter.ScanForBroadcasts(
            peripheral =>
            {
               Device.BeginInvokeOnMainThread(
                  () =>
                  {
                      **if (peripheral.Advertisement.ServiceData.ElementAt(0).Value[1] == 255)** 
                      {
                                **//The byte has changed**
                      }
                      else
                      {
                                **//The byte has NOT changed**
                      }

Notes:
1 - I use the same BLE device for the tests, so I'm sure that the firmware in device is working.
2 - I did the test by clicking in the button of my BLE device and using an App to read BLE packages in my Iphone. I can see that Iphone is receiving packages updates by this App.

Could you please help me?
Thanks in advanced

Problem with EnableAdapter() on Android?

Hi!

I get some problem when using bleAdapter?.State.EnableAdapter();. It works fine and the user get the question if its ok to Enable bluetooth on Android. But the method never returns?

My code:

public async Task EnableBluetoothOnDevice()
{
   if (bleAdapter == null || bleAdapter.State.AdapterCanBeEnabled == false)
   {
         return;
   }
   else
   {
         try
         {
            var result = await bleAdapter?.State.EnableAdapter();
            return result;
         }
         catch (Exception ex)
         {
            Debug.WriteLine(ex.Message);
            return false;
         }
   }
}

Best Regards
Niklas Carlberg

nexus.core 0.31.0 issue

Error Could not install package 'nexus.core 0.31.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Understanding Scan Filter

So I'm trying to implement scan filter, a little confusion has ensured. Let me just show my trace/debug pictues to help in my explanation.

I have setup a scan filter:
new ScanFilter() .SetAdvertisedDeviceName("f4:c3:33:07:cb:6c") .SetIgnoreRepeatBroadcasts(false),

When I set a breakpoint on the ScanFilter and look at the 'advertisement' variable I see no properties and none of my devices have a name or service attribute they're always null. I'm using Estimote iBeacons for the record.
scanfilter

Without a scan filter it does parse the addresses properly, but there are no names.

variables

Question:

So here's my thought process, where is the ScanFilter being called from and can I pass it IBlePeripheral instead of IBleAdvertisement and construct my own filter? Or is IBlePeripheral constructed using IBleAdvertisement and the ScanFilter is basically trying to skip the construction by doing a filter at the level below?

Fix descriptor write on Android

From #21

I tried working around this by doing this after the call to gattServer.NotifyCharacteristicValue:

Guid notifyDescriptorId = Guid.Parse("00002902-0000-1000-8000-00805f9b34fb");
await gattServer.WriteDescriptorValue(myServiceUuid, myCharacteristicUuid, notifyDescriptorId, new byte[] { 0x02, 0x00 });

but I get an NRE in OnDescriptorWrite:

12-08 16:58:07.322 I/MonoDroid(20572): UNHANDLED EXCEPTION:
12-08 16:58:07.347 I/MonoDroid(20572): System.NullReferenceException: Object reference not set to an instance of an object.
12-08 16:58:07.347 I/MonoDroid(20572):   at _Nc._Ab (_Nc+_jb , Java.Util.UUID , System.Action`1[T] ) [0x00054] in <6a3dedf7a0504e8380533e727c93d50b>:0 
12-08 16:58:07.347 I/MonoDroid(20572):   at _Nc._AA (Android.Bluetooth.GattStatus , Android.Bluetooth.BluetoothGattDescriptor ) [0x000d7] in <6a3dedf7a0504e8380533e727c93d50b>:0 
12-08 16:58:07.347 I/MonoDroid(20572):   at _Nc+_gb.OnDescriptorWrite (Android.Bluetooth.BluetoothGatt gatt, Android.Bluetooth.BluetoothGattDescriptor descriptor, Android.Bluetooth.GattStatus status) [0x0000a] in <6a3dedf7a0504e8380533e727c93d50b>:0 
12-08 16:58:07.347 I/MonoDroid(20572):   at Android.Bluetooth.BluetoothGattCallback.n_OnDescriptorWrite_Landroid_bluetooth_BluetoothGatt_Landroid_bluetooth_BluetoothGattDescriptor_I (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_gatt, System.IntPtr native_descriptor, System.Int32 native_status) [0x00017] in <c82a099136944d8aa96281cf061cbc12>:0 
12-08 16:58:07.348 I/MonoDroid(20572):   at (wrapper dynamic-method) System.Object:2e98fcf3-a2e2-4e76-8046-8bdd747a9455 (intptr,intptr,intptr,intptr,int)

Help compiling against Profile111

Hi,

Can you update the source so can compatible with .netVersion4.5 ?
I already use your github or from nuget, but it still can't work in .netVersion 4.5

Or, can you tell me which one that should i modified for the upgrade.

Thx

Run issue

Hi,

I just cloned the repo and compiled everything but when I run the sample App on Android 7.0 phone, i have this error:

01-08 10:23:58.630 W/Mono    (20694): no implementation for interface method nexus.protocols.ble.IAdapterControl::get_AdapterCanBeDisabled() in class _F
01-08 10:23:58.631 W/Mono    (20694): METHOD .ctor(nexus.core.logging.ILog,Android.Bluetooth.BluetoothAdapter,Android.Content.Context,System.TimeSpan)
01-08 10:23:58.631 W/Mono    (20694): METHOD get_DiscoveredPeripherals()
01-08 10:23:58.631 W/Mono    (20694): METHOD get_State()
01-08 10:23:58.631 W/Mono    (20694): METHOD _CC()
01-08 10:23:58.631 W/Mono    (20694): METHOD ConnectToDevice(nexus.protocols.ble.scan.IBlePeripheral,System.Threading.CancellationToken,System.IProgress`1<nexus.protocols.ble.ConnectionProgress>)
01-08 10:23:58.631 W/Mono    (20694): METHOD ConnectToDevice(System.Guid,System.Threading.CancellationToken,System.IProgress`1<nexus.protocols.ble.ConnectionProgress>)
01-08 10:23:58.631 W/Mono    (20694): METHOD Dispose()
01-08 10:23:58.631 W/Mono    (20694): METHOD ScanForBroadcasts(System.IObserver`1<nexus.protocols.ble.scan.IBlePeripheral>,System.Threading.CancellationToken)
01-08 10:23:58.631 W/Mono    (20694): METHOD ScanForBroadcasts(nexus.protocols.ble.scan.IScanFilter,System.IObserver`1<nexus.protocols.ble.scan.IBlePeripheral>,System.Threading.CancellationToken)
01-08 10:23:58.631 W/Mono    (20694): METHOD _Yc(nexus.protocols.ble.scan.IScanFilter,System.IObserver`1<nexus.protocols.ble.scan.IBlePeripheral>,byte[],int,Android.Bluetooth.BluetoothDevice)
01-08 10:23:58.631 W/Mono    (20694): METHOD _5(Android.App.Activity)
01-08 10:23:58.631 W/Mono    (20694): METHOD _Oc(System.Collections.Generic.KeyValuePair`2<_Bb, long>)
Unhandled Exception:

System.TypeLoadException: VTable setup of type _F failed

I'm working on Visual Studio Entreprise 2017 15.5.2

Thanks

ScanForBroadcasts seems to scramble the Advertised Service UUID

As I've continued on work with the sample code, I have found an issue with the advertised service UUIDs discovered by the ble adapter on ScanForBroadcasts (found in BleDeviceScannerViewModel.cs).

I have a device advertising a known UUID. Using other BLE tools, I can see that the proper service is being provided in the advertise data. However, when I examine the service guid discovered by ScanForBroadcasts, it appears that something has been messed up in the ordering of the string. Because of this, I am unable to apply a ScanFilter to specify my known service (ScanForBroadcast returns nothing). If I set the ScanFilter to the scrambled guid string, ScanForBroadcast returns the peripheral data.

Possible re-entrancy race condition with sequential notify then read/write

Hi!
i have a specific problem with gattServer.NotifyCharacteristicValue()

As i understand i am guaranteed that await writeCharacteristicValue() dont return before the package has been sent. But how is it with gattServer.NotifyCharacteristicValue()? I cant await that method?

I have seen that if i start listen for notifications on a specific characteristic and then write to change that characteristic the package with notificationListner with 2 bytes can sometimes be sent first after the write-package. This will do that i do not get any notification.

This is very critical to get my app to work properly.

Best regards
Niklas Carlberg

Disconnection Notification

Is there a way to detect when the device itself disconnects? I couldn't find a callback or anything, but could have missed it.

How to identify if a beacon belongs to Eddystone or iBeacon?

Hi,
I am new to working on beacons. I don't understand how to identify whether a beacon belongs to Eddystone or iBeacon.
And also how to get the advertisement data for a Eddystone beacon and iBeacon data as Eddystone beacon data has "Namespace" and "Instance ID" and iBeacon data has "Major", "Minor" and "UUID" values.

Could you please help me?
Thanks in advance

Question regarding EnabledDisabledState.Unknown;

Hi!

Regarding bleAdapter.CurrentState.Value == EnabledDisabledState.Unknown; What does this state indicate?
I can see that in your test-project you see this as if the ble adapter was enabled?

Best Regards
Niklas

Problem with ReadCharacteristicValue on iOS

Hi!

I have a question regarding "ReadCharacteristicValue". On iOS i need to first make a call to "ListAllServices();" and "ListServiceCharacteristics" to be able to read a characteristic. If i dont i get a Null-pointer exception. This is only for iOS, in Android i dont need to do those extra calls.

In my case i know from start the Guid:s for all Services and Characteristics so i dont need to get them from the perhiperal before reading them

I am using Nuget 0.12.14

Thank you

Using SCAN_MODE_LOW_LATENCY

Does your library allow for the use of SCAN_MODE_LOW_LATENCY on Android? I am using it to scan and connect to many devices and am hoping that enabling this will decrease my scan/connection times.

Problem scanning on iOS

Hi @nexussays ,

I have installed the latest beta version from Nuget and still, the ble devices are not getting enlisted.

This is what I have done till now:
packages.config

<package id="ble.net" version="1.0.0-beta0007" targetFramework="xamarinios10" />
<package id="ble.net-ios" version="1.0.0-beta0007" targetFramework="xamarinios10" />

AppDelegate.cs

[Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            BluetoothLowEnergyAdapter.ObtainDefaultAdapter();
            LoadApplication(new App());
            return base.FinishedLaunching(app, options);
        }
    }

info.pList

<key>NSBluetoothPeripheralUsageDescription</key>
<string>MyApp would like to use bluetooth.</string>
<key>UIBackgroundModes</key>
<array>
   <string>bluetooth-central</string>
</array>

**Scanner class **

await adapter.ScanForBroadcasts((IBlePeripheral peripheral) =>
               {
                   var a = peripheral.DeviceId; // breakpoint not hitting
                   
               },TimeSpan.FromMinutes(30));

I am using VisualStudio 2017, iPhone 6- OS Version 11.1.2. The only problem I am having is scanning on iOS rest of the platforms works fine.
Any help on this?
Thanks in advance!

ScanFilter could not be found

I have the beta0007 sampleapp working fine on android.
Now trying to connect to a specific device (SensorTag) without scanning using, FindAndConnectToDevice.

In BleDeviceScannerViewModel.cs I have,

    `private async void StartScan(Double seconds)
    {
        if (IsScanning)
        {
            return;
        }

        if (!IsAdapterEnabled)
        {
            m_dialogs.Toast("Cannot start scan, Bluetooth is turned off");
            return;
        }

        StopScan();
        IsScanning = true;
        seconds = BleSampleAppUtils.ClampSeconds(seconds);
        m_scanCancel = new CancellationTokenSource(TimeSpan.FromSeconds(seconds));
        m_scanStopTime = DateTime.UtcNow.AddSeconds(seconds);

        Log.Trace("Beginning device scan. timeout={0} seconds", seconds);

        RaisePropertyChanged(nameof(ScanTimeRemaining));
        // RaisePropertyChanged of ScanTimeRemaining while scan is running
        Device.StartTimer(
           TimeSpan.FromSeconds(1),
           () =>
           {
               RaisePropertyChanged(nameof(ScanTimeRemaining));
               return IsScanning;
           });

        await m_bleAdapter.FindAndConnectToDevice(
           new ScanFilter()
                 .SetAdvertisedDeviceName("CC2650 SensorTag")
                 .SetAdvertisedManufacturerCompanyId(0x000D)
                 .AddAdvertisedService("0000aa80-0000-1000-8000-00805f9b34fb"),
           TimeSpan.FromSeconds(30));
    }`

Except when clean & rebuild I get,

Error CS0246 The type or namespace name 'ScanFilter' could not be found (are you missing a using directive or an assembly reference?)

I'm seeing ScanFilter in the API branch, but what other part needs to be done to click "Start Scan" right into the SensorTag?

-thank-you

Disconnection on iOS doesn't complete/cancel outstanding reads & writes

Hi!

I have a problem regarding lost connection. Like if you go away from the peripheral or break power to the peripheral so that the connection will break.
If you do a read or write just after the kind of disconnect the api will not give me an exception, it get stuck just wait for the method to return. This happens on iOS. On Droid i get the gatt-exception after 20 sec

Im not sure of it but it seems like the method finally returns if you connect again leading to very strange behavior.

This is very critical for our app to get it to work as aspected so it would be very nice to prior this bug

To have the latest 1.0 release and have testet on iPhone 7 (ios 11.2.6)

You could create this bugg by this kind of code below.

First run Connect()
Then run DisconnectionTest()
Then break power to the peripheral (i think it will work if you go away also)
I dont get any exception, have wait for minutes.

public async Task<Boolean> Connect()
{
   BlePeripheralConnectionRequest connection;
   var connectCancel = new CancellationTokenSource( TimeSpan.FromSeconds( 30 ) );

   try
   {
      connection = await bleAdapter.ConnectToDevice( deviceId, connectCancel.Token );
   }
   catch(GattException ex)
   {
      return false;
   }
   catch(Exception ex)
   {
      return false;
   }

   if(!connection.IsSuccessful() || connection.GattServer == null)
   {
      return false;
   }

   connectedDevice = connection.GattServer;

   return true;
}

public async Task<Boolean> DisconnectionTest()
{
   var result = true;

   for(Int32 i = 0; i < 1000; i++)
   {
      //try break connection by drop power to peripheral

      result = await WriteToCharcteristic( service1, characteristic3, BitConverter.GetBytes( i ) );
   }

   return result;
}

public async Task<Boolean> WriteToCharcteristic( Guid service, Guid characteristic, Byte[] value )
{
   try
   {
      var result = await connectedDevice.WriteCharacteristicValue( service, characteristic, value );

      if(result != null)
      {
         return true;
      }

      return false;
   }
   catch(GattException ex)
   {
      DebugUtil.WriteLine( "WriteToCharcteristic exception: " + characteristic + " ex: " + ex.Message );
      return false;
   }
   catch(Exception ex)
   {
      DebugUtil.WriteLine( "WriteToCharcteristic exception: " + characteristic + " ex: " + ex.Message );
      return false;
   }
}

iOS: Read results in notification

Hi!

I have a problem with iOS. If i activate notification for a characteristic and then do a read on the same, it will result in a notification? This behavior only happens on iOS? Evry read i do will lead to a notification, even if the value is not changed.

Let me now if you need some more information but i guess its easy to recreate for you

Problem with StateChanged-callback for iOS

Hi!
First of all i want to say thank ypu for this lib! =)
I have a problem with a callback when ConnectionsStates changes, only on iOS, works fine on Android.

I have the same problem when i run the sample-app.

I use that app as example:
In "BleGattServerViewModel" in the "OpenConnection() - method" you subscribe for statechanges. But i dont get this callback (in ios) when the phone is losing the connection with the peripheral:

m_gattServer.Subscribe(
c =>
{
   if(c == ConnectionState.Disconnected)
   {
      m_dialogManager.Toast( "Device disconnected" );
      CloseConnection();
   }
   Connection = c.ToString();
} )

I am using Nuget ver 0.12.14

I also wonder if its possible for me to use this lib with Bluetooth-le background mode? I need to be able to communicate with the peripheral when the app is in the background.

Tank you!

Asynchronous disconnect from device

Hi!
It dont say anything regarding disconnecting from the device in the reademe-file.

Currently i use connection.Dispose() to disconnect. But i get issues if i try to connect to fast after disconnecting. Is there som sort of callback to see when the disconnet is all done?

If i connect to fast i usaly can connect but then i cant write to a characteristic or i gett disconnected just after i benn connected.
I guess this can be a device-problem as well.

But it would be nice with a callback saying when the disconnect is completed.
Also, is there a standard saying that you shoult wait for x seconds before

I have been trying this on a Android. I should soon update to latest beta but right now i go with 1.0.0 beta0007

Best regards
Niklas Carlberg

Android problem : "Use Compile using SDK version"

Hi!

I have some problem since i change a setting in Android Manifest.

It works fine with this settings:
Compile using Android version: Android 7.1 Nougat
Target Android version: Use Compile using SDK version
Minimum Android version: Android 4.0.3 Ice Cream

But Xamarin recomends to not use "Use Compile using SDK version" and to get other parts to work properly like permissons i need to have this settings:
Compile using Android version: Android 7.1 Nougat
Target Android version: Android 7.1 Nougat
Minimum Android version: Android 4.0.3 Ice Cream

But if i change this i get problems, i cant find any devices when scanning. I have also try with Android 6 and 8. If i not use "Use Compile using SDK version" it want work properly.

Are you getting the same problem if you change from "Use Compile using SDK version"

Info regarding Android API Levels
https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/

Best regards
Niklas

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.