Search Unity

Bluetooth Low Energy Plugins for iOS and Android

Discussion in 'Assets and Asset Store' started by Hotshot10101, Apr 17, 2015.

  1. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    We do not have any plans on supporting peripheral mode for Android. It was only added to iOS initially as a way to test the plugin while I was developing it and at the time Android did not support it at all (Android 4.3).

    We have not received that many requests for it because out plugin is mainly used for phone / tablet to device where the device is a BLE device of some kind and not another phone / tablet.

    I am sorry if this causes any inconvenience.
     
  2. sgygkgk

    sgygkgk

    Joined:
    Apr 28, 2015
    Posts:
    6
    That news is very unfortunate, but I understood.
    I will make peripheral mode myself plugin.

    However, if you will implement Android's peripheral mode in your plugin, it will make your plugin better.
    (Function that can only be used with Android 5.0 or higher)

    If you are interested, please try it.
    https://developer.android.com/samples/BluetoothAdvertisements/index.html
     
  3. sgygkgk

    sgygkgk

    Joined:
    Apr 28, 2015
    Posts:
    6
    I will correct my opinion.

    The utilization rate of 4.4 is still 20.0%.
    https://developer.android.com/about/dashboards/index.html

    Functions that can only be used with 5.0 or higher may not be worth much at this time.
    I think that it is worthwhile if most users are 5.0 or higher.

    Please consider it in the future. ;)
     

    Attached Files:

  4. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    Hey,

    We want to use this plug in to control our drone through a Unity app, within bluetooth range. Will this plug in be suitable?
     
  5. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    As long as the drone is ble it should be fine.

    I am not sure if the through put will be fast enough. That will depend on the type of control you are trying to accomplish and the phone you use.
     
  6. jestermaximusJr

    jestermaximusJr

    Joined:
    Jan 12, 2013
    Posts:
    14
    Hello, I'm just starting with Aruino/ble/IoT. The Bluetooth breakout I just bought (Bluefruit LE UART Friend) for my arduino board says it uses UART to act as a serial port when communicating with the connected device. Is this the use your plugin was created for? If not, is there another plugin, or resource you could point me to? I just need to exchange strings back and forth between a tablet running unity and an arduino.

    Thank you!
     
  7. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    You can use my plugin with the board you are using. It is kind of a hybrid between serial and BLE.

    If you decide to get the plugin please read through the great article that AdaFruit has about BLE here:

    https://learn.adafruit.com/introduction-to-bluetooth-low-energy

    Then use my support email to ask any questions you might have.

    You will basically use the send / receive characteristics to send and receive data using BLE.
     
  8. jestermaximusJr

    jestermaximusJr

    Joined:
    Jan 12, 2013
    Posts:
    14
    Thanks for your help. I'm picking up your asset now!
     
  9. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Awesome. Have fun with it.

    Make sure to check out the instruction PDF for notes about OS things.

    Email support if you need help.
     
  10. Luis_Marquez

    Luis_Marquez

    Joined:
    Apr 6, 2017
    Posts:
    1
    hi friend awesome asset,

    we have your asset running, we would like to know if thereis a way to manipulate the whole advertising package, is there a way?
    we have an in house ble peripheral, with whom we would like to communicate,

    we managed to trigger the second callback using the manufacturer id but we dont get much more, as we are working we are "embedding" all our interest info into the name, but we would like to obtain the rssid,and handle the advertisment package, to avoid exposing the info on the name

    thanks in advance

    tl,dr, we would like to get something with this form on a variable:
    [0x02, 0x01, 0x06, 0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
    0x45, 0x4d, 0x4f, 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd]

    is it possible?
     
  11. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    If you have control of the firmware that is being put on the device and can control the advertising information, then you should be able to do it.

    The plugin will return what is called the Manufacturer Specific Data Packet. This packet has a type of 0xFF.

    I don't know what embedded device you are using, but all of them that I know of are able to add this packet type to the advertising data.

    Keep in mind that you still are restricted to the byte limit of the advertising packet unless you also implement the extended information (this is outside the scope of this answer). That involves a central device sort of connecting and gathering more information from the device.

    It is better to simply limit what you advertise. Total you have about 31 bytes. That includes the name of the device and any services you advertise, so be aware of the limits.

    If you do implement the manufacturer specific data packet, then you will get all of those bytes in the scan callback as the byte[] parameter.

    Let me know if I can help further.
     
  12. Addranor059

    Addranor059

    Joined:
    Nov 6, 2017
    Posts:
    2
    Can we use this plugin to connect two android devices for bluetooth multiplayer ?
     
  13. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    This plugin is not made for that. It is for connecting to actual bluetooth device using bluetooth low energy.
     
  14. Addranor059

    Addranor059

    Joined:
    Nov 6, 2017
    Posts:
    2
    Alright, thank you for your quick answer !
     
  15. hicatRkk

    hicatRkk

    Joined:
    Nov 29, 2017
    Posts:
    1
    Hello,Hotshot
    I am using this plugin for my application to connect with micro:bit ; But it doesn't work when I scan for peripherals.
     

    Attached Files:

    • shot.jpg
      shot.jpg
      File size:
      16.8 KB
      Views:
      935
  16. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I do not check this thread very often. Sorry it has taken me until now to see your post.

    First are you using Android version 6+? If you are did you add the line to the manifest xml file that is indicated in the Android documentation?

    The second thing is to try the ScannerTest example instead. It is a simpler example and not so specific to the hardware used in the main example your screen shot comes from.

    If you want faster answers please use the support email address on the asset store page for this plugin.
     
  17. dumbledad

    dumbledad

    Joined:
    Feb 11, 2016
    Posts:
    7
    @Hotshot10101, should the samples, like ScannerTest work in the Unity Editor (on a Mac) or just when deployed to the target device?
     
  18. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    This plugin only works on iOS and Android. I also got your email and we can continue tech support using email.
     
    dumbledad likes this.
  19. mtomara

    mtomara

    Joined:
    Feb 18, 2017
    Posts:
    3
    Hi,

    I bought a microbit and want to control it from a unity app over BLE. Do you think your plugin will be suitable for that?
     
  20. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    As long as the microbit is bluetooth low energy and not bluetooth classic it should work. You can post a link to it here or send an email to our support email and I can help look into it.
     
  21. mtomara

    mtomara

    Joined:
    Feb 18, 2017
    Posts:
    3
  22. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    This plugin should work with the microbit.

    BLE is not trivial, but this plugin will give you all the methods you need to connect Unity to any BLE device.

    I would start with the ScannerTest example in the plugin just to make sure you have everything set up correctly for BLE to function on your iOS / Android device.

    Then I would use the SimpleTest example as a guide on how to make a full app.

    You will still need to do the work of setting the proper Device Name and service / characteristic UUID values.
     
  23. mtomara

    mtomara

    Joined:
    Feb 18, 2017
    Posts:
    3
    Thank you for taking the time to look into this, I think it will work for me.
     
  24. thatfoolsean

    thatfoolsean

    Joined:
    Aug 20, 2012
    Posts:
    13
    Hi Hotshot!

    I'm loving the plugin, but I'm having trouble getting it onto my Apple TV correctly. Xcode is giving me a whole host of problems when I try to build to the AppleTV, and they all seem to do with the iBeacon support (which I assume isn't available on the Apple TV device). Is there an easy way to strip all of that out in order to make a clean Apple TV build?

    Thanks!
     
  25. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I usually check tvOS before I release. For some reason I figured this would not be an issue.

    I will get this fixed right away and submit a new version to the Unity Asset Store.

    Hopefully they will release it quickly.
     
  26. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I have removed support for the iBeacon parts when building for tvOS. I have submitted a new version 2.22 to the asset store. They were pretty quick at getting 2.21 out, so hopefully it will only be a day or 2. Then you should get an update notice.
     
  27. thatfoolsean

    thatfoolsean

    Joined:
    Aug 20, 2012
    Posts:
    13
    Awesome, thanks! You're so quick with the fix! Great product, great support! Couldn't recommend enough!
     
  28. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    You are most welcome.
     
  29. foobraco

    foobraco

    Joined:
    Oct 20, 2012
    Posts:
    12
    Hey @Hotshot10101

    Could I use this plugin to push notifications from a Sensoro Beacon?

    The workflow that I need is, send a notification from the beacon with an URL included and then that Notification would open my Unity app passing through that URL. Would this be possible with the plugin?
     
  30. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    You would have to do a little extra work for it to work in background mode, but it is possible.
     
  31. foobraco

    foobraco

    Joined:
    Oct 20, 2012
    Posts:
    12
    Thanks for the quick reply @Hotshot10101, do you think that extra work could be done in the Unity side, or would I have to write native code for each platform in order for it to work?
     
  32. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    You will need to make native code changes.
     
  33. Wilbert-Blom

    Wilbert-Blom

    Joined:
    Aug 13, 2011
    Posts:
    110
    Hi,

    When will this be available for Windows ?
     
  34. Big-Al

    Big-Al

    Joined:
    Apr 3, 2019
    Posts:
    1
    I need this for a research project at school. We are trying to reduce nausea in VR with some hardware. BLE is how we wanted to communicate. We are using android because nobody can afford a VR set up. I would build this myself to save money (I have started) but the complexity of something like an android plugin for unity given the free vs the pro versions ie managed vs unmanaged plugins is something I don't understand. So I have two questions will this asset be effected by the pro or free versions? I need this asset for a small team on a unity collab, do we both need to buy the asset?
     
  35. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Pro or Free doesn't affect how it works.

    Please contact me directly and we can talk about the licensing.
     
  36. unity_VEvDQJr3VRwigA

    unity_VEvDQJr3VRwigA

    Joined:
    Oct 11, 2018
    Posts:
    1
    Hello,

    I would like to know how many BLE peripheral I can connect to at the same time ?
     
  37. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    That is not controlled or determined by the plugin. It is entirely up to the OS of the device you are using the plugin on. Most modern Phones don't have any real limit, but some devices might. If they do it is usually more than 10 at least.
     
  38. talyh

    talyh

    Joined:
    Dec 2, 2016
    Posts:
    20
    Hi there.

    We have the cycle of Scan / Connect / Subscribe / Write working well.
    However, we'd like to turn some of the Characteristics (created in our proprietary hardware) to be indications instead of notifications.

    Is that something the BLE plugin would support? And, if so, what changes (if any) would we need to make to the Subscription / Writing associated to those characteristics?

    Thanks!
     
  39. Majid468

    Majid468

    Joined:
    Feb 11, 2017
    Posts:
    3
    Hi there,
    I got status 133 while connecting to BLE device i.e, Stylus Pen.
    I only able to connect the device with Android version 7.0. nothing more nothing less....
    any help..???
     
  40. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    The plugin already automatically will use indication or notification based on the properties it finds in the characteristic when it enumerates them.
     
  41. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Hopefully someone can help Majid because I have exhausted all I know in email trying to help. I am already doing the check for the Android version being greater than or equal to Android 6 and if so I am passing the TRANSPORT_LE parameter in to the connect command.

    For some reason Majid is not able to get Android 6 devices to work anyway. I have no idea why that is the case.
     
  42. exsurgo_ankit

    exsurgo_ankit

    Joined:
    Feb 5, 2020
    Posts:
    29
    Hello Tony,
    I have just started using your plugin. It works well but I can't figure out how to handle the unitybluetoothLE errors.
    For example, the bluetooth peripheral has reset and lost connection but through the plugin we keep trying to subscribe to characteristics. The Android debug logs show the exception.

    Here are the logs, we want to handle this error.
    2020-02-07 10:26:14.923 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: subscribe characteristic
    2020-02-07 10:26:14.928 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Part: 0 - Error
    2020-02-07 10:26:14.928 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Part: 1 - Failed to set characteristic notification
    2020-02-07 10:26:14.930 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Error during initialize: Failed to set characteristic notification
    2020-02-07 10:26:19.264 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: subscribe characteristic
    2020-02-07 10:26:19.268 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Part: 0 - Error
    2020-02-07 10:26:19.268 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Part: 1 - Failed to set characteristic notification
    2020-02-07 10:26:19.269 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: Error during initialize: Failed to set characteristic notification
    2020-02-07 10:26:24.278 10465-10502/com.XXXXX.YYYY I/UnityBluetoothLE: subscribe characteristic

    regards
    Ankit
     
  43. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Errors come in asynchronously to the second method passed in to the Initialize method. You can watch for errors there.

    On top of that if the peripheral has disconnected you should get notified in the disconnect callback you pass into the connect method. You should be able to deal with it that way as well.
     
  44. exsurgo_ankit

    exsurgo_ankit

    Joined:
    Feb 5, 2020
    Posts:
    29
    Hello Tony,

    Thank you for sharing the callback information. That has helped. I would like to run a scan without requiring the location services to be enabled. I understand that permission for location are required for Android but if the api used StartDiscovery then the location services don't need to be enabled. Is this possible with the plugin?
     
  45. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    As far as I know you have to have location permissions no matter what. For some reason they are tied together.
     
  46. exsurgo_ankit

    exsurgo_ankit

    Joined:
    Feb 5, 2020
    Posts:
    29
    Hello Tony,

    I will rephrase the question. Can I modify the code to call StartDiscovery rather than apiScan?
     
  47. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    No. You cannot modify the source code to call startDiscovery.
     
  48. exsurgo_ankit

    exsurgo_ankit

    Joined:
    Feb 5, 2020
    Posts:
    29
    Hello Tony,

    We are noticing that the BluetoothDeviceScript discards data on one android device periodically when the Garbage Collection runs but works just fine on other android device. Both devices are running Android version 9.0 but have different kernels. Using the profiler in unity we can see that the spikes are related to OnBluetoothMessage. We also see incorrect length of data when this happens which causes the data bytes to be discarded.

    Is there a way to tweak the buffer sizes to avoid this issue? We are only transmitting 4500 bytes every second. The connection interval gets set to 24 ms, so we limit single transaction to less than 150 bytes.

    Can we control the connection interval and set it to a lower value?

    regards
    Ankit
     
  49. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    You have found the biggest annoyance of Android. Differences between devices.

    The only way you can be sure to all bytes make it is to limit the number of bytes to 20. The standard BLE packet size. Trying to send larger packet sizes will result in lots packets on some phones.

    I have added the ConnectionInterval setting. If you have the latest that setting should be in there. It defaults to medium, but you can set it to high.
     
  50. exsurgo_ankit

    exsurgo_ankit

    Joined:
    Feb 5, 2020
    Posts:
    29
    Hello Tony,

    Thank you for a quick response.

    Where can I find this ConnectionInterval setting? I can only see ConenctionPrioirty in the BluetoothDeviceScript. If it ConnectionPriority then should be set before connection?

    Regarding the BLE packet size, we are using Data Length Extensions and the tablets support Bluetooth 5.0 so our packet sizes are 100+ bytes. The stutter is periodic and at exact intervals with garbage collection.

    Regards
    Ankit