Converting iOS External Accessory Framework code to Android - android

We were given a bluetooth device that we were asked to connect both iOS and Android devices to a particular custom peripheral.
The demo app seems to bring up a list of devices, asking which to use, then brings up a list of protocols, which includes one defined in the info.plist under "Supported external accessory protocols" as com.(company).bt.
I looked all over and found nothing about this process being standard with Bluetooth, and the entire workflow appears to be different on Android. I've tried using the bluetooth sample app to connect to this device but the red connected LED never lights up, and depending on the UUID given, I either receive 1 byte or 7. The sample code I was given doesn't even touch the InputStream unless the stream has reached 16 bytes (Which of course, never happens)
Is there some sort of guide on how to connect to this device? Based on what I read from the code, a message isn't even sent until the user presses a button, but the LED is lit long before this is even an option in iOS.
Edit: I finally found something from clicking around - it seems that the plist entry has to do with mfi (Which I guess the documentation is only available to those in the program?) With that said, does that mean this device will only work with iOS devices?

As you mentioned connection in Android and iOS is done differently.
The protocol defined in info.plist should be the protocol you are meant to use with the particular Bluetooth chip you have.
There is a guide explaining how to connect in iOS, you should probably also check which Bluetooth version it is. If it is lower than Bluetooth 4.0 (BLE- Bluetooth Low Energy) or not. I assume it isn't BLE since you mentioned it is MFI...
1)If it is BLE use Core Bluetooth
2)Otherwise have a look at the following link: Introduction to Stream Programming Guide for Cocoa.
It is a bit hard to understand what you mean about the red LED because we don't know what device you are using. Considering you are receiving some bytes from the device it means that the communication was established. You can start debugging and perhaps understand better the code by changing it to "touch" the InputStream even if 1 byte is received...
Hope this helps.
Cheers!
EDIT: Just read the title again, I am not sure what you mean by saying you want to convert the code to Android? You only described your attempt to connect in iOS.
A quick Google search would give you the following links for Android guide:
1) Bluetooth (not BLE)
2) BLE

Related

Android BLE Numeric Comparison Pairing Implementation

How do we implement Numeric Comparison for Android?
I've done alot of research and I know I need to set the IOCapability to KeyboardDisplay.
And if the other BLE device's own IOCapability makes it match the matrix result of Numeric Comparison, it will pair with Numeric Comparison.
But I cannot find any example code online.
We are supposed to somehow use BluetoothConfigManager to set the IO Capabilities right?
I.E. Use setIoCapability(int capability) and IO_CAPABILITY_KBDISP
See here: https://developer.android.com/reference/com/google/android/things/bluetooth/BluetoothConfigManager
Thanks.
You are right that usually the IO capabilities of both devices determine if the pairing pop up should appear, however, this is not the case for Android. On Android, this is usually handled by the device hardware so unfortunatey there is no way to guarantee that you can get the pairing dialog to pop up. Howoever, there are hacks that you can use that have worked for other people in the past. Have a look at the links below:-
CreateBond doesn't always show PIN dialog
Making Android BLE work - bonding
Pairing in Android is handled by the system. The system sets the IO Capabilities. For normal smart phones you usually have both a display and a keyboard, so these will be used. Any recent Android version also supports LE Secure Connections (LESC), where numeric comparison was introduced.
As you say, as long as the remote device has a display and yes/no input as IO Capability and supports LESC, the numeric comparison will be used.
If this does not seem to be the case, check the hci log or use an air sniffer to inspect the Pairing Request and Pairing Response messages to see which capabilities each device announces.
I was able to finally get the Numeric Comparison paring to finally work!
I was using the Nordic BLE library, and using createBond() prompts the Android OS to take care of the entire Numeric Comparison process (see picture below).
I think this is a great step for documenting this, because I searched everywhere on the internet for example code/ implementation for this and could not find anything. This is maybe the first.
If you are not using Nordic BLE library, I think the normal library functions related to creating bonds will do the same thing.

Is there any way to monitor bluetooth traffic?

So, what I want is just to scan the environment and see if any packages are sent without pairing or connecting to a device. Just a general scan of bluetooth in the air and being able to see some of what comes up, like packages exchanged and maybe some information of them. Everything I've read so far is about pairing or connecting first.
Thanks in advance!
The question is old, but since nobody gave an answer I try to fill the gap.
Bluetooth is, because of its technical specifications (frequency hopping etc.), difficult to sniff. A monitor mode like in WiFi doesn't exist out of the box. You would need to scan all Bluetooth channels at the same time. And then there is the challenge that since you managed to detect something, you need to know the next hop (to which channel the devices jump next). There are commercial hardware that can do that. Also some open source projects come up like Ubertooth, but with less capabilities.
You could try to purchase an Ubertooth and play with it.

Can you manipulate Raspberry Pi sensor data on an Android smartphone?

I am new to using the RPi and just got the A+ model which I have been using to generate different types of data from external sensors. I was wondering if it is possible to send this data it is gathering to an android device in real-time, and if so the best method? I want to be able to notify the user (through a an app made with the Ionic framework) when the data enters a particular range etc.
And also is it possible to do this whilst the user is walking around with both the devices in hand?
The short answer to the question is: Yes, you can ;-)
The longer answer is much longer, since there are many ways to do this.
The one I personally would choose as the simplest is classic Bluetooth (not LE) using the SPP profile, which basically makes the BT link a serial connection between the RPi and the phone.
On this serial link you invent you own streaming protocol suitable for the data you want to transfer.
On the RPi side you install a module such as this: https://www.sparkfun.com/products/12577
(There are many alternatives, but the RN42 module is very foolproof...)
Don't know the level of your hardware skills, you might need something more plug and play if you feel uncomfortable hooking up the 4 wires needed for 3.3V power and serial communications between the Pi and the BT Module...
On the phone side you install https://github.com/don/BluetoothSerial, which gives you an API reachable from Ionic where you can receive the BT data stream.
With that and a bit of coding on both sides you are good to go.
I've used a Raspberry Pi in combination with an Android smartphone & Lego NXT.
Communication was achieved using Bluetooth on Raspbian. I used a cheap $1 USB Bluetooth dongle. The Bluetooth stack had to be compiled for Raspi, which may not be necessary anymore. Steps can be found here: Bluetooth error: Native Library bluecove_arm not available
Bluetooth seems most logical to me.
I'm at work at the moment, hence the lightweight answer, if you'd like to discuss this further then please leave a comment and I'll be happy to provide more verbose response.
You can upload the data to any cloud services. You can use Xively/Box. Xively is specially made for real time data collection.
To connect RPi to Xively, refer this: https://xively.com/dev/tutorials/pi/
For Box, refer this: http://www.sbprojects.com/projects/raspberrypi/webdav.php
You can then use Xively API in your android app. You can see GitHub for this
Google app store already has some apps for you, if you want to use
It might look a little complex. But its really simple once you follow the above methods.

How to sniff Bluetooth traffic in Android?

I would like to know if there are any apps/api tools to track all the bluetooth connections happening in android? I tried using hcidump via BusyBox, but the trace is truncated, it does not display all the data I need.
I am trying to receive data from blood pressure monitor in android using Bluetooth HDP profile. However, the connection works at the beginning, and then stops. Therefore, I would like to use some packet sniffer to see the low level bluetooth connection for better debugging.
I found out that traces from hcidump tools are not truncated, and I think this is a perfect solution. However, I have to copy the trace from android to the pc evry time (e.g. sending by e-mail) and therefore it is a cumbersome work. Would be great if there was a tool to get access to the terminal emulator of android. Btw, BusyBox provides also some other very useful tools from Linux.
There are two options for this currently, the first is to use a software-defined radio that supports the ISM band (at least 2.4 to 2.485 GHz). This will allow you to grab any radio signals within the bluetooth range and will be especially useful if you're trying to identify interfering signals.
The downside is that you'll be receiving totally raw waveforms which you then need to demodulate using something like the gr-bluetooth stack.
The other option is a specialized device like the Ubertooth.

Combine iBeacon bluetooth low energy with Android 4.3

I'm looking for a way to detect iBeacon (iOS 7.0 feature) from an Android device. I read the Android documentation, where it seem that the iBeacon is some kind of GATT server which sends its position. While the Android documentation says that I should not poll that data, but for the detection this would be nessesary.
I google a lot but this topic is quite new (I even created a new tag ibeacon) so I would be happy if I get some links to ressources from the iOS world which descripes the implementation. Also if there are some Android libs which I did not find yet would be nice.
EDIT: The library below has been moved here:
https://github.com/AltBeacon/android-beacon-library
I have ported the iOS7 iBeacon SDKs to Android, and was able to see standard iBeacons and estimate their range. The code is available here:
https://github.com/RadiusNetworks/android-ibeacon-service
For this to work, you need Android 4.3 which introduced the Low Energy Bluetooth APIs. You also need a device with a low energy bluetooth chipset.
If you don't want to use the full library above, you can roll your own. iBeacons simply transmit a BLE advertisement once per second that start with a known sequence of bytes. You simply have to tell Android to do a BLE scan, get each advertisement, and look for one that starts with the known iBeacon byte sequence. You can then parse out the iBeacon fields. Here is the code the shows how this is done:
https://github.com/RadiusNetworks/android-ibeacon-service/blob/master/src/com/radiusnetworks/ibeacon/IBeacon.java#L177-L231
The only catch here is to detect beacon even the app is not running. Unlike iOS7, it is not natively support. In iOS7, when you on your BT, it will automatically notify you when you enter the region of registered iBeacon.
I had implemented iBeacon in Android 4.3 API using IntentService plus AlarmManager. To do a scan every 30 sec( to save your battery power, it shall be longer). It works well for user. Only when the matching uuid/major/minor is found, then it will trigger notifications. Otherwise, it will sleep and wake up for scanning again.
i think this is the solution for your question.
I didn't quite get what you mean, could you provide links to the documentation which said that you should not poll the data?
But it seems to me that the iBeacon is working as a server, which is kind of funny to me. Isn't it meant to find other devices, not the phone itself?
https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.position_quality.xml
This is the characteristics it uses though. To me it sounds like that the devices you are looking for are the "beacons" and the phone itself is just a listener. So you would not poll the EHPE and EVPE data but you should actually listen to it's changes or "broadcasts".
I'm kind of new to this myself also and couldn't find any really specific documentation.
Though, be advised, in the link I provided there is download link in the top corner which will provide you the full documentation in PDF format. There you will probably find more answers.

Categories

Resources