void Start() { try{ Debug.Log("HI"); BluetoothHelper.BLE = true; //use Bluetooth Low Energy Technology bluetoothHelper = BluetoothHelper.GetInstance(); bluetoothHelper.OnConnected += () => { Debug.Log("Connected"); sendData(); }; bluetoothHelper.OnConnectionFailed += () => { Debug.Log("Connection failed"); }; bluetoothHelper.OnScanEnded += OnScanEnded; bluetoothHelper.OnServiceNotFound += (serviceName) => { Debug.Log(serviceName); }; bluetoothHelper.OnCharacteristicNotFound += (serviceName, characteristicName) => { Debug.Log(characteristicName); }; bluetoothHelper.OnCharacteristicChanged += (value, characteristic) => { Debug.Log(characteristic.getName()); Debug.Log(System.Text.Encoding.ASCII.GetString(value)); }; BluetoothHelperService service = new BluetoothHelperService("FFE0"); service.addCharacteristic(new BluetoothHelperCharacteristic("FFE1")); BluetoothHelperService service2 = new BluetoothHelperService("180A"); service.addCharacteristic(new BluetoothHelperCharacteristic("2A24")); bluetoothHelper.Subscribe(service); bluetoothHelper.Subscribe(service2); bluetoothHelper.ScanNearbyDevices(); }catch (Exception ex) { Debug.Log(ex.Message); } }
void Start() { try { BluetoothHelper.BLE = true; //use Bluetooth Low Energy Technology bluetoothHelper = BluetoothHelper.GetInstance(); bluetoothHelper.OnConnected += OnConnected; bluetoothHelper.OnConnectionFailed += OnConnectionFailed; bluetoothHelper.OnDataReceived += OnMessageReceived; //read the data bluetoothHelper.OnScanEnded += OnScanEnded; bluetoothHelper.setTerminatorBasedStream("\n"); bluetoothHelper2 = BluetoothHelper.GetNewInstance(); bluetoothHelper2.OnConnected += OnConnected2; bluetoothHelper2.OnConnectionFailed += OnConnectionFailed2; bluetoothHelper2.OnScanEnded += OnScanEnded2; bluetoothHelper2.OnCharacteristicChanged += (value, characteristic) => { Debug.Log(characteristic.getName()); Debug.Log(System.Text.Encoding.ASCII.GetString(value)); }; BluetoothHelperService service = new BluetoothHelperService("180D"); service.addCharacteristic(new BluetoothHelperCharacteristic("2A37")); service.addCharacteristic(new BluetoothHelperCharacteristic("2A38")); service.addCharacteristic(new BluetoothHelperCharacteristic("2A39")); bluetoothHelper2.Subscribe(service); bluetoothHelper.ScanNearbyDevices(); text.text = "start scan"; } catch (BluetoothHelper.BlueToothNotEnabledException ex) { sphere.GetComponent <Renderer>().material.color = Color.yellow; Debug.Log(ex.ToString()); text.text = ex.Message; } }
void Start() { timer = 0; try{ Debug.Log("HI"); BluetoothHelper.BLE = true; //use Bluetooth Low Energy Technology bluetoothHelper = BluetoothHelper.GetInstance(); bluetoothHelper.OnConnected += (helper) => { List <BluetoothHelperService> services = helper.getGattServices(); foreach (BluetoothHelperService s in services) { Debug.Log("Service : " + s.getName()); foreach (BluetoothHelperCharacteristic item in s.getCharacteristics()) { Debug.Log(item.getName()); } } Debug.Log("Connected"); BluetoothHelperCharacteristic c = new BluetoothHelperCharacteristic("ffe1"); c.setService("ffe0"); bluetoothHelper.Subscribe(c); //sendData(); }; bluetoothHelper.OnConnectionFailed += (helper) => { Debug.Log("Connection failed"); }; bluetoothHelper.OnScanEnded += OnScanEnded; bluetoothHelper.OnServiceNotFound += (helper, serviceName) => { Debug.Log(serviceName); }; bluetoothHelper.OnCharacteristicNotFound += (helper, serviceName, characteristicName) => { Debug.Log(characteristicName); }; bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) => { Debug.Log(characteristic.getName()); Debug.Log(value[0]); }; // BluetoothHelperService service = new BluetoothHelperService("FFE0"); // service.addCharacteristic(new BluetoothHelperCharacteristic("FFE1")); // BluetoothHelperService service2 = new BluetoothHelperService("180A"); // service.addCharacteristic(new BluetoothHelperCharacteristic("2A24")); // bluetoothHelper.Subscribe(service); // bluetoothHelper.Subscribe(service2); // bluetoothHelper.ScanNearbyDevices(); // BluetoothHelperService service = new BluetoothHelperService("19B10000-E8F2-537E-4F6C-D104768A1214"); // service.addCharacteristic(new BluetoothHelperCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214")); //BluetoothHelperService service2 = new BluetoothHelperService("180A"); //service.addCharacteristic(new BluetoothHelperCharacteristic("2A24")); // bluetoothHelper.Subscribe(service); //bluetoothHelper.Subscribe(service2); bluetoothHelper.ScanNearbyDevices(); }catch (Exception ex) { Debug.Log(ex.StackTrace); } }