Showing posts with label bluetooth. Show all posts
Showing posts with label bluetooth. Show all posts

Tuesday, June 12, 2018

Windows 10 Pro -version 1803 bluetooth Profiles Access

Leave a Comment

We are looking to access and use Bluetooth profiles in our WPF application using C# in Visual Studio 2017.

Issue details:

Platform: Windows 10 Pro - version 1803.

Issue brief: We are trying to access Bluetooth profiles via desktop(c#) of connected phones, however on windows 10 the profile show enable but the profiles are not working eg: HFP connects, however, the voice is not heard

We have tested this on following Bluetooth devices:

1.Bluetooth CSR 4.0 Dongle (CSR8510 A10) (Note: this Bluetooth connects and show HFP and works as expected, however, the Bluetooth does not show on the device list and hence we cannot connect programmatically using c#)

2.IOGEAR's Bluetooth 4.0 (Model GBU521W6) (Shows on device list and our application can detect a device, however, HFP is not working as expected both from the application or from normal device section)

Required Profiles:

1.Hands-Free Profile (HFP) 2.Message Access Profile (MAP) 3.Phone Book Access Profile (PBAP)

We have Already Tried with following:

  1. Updating drivers
  2. Tried uninstall install many times
  3. Used android, ios, and windows phone's

Side note: Our application with same code works on windows 7

1 Answers

Answers 1

MAP abd PBAP is not a problem because both are OBEX based (which is RFCOMM).

However there can be some problems with HandsFree. It works great with BlueSoile drivers. But with standard microsoft may not work.

The first step it to use BluetoothSetServiceState with HFP UUID to tell windows to install drivers for your device's HFP profile. If function succeed you should see 2 audio devices appeared in your system: one is Inout and other is Output. You can find them using any media API (DirectSound, legacy API).

To be able to work with PBAP and MAP you need anyhow connect to your device through RFCOMM. WinSock or any other way is good.

Please note that the method above works only with Microsoft Bluetooth drivers. Other drivers (BlueSoleil, Toshiba) have absolutely different API so you have to add it into your application if need to support them.

Or you can simple take a look on BluetoothFramework

Read More

Wednesday, January 24, 2018

Read bluetooth device rssi without connected them starscan() issue

Leave a Comment

I read this Issue.

I want to make one sample app to read the all BLE device rssi near of my application range without connecting them.

I create STICKY service & access near device scan result.

BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(SmartIDService.this.BLUETOOTH_SERVICE);         mBluetoothAdapter = mBluetoothManager.getAdapter();  //Start Scan. mBluetoothAdapter.startLeScan(mLeScanCallback);  //Listen scan Resul. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback()     {          @Override public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord)         {                        AppLogger.showDebugLog(TAG + "rssi: " +rssi);          }     };  

I got the result as I want,but if BLE device out of range for some time I can't get the result again. I think that startLeScan() is remove from memory, so I create One alarm service to wakt up mBluetoothAdapter.startLeScan(mLeScanCallback); some time interval & issue is resolved. But I can't find the actual time interval that I will wake up alaram service.

any solution !!!
idea time interval for every device?
Any other process?

please guide me

1 Answers

Answers 1

Can you check this Github code, I have used once in my project and it worked perfectly.

https://github.com/googlesamples/android-BluetoothLeGatt

let me know if it won't work.

Thanks Madhav

Read More

Thursday, July 13, 2017

Make my python's Bluetooth server visible to iOS

Leave a Comment

I've been struggling to connect a Bluetooth server (using Bluez or similar) in a Python script which runs on a Linux service, with an iPhone device which runs a Cordova hybrid app.

I'm using cordova-plugin-ble-central for the latter, and for the former I give you the code below:

try:     server_sock = BluetoothSocket(RFCOMM)      server_sock.bind(("", 0))     server_sock.listen(1)     port = server_sock.getsockname()[1]      uuid = "d507688e-5fa7-11e7-907b-a6006ad3dba0"     advertise_service(server_sock, "TestService", service_id=uuid, service_classes=[uuid])      print("Waiting for connection on RFCOMM channel %d" % port)      client_sock, address = server_sock.accept()     print "Accepted connection from ", address      data = client_sock.recv(1024)     print "received [%s]" % data      client_sock.close()     server_sock.close() except Exception as e:     print 'ERROR: ' + str(e) 

The issue is that a "scan()" function result from the iPhone gives me several devices nearby, but not mine...in Android it works great off course!

What am I missing? Is there a way to make it discover-able?

Thanks in advance

0 Answers

Read More

Monday, July 3, 2017

How to enable Indications on Client Configuration descriptor from iOS8

Leave a Comment

I am trying to get the notification from a bluetooth device upon the characteristic value change. For this I need to enable notification for Client Characteristic Configuration(CCC) descriptor. I have used setNotifyValue(enabled: Bool, forCharacteristic characteristic: CBCharacteristic) for the characteristic but not getting the update for value changes.

I tried to enable the indication for CCC using writeValue(data: NSData, forDescriptor descriptor: CBDescriptor) but my app crashes for this API and shows the error as

Cannot write Client Characteristic Configuration descriptors using this method!

Any help!!

1 Answers

Answers 1

Provide more codes might help to imporove accuracy of an answer; however, let's be assuming you have already been able to discover all characteristic values. Usually you just need to iterate all characteristics and set/write value according to each Client Characteristic Configuration(CCC) descriptor in CBPeripheralDelegate implementation.

An example is attached below:

 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {     if (error) {         NSLog(@"Error discovering characteristics: %@", error);         return;     }      for (CBCharacteristic *characteristic in service.characteristics) {          if ([characteristic.UUID isEqual:[CBManager accelDataUUID]]) {             [peripheral setNotifyValue:YES forCharacteristic:characteristic];         } else if ([characteristic.UUID isEqual:[CBManager accelConfigUUID]]) {             [peripheral writeValue:[CBManager switchData:YES]                  forCharacteristic:characteristic                               type:CBCharacteristicWriteWithResponse];         }         //... if you have more to iterate     } } 
Read More

Sunday, April 9, 2017

Always discoverable Classic Bluetooth module

Leave a Comment

I recently purchased a Bluetooth device which connects to both my iOS and Android devices.

The device uses Classic Bluetooth and seems to be quite stable on my Android device however recently, I have noticed a few issues with the connection on my iOS devices. It seems to occasionally become a bit unstable.

While trying to figure out if the problem was on my end, I noticed that the Bluetooth device is actually always discoverable. I did a little digging and have been unable to find much information regarding this practice.

I've read up on how Bluetooth selects a channel over the 2.4G band, and how there are 3 out of the 80 channels which are used for discovery. Does this mean that the device is always on 1 of those 3 channels because it is always discoverable? Does it also mean that it's unable to change channel in the event of being on a noisy frequency?

Again, I'm assuming this is bad practice in terms of setting up a Classic Bluetooth connection but I haven't done too much work myself with Bluetooth and haven't had much luck finding more information regarding the issue. Could it also present issues of other devices attempting a connection while a connection is already made? I believe BLE devices become hidden once they've made a connection however I don't think this is the case for Classic Bluetooth.

0 Answers

Read More

Sunday, September 4, 2016

BluetoothAdapter ActionDiscoveryFinished

Leave a Comment

I just started to take a look at xamarin and now I want to scan for bluetooth-devices. Therefor I use the following code:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter; bluetoothAdapter.StartDiscovery(); 

And I have the following class for getting the result:

[BroadcastReceiver] [IntentFilter(new [] {BluetoothAdapter.ActionDiscoveryFinished})] public class BluetoothReceiver : BroadcastReceiver {     public BluetoothReceiver()     {      }      public override void OnReceive(Context context, Intent intent)     {         if (BluetoothAdapter.ActionDiscoveryFinished.Equals(intent.Action))         {          }     } } 

I've also set the permissions for my app to BLUETOOTH and BLUETOOTH_ADMIN. Everything just works fine and the OnReceive-Method is called correctly. My problem now is: How do I get the found devices from the parameters of the OnReceive-Method?

1 Answers

Answers 1

ACTION_DISCOVERY_FINISHED doesn't tell you anything other than the discovery action has finished. https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_DISCOVERY_FINISHED

If you wanted to grab devices from the scan, you should read what startDiscovery() has to say regarding finding devices:

The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

This is an asynchronous call, it will return immediately. Register for ACTION_DISCOVERY_STARTED and ACTION_DISCOVERY_FINISHED intents to determine exactly when the discovery starts and completes. Register for ACTION_FOUND to be notified as remote Bluetooth devices are found.

https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#startDiscovery()

Thus you should use ACTION_FOUND and parse the EXTRA_DEVICE for devices:

Broadcast Action: Remote device discovered.

Sent when a remote device is found during discovery.

Always contains the extra fields EXTRA_DEVICE and EXTRA_CLASS. Can contain the extra fields EXTRA_NAME and/or EXTRA_RSSI if they are available.

https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_FOUND

In sequence of events, you would do the following:

  1. ACTION_DISCOVERY_STARTED - Which will start discovery
  2. ACTION_FOUND - Which will find a device
  3. ACTION_DISCOVERY_FINISHED - Which will end discovery
Read More

Tuesday, May 3, 2016

Windows UWA (IoT) Bluetooth RfcommService

Leave a Comment

I'm trying to establish a communication between two windows 10 devices:

  1. Raspberry PI 2 B + Bluetooth dongle
  2. Surface pro

Server at raspberry pi:

private readonly Guid _rfcommChatServiceUuid = Guid.Parse("34B1CF4D-1069-4AD6-89B6-E161D79BE4D8");  private async void CreateServer()     {         _provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(_rfcommChatServiceUuid));         _listener = new StreamSocketListener();          _listener.ConnectionReceived += OnConnectionReceived;         await _listener.BindServiceNameAsync(_provider.ServiceId.AsString(),SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);          InitializeServiceSdpAttributes(_provider);         _provider.StartAdvertising(_listener);     }      const uint SERVICE_VERSION_ATTRIBUTE_ID = 0x0300;     const byte SERVICE_VERSION_ATTRIBUTE_TYPE = 0x0A;   // UINT32     const uint SERVICE_VERSION = 200;     void InitializeServiceSdpAttributes(RfcommServiceProvider provider)     {         var writer = new DataWriter();         writer.WriteByte(SERVICE_VERSION_ATTRIBUTE_TYPE);         writer.WriteUInt32(SERVICE_VERSION);         var data = writer.DetachBuffer();         provider.SdpRawAttributes.Add(SERVICE_VERSION_ATTRIBUTE_ID, data);     }   async void OnConnectionReceived( StreamSocketListener listener, StreamSocketListenerConnectionReceivedEventArgs args)     {          _provider.StopAdvertising();         _listener.Dispose();         _listener = null;         _socket = args.Socket; 

The client at surface:

   var services = await DeviceInformation.FindAllAsync(               RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(_rfcommChatServiceUuid))); 

The services collection is empty.

What is wrong with that?

Thanks

1 Answers

Answers 1

I think it is worth trying to hard code the address in client side. There is a sample C code of RFCOMM connections for both server and client.

The Bluetooth RFCOMM chat sample for Windows(universal) is here.

Read More

Wednesday, April 20, 2016

iOS BLE Bluetooth - send/receive HEX data

Leave a Comment

I am creating an iOS application that should connect to a custom BLE device. I need to iOS app to send 2 HEX commands, one to enable a part of the device and another to request for Data.

Is there any way in iOS to send/receive custom HEX data, other than working with services & characteristics?

2 Answers

Answers 1

No that is not possible, but the reason for this is not iOS but that the 'services' and 'characteristics' are just part of how the BLE protocol is defined.

Official spec: https://developer.bluetooth.org/TechnologyOverview/Pages/BLE.aspx

Generic Attribute Profile

The latest Bluetooth specification uses a service-based architecture based on the attribute protocol (ATT). All communication in low energy takes place over the Generic Attribute Profile (GATT). An application or another profile uses the GATT profile so a client and server can interact in a structured way.

The server contains a number of attributes, and the GATT Profile defines how to use the Attribute Protocol to discover, read, write and obtain indications. These features support a service-based architecture. The services are used as defined in the profile specifications. GATT enables you to expose service and characteristics defined in the profile specification.

Answers 2

The other answer is accidentally right, but for the wrong reasons.

Of course it is possible in BLE to send any kind of data, not just GATT. It's just that iOS forces you to work with GATT. There are no iOS APIs for anything else. So, yes, it is iOS that prevents you from doing it.

If you wouldn't be forced to work with GATT, there would be some other options:

  • L2CAP Credit-Based Channels - you create a channel that allows you to send full 23 octets of data per packet (that's in BLE 4.0 and 4.1; 4.2 allows more than that), in whatever format you choose to.
  • With access to the HCI, you can send a custom ACL Data Packet to avoid the L2CAP header. But you need to also modify the other side to make sure it parses it correctly.
Read More