2

I'm developing a mobile application (iOS and Android) that is communicating via Bluetooth with embedded arm-based device running Linux. The communication is client-server. Phone (client) pairs with device, connects to it and sends queries. Device replies to these queries.

I have decided to use Cordova (and Ionic framework) for the mobile development. The Android part is done. For the communication I'm using BluetoothSerial plugin (https://github.com/don/BluetoothSerial).

The server part on the device is based on this tutorial: https://people.csail.mit.edu/albert/bluez-intro/x502.html#rfcomm-server.c

Recently I purchased iPhone SE and I want to target iOS. All is working fine except the Bluetooth communication.

If I'm understanding it correctly, Bluetooth communication on iPhone is limited to just Bluetooth Smart (or Bluetooth Low Energy/BLE). The BluetoothSerial plugin that I'm using is, capable to communicate on iOS with very limited number of devices.

So my questions are:

  1. Is it possible to have full Bluetooth support on iOS? By full I mean a chat-like communication where client (phone) is sending some structured data and the device is replying also some structured data in text .

  2. If so, can I use BluetoothSerial plugin? I have also find BLE plugins for Cordova but they seem to have very limited support for Bluetooth communication (from my perspective). They are just for getting or writing some advertised characteristics on BLE device.

  3. If I have to use BLE-based solution I think that I have to also rewrite server code on the device. Am I right?

Thank you for any cues, suggestions or solutions.

stepan
  • 145
  • 2
  • 10
  • I think you need to write your plugin for that. Cordova isn't really a good framework for this. You should be doing all this in native. – Kunal Balani Jul 22 '16 at 21:13
  • @KunalBalani Yes, I know that I have to use plugin in order to communicate with hardware and that is exactly what I'm doing in Android case - I'm using BluetoothSerial. My question is if this is possible on iOS (100% native application or plugin for Cordova). And if so, what plugin/library/framework to use. – stepan Jul 23 '16 at 06:42
  • Stepan, can you pls provide an update. I'm simply trying to send/receive a few bytes to/from an Arduino board, using BLE Central plugin. I can get iOS to connect to my device and I can read its characteristics but I'm having a really hard time sending/receiving data. Would be happy to have this discussion outside this post – frednikgohar Dec 14 '18 at 00:18
  • @frednikgohar I gave up porting the app to iOS since the data throughput was crucial (I was sending images and a quite bit chunks of JSON data). In next weeks I'm going to start implementing another app for communication with custom ARM-based Linux device on one side and phone on the other side. Embedded device will run BLE beacon with several characteristics for both reading and writing. Once I will have at least some proof of concept I might let you know. Most probably, I will blog about this if I have a time. – stepan Dec 14 '18 at 09:47

2 Answers2

2

In this scenario, there are two options to communicate between a phone and a device using Bluetooth.

  1. Phone --- RFCOMM over Legacy Bluetooth ------- Device implementing ( Serial Port Profile)SPP server

  2. Phone --- GATT over Bluetooth Low Energy (BLE)---- Device implementing custom GATT service. There is no standard SPP GATT service over BLE.

The Serial plugin supports option 1 for Android and option 2 for iOS.

So your Android app via the Serial plugin, uses option 1 to connect to the device which runs RFCOMM server. To use option 1 for iOS, I think the device needs to go through the MFi program. Serial plugin does not support option 1 for iOS.

For Option 2: Serial plugin does support option 2 for iOS but not for Android. https://github.com/don/cordova-plugin-ble-central, supports option 2 for both Android and iOS. The device now needs to implement a GATT Service emulating a serial port.

Answers to your questions

  1. I think for SPP profile over legacy Bluetooth on iOS, the device needs to be MFi compliant.

  2. https://github.com/don/cordova-plugin-ble-central and https://github.com/randdusing/cordova-plugin-bluetoothle support both Android and iOS for option2. The device needs to implement a GATT service. The way to communicate between the phone and device is by reading and/or writing to the characteristics on the GATT server.

  3. Yes, the device now has to implement a GATT service. It currently implements a RFCOMM service.

Preeti
  • 336
  • 1
  • 7
  • Thanks for the reply! Now it seems that I have to rely on BLE/GATT solution since MFi certification is not realistic scenario. I'm concerned about the connection speed a bit. On Android and RFCOMM I'm transfering small images (10KB) at 15fps for example. I guess that this won't be possible any more: http://stackoverflow.com/questions/10254048/iphone-4s-ble-data-transfer-speed – stepan Jul 26 '16 at 14:12
  • If the device and phone support LE 4.1, then the max theoretical data rate at the l2cap layer is ~305kbits/sec. At the application layer, it will be much lower. LE 4.2 introduces higher data rates. – Preeti Jul 27 '16 at 18:20
0

I think what you want to do is possible:

  1. iOS has full Bluetooth support. Bluetooth low energy is an addition, not a replacement. By full I mean that it supports all features up to a certain level in the Bluetooth protocol stack, but your question is a bit different; you are also asking if there is a profile for your use case. An additional thing about iOS is that there are 2 libraries for Bluetooth: Core Bluetooth (BLE) and IOBluetooth (traditional Bluetooth).
  2. BluetoothSerial is a BLE implementation. Be sure to use Core Bluetooth. Apart from that I don't see why it shouldn't work.
  3. I'm a bit confused about what you have actually used, and how you got it to work. BluetoothSerial is a BLE solution (that's what the doc says), but you refer to a tutorial for that uses RFCOMM which is a protocol for Bluetooth classic. In any case you would have to choose either BluetoothSerial using BLE, or Bluetooth classic and RFCOMM.
Eirik M
  • 726
  • 1
  • 6
  • 12
  • Hi, thanks for the reply. BluetoothSerial is not strictly BLE solution. This plugin actually uses Bluetooth Classic on Android and BLE on iOS. So far I have only Android solution and I'm seeking for similar solution that works on iOS too. – stepan Jul 25 '16 at 19:37
  • I see, it is the BluetoothSerial code that is only for BLE on iOS. It should be possible to port it to Bluetooth classic on iOS. Unless it requires some features that are restricted on that platform, which is sometimes the case. You could use the Android code as reference and see if all the needed functions are available. – Eirik M Jul 25 '16 at 21:24
  • Well, but if I understand it correctly, if you want to communicate with the device using iPhone and Bluetooth classic your device should be certified by Apple MFi program. Otherwise you are only allowed to use BLE. – stepan Jul 25 '16 at 21:43
  • I wasn't aware of that, but it sort of makes sense. After checking, what is actually the case is that standard profiles do not require MFi, but beyond that it is needed. – Eirik M Jul 26 '16 at 07:13