Windows Mobile 10 Bluetooth LE Connect/Disconnect without pairing - bluetooth

I'm developing an app on the Windows Mobile 10 preview.
I have a Bluetooth product that I need to connect to, write some values then disconnect. I currently do this just fine in Android and iOS.
It seems that Windows Mobile 10 requires the device to be paired manually by the user and then it will automatically connect to the device. I really don't want this behaviour because it's important that other devices be able to connect.
Let me give the example of a door lock using Bluetooth LE. In this case there will be many phones that need to lock/unlock the door. It makes no sense to pair the door lock to one phone because that would automatically connect to the device (and thus prevent any other phone from connecting).
What's the solution in Windows Mobile 10 for our door lock? Can we pair/unpair from code?

Related

Establish a connection between smartphone and PC via Bluetooth automatically

I'm trying to establish a connection between my PC running Ubuntu and my iPhone via Bluetooth automatically when it becomes available, after being manually paired beforehand. I've seen this to be possible with certain peripherals, mainly audio. For example, my phone will automatically connect to a Bluetooth speaker when it is turned on and Bluetooth is active on my phone; another example is my phone automatically connects to my car's radio system via Bluetooth when I turn the car on.
I'm not able to connect my phone to my PC without first initiating the connection from the smartphone's Bluetooth menu. I'm thinking that I could possibly write an application for the PC to attempt to connect to the device every few minutes or something, but it seems that the phone needs to be the device to initiate the connection.
The only information that I need for what I'm trying to do ultimately is that the devices can pair successfully. Essentially I'm trying to build a sort of proximity trigger between my phone and my PC without using Wi-Fi and GPS - I can't use these for some specific reasons.
Is there any way to make this happen?
Yes this should be doable as long as you use the Background Processing feature for iOS apps. In the example I'll give below, we'll have the PC be the peripheral and the phone be the central, but you can really have it working either way. You will need to do the following:-
First initial connection needs to be performed in the foreground (this is due to iOS's background limitations).
On the iOS side, you need an application that acts as a central that scans and connects to the remove device (check this example as a starting point).
Upon connection, you need to bond with the PC. Bonding is important as it will prevent you from having to do the pairing again in the future. However, pairing/bonding is managed by the iPhone's OS so you cannot write it in your application, so the workaround is to have an encrypted characteristic on the PC side that will force the iPhone to bond (this is covered later).
On the PC side, you need to have a BlueZ script that acts as a peripheral that is always advertising. You can do this using bluetoothctl (check the examples here and here).
Before you start advertising, you need to have a GATT server on the PC side (to do this, check this example).
When registering characteristics, ensure that one of them has the encrypt-read property (you can find a full list of the properties here).
Now when you attempt to read this characteristic from the iOS side, the two devices should bond (make sure that your PC is bondable which you can do this via these commands).
Once the devices are paired, your iOS app needs to be working in the background constantly scanning and attempting to connect to the same peripheral (have a look at this and this example).
You can find more useful information at the links below:-
Getting started with Bluetooth Low Energy
The Ultimate Guide to CoreBluetooth Development
How to manage Bluetooth devices on Linux using bluetoothctl

How to find the connected device after BLE scan

When performing a BLE scan using startScan(onFoundBLEDevice, onBLEScanError). First, is the parameter sent to onFoundBLEDevice a single device or is it a list of devices? And if the answer is "single device" what happens when there is more than one BLE device in the local vicinity when performing the scan?
Secondly, Since my goal is to retrieve the battery level from my own smartphone (the one that is paired AND connected to my smartwatch) how can I tell which of the devices found by my scan is the one that's connected? Or do I even need to perform a scan? Is there another way to retrieve the device object in order to then get the battery service 0x180F and then the battery level characteristic, 0x2a19? In other words, I want to be sure that the battery level I retrieve is that of my phone, not my buddies sitting next to me.
UPDATE: my smartphone is a Samsung Galaxy S3 running Android 4.3 and my smartwatch is a Samsung Gear S2 running Tizen 2.3.1. I'm using Tizen Bluetooth API.
The BluetoothLEScanCallback (In your case onFoundBLEDevice) is invoked everytime a device is found. (For 3 nearby devices -> 3 calls)
I've scanned nearby devices from my gear while it's connected with a Mobile through 'Samsung Gear' app. No, There's no way to distinguish specific Mobile connected via Gear Manager from other devices. So, You can't find the connected device in this procedure. (Unless you are developing the app for personal use, In that case you can hardcode your Mobile device's UUID)
Samsung Provides 'Accessory' SDK for such purposes.
Samsung Accessory SDK
Any data you exchange using Accessory SDK would provide you info of specific 'The Connected' device via Samsung Gear. Check Out the API References, Programming Guides and Android-End Sample apps and Tizen-End Sample apps in Accessory SDK section.

App Specific Bluetooth Pairing

I was wondering if there's any way that I can control BLE device pairing specific to my app running on mobile device?
I do not want to write my own bluetooth profile so that only my app can talk to the BLE device instead i want to standard profiles available in BLE device but when it's paired to my phone, only my app should be able to communicate to it and none of the other apps should be able to communicate.
No don't do that.
If you MUST then you should encrypt your data with a key only your app knows.
Bluetooth Low Energy is supposed to be open and free for all.
What is the purpose for you to block others? Preventing them to block your service?
Then use some pre-shared key to verify that it's your app in both sides and close the connection if it's not.

Can PeerFinder class of .NET communicate with mobile phone devices through laptop via bluetooth?

I doubt the limitation of PeerFinder class in .NET. Can it make connection only with other laptops when implemented on laptop and phone to same phone when implemented on phone? Is it limited only to communicate with Windows OS devices, or is it able to communicate with any bluetooth device irrespective of OS?
Kindly, help me if you are sure of this class capabilities. I have seen the implementation of 32Feet.NET but my question is limited about PeerFinder class and its limitations.
Start from this link, in which you can find several useful links for WinRT communication (the suggested protocol to use from Windows Phone 8 to communicate using NFC or Bluetooth)
http://blogs.ugidotnet.org/Nick60/archive/2012/12/30/win-rt-proximity-communication.aspx
You have two possible scenarios:
App to Device: you can connect a Windows Phone 8 device to third party devices (for example a LEGO robot or car audio systems) Bluetooth/RFCOMM (that is serial port profile, for the emulation of RS232 serial connections).
App to App: for communications between Windows Phone 8 devices and also Windows 8/Windows RT devices!
The PeerFinder class is the base class for discover another instance of your app on a nearby device and create a socket connection between the peer apps by using a tap gesture or by browsing:
http://msdn.microsoft.com/en-us/library/windows/apps/br241203.aspx
Hope this helps!
Unfortunately, it seems that the only way to stablish a socket connection using Bluetooth between a WP8 app and a Windows 8 app is by triggering the connection using NFC tap gesture. Although the PeerFinder documentation suggests that you might be able to specify AlternateIdentities to advertise peers running on both devices, it seems that Windows 8 relies on WiFi Direct, while WP8 uses Bluetooth.
So, if you are not able to use the NFC tap gesture between both devices to trigger the connection, you might not be able to pair both apps running on the different devices.
See this thread for more info.

Data Exchange between applications over ActiveSync

Can anyone tell me how to send receive data between two applications over an ActiveSync connection?
In my scenario there will be one application running on a desktop and another on a windows mobile device, both these applications need to communicate among them. The connection between the desktop and the mobile device can be ActiveSync over USB or Bluetooth. I need the applications to exchange a continuous stream of data, more like a chat application. Ideally, the mobile device application will be sending out data 10-15 times a second (maybe more) and the desktop application will receive the data and display it.
For e.g., let’s consider the ‘Notes’ application for mobile device. Basically it allows user to save small textual notes. Now my application would be something similar, with the exception that it will send out all input it receives to the desktop application. The desktop app will receive the ‘inputs’ and process it.
Finally, I'm open to using any other option then ActiveSync, provided it supports Bluetooth.
You should check out ActiveSync api documentation for informations.
There is also an alternative solution, which I use.
Windows Mobile activates a temporary LAN when the device is connected on the USB.
You can use Window Sockets for the communication and avoid ActiveSync,
if it's not too much trouble for you.
Usually, the device gets IP 169.254.2.1 and the PC the 169.254.2.2.

Resources