GithubHelp home page GithubHelp logo

giomurru / ble-framework Goto Github PK

View Code? Open in Web Editor NEW
83.0 8.0 23.0 1.38 MB

A Unity framework for using bluetooth low energy (BLE) ReadBearLab boards with iOS and Android mobile platforms.

License: MIT License

C# 36.84% HTML 0.33% Objective-C 16.73% C 1.08% Objective-C++ 6.83% Java 26.20% C++ 11.98%

ble-framework's Introduction

BLE framework is a Unity library that you can use to easily manage the Bluetooth communication between your mobile device and a ReadBearLab BLE boards. The supported boards are:

  • BLE Shield
  • BLE Mini
  • Blend Micro
  • Blend
  • BLE Nano
  • RBL nRF51822

The ReadBearLab BLE boards can be attached to a micro controller such as Arduino to allow simple wireless serial communication with your mobile device.

The sample Unity project inside the folder Unity contains two sample scenes to get started using the framework.

  1. RobotServer: build this scene for testing BleMini with Arduino Mega + Adafruit Motor Shield with 4 DC Motors. The code for Arduino is inside the folder Arduino/RobotClient. Read this article for details on how to wire the Adafruit Motor Shield with 4 DC Motors: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/overview
  2. MeteoStation: build this scene for a sample app for temperature and humidity sensor reading. The hardware setup is BleMini with Arduino Mega + Sparkfun RTH03 sensor. Read this article for details on how to wire the humidity and temperature sensor: https://learn.sparkfun.com/tutorials/rht03-dht22-humidity-and-temperature-sensor-hookup-guide/all You can find the code for Arduino inside the folder Arduino/MeteoServer. In both hardware configurations (RobotClient and MeteoServer) the BleMini Rx and Tx pins must be wired respectively to the Tx1 18 and Rx1 19 digital pins of the Arduino Mega 2560.

Before building the Unity project for Android targets, you need to generate the android plugin using the AndroidPlugin project. You can open this project using Android Studio, then click on Run 'copyPlugin' to generate and copy the plugin in the BleFramework/Assets/Plugin/Android folder. Now you are ready to build the Unity project for Android targets. VERY IMPORTANT FOR ANDROID: When running the android example app the first time you have to grant permission for Location in the Android apps settings menu. No popup is prompt asking for permission and you have to grant the Location permission manually. If you don't give Location permission the BLE scan will return empty result.

As mentioned before Android plugin is generated by the AndroidPlugin Android Studio's project. You can find the code inside the 'bleframework/src' subfolder.

As regard iOS you can find the plugin source code inside the folder Unity/Assets/Plugins/iOS/BLE.

If you want to modify the plugins you can just modify the source code in these folders.

ble-framework's People

Contributors

giomurru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble-framework's Issues

No device found on iPhone 6s with iOS 11

Below is the debug log from xcode:

2017-11-15 17:40:25.507969+0800 bleframework[5308:518616] scanForPeripheralsWithServices
2017-11-15 17:40:27.508815+0800 bleframework[5308:518616] Stopped Scanning
2017-11-15 17:40:27.508880+0800 bleframework[5308:518616] Known peripherals : 0
2017-11-15 17:40:27.509323+0800 bleframework[5308:518616] List of currently known peripherals :
2017-11-15 17:40:27.509351+0800 bleframework[5308:518616] No peripherals found
AppControllerBehavior: HandleOnBleDidCompletePeripheralScanErrorEvent: Error scanning for BLE peripherals: Fail: No device found
BLEFramework.Unity.BLEControllerEventHandler:OnBleDidCompletePeripheralScan(String)

How to send data from Unity to Android (via BLE)

Everything works, i.e., I can connect the phone (running your code in Unity, on an android) and my arduino which has a BT LE module. (I see the blue LED that signifies the connection worked).

However, the function _SendData, crashes in runtime with:
07-10 18:38:28.493 4294-4318/? I/Unity: AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference at com.gmurru.bleframework.BleFramework._SendData(BleFramework.java:605) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.a(Unknown Source) at com.unity3d.player.UnityPlayer$b.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJavaObject._Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJavaObject.Call (System.String methodName, System.O

Is this the proper way to send a few bytes through the BT connection? Do I have to initialize a service first? (I do that in my Android Studio app, was trying to replicate in Unity)

Select Characteristic to write to

Hi, I wanted to use this asset in my application to be made in unity. Can I select which services/characteristic I want to write to?

If yes, then how?

If no, then please suggest some solutions?!

TIA

bluetooth LE for android unity

Hello is this plugin works for Raspberry pi zero wirless?? i have to send and receive data between Raspberry and android using unity ! is this works for me?

Unable to run copyPlugin

Importing to latest version of Android Studio doesn't permit Run of copyPlugin.
"You can open this project using Android Studio, then click on Run 'copyPlugin' to generate and copy the plugin in the BleFramework/Assets/Plugin/Android folder."

Is there a way to manually perform the task?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.