Example #1
0
 void OnConnected()
 {
     sphere.GetComponent <Renderer>().material.color = Color.green;
     try
     {
         List <BluetoothHelperService> services = bluetoothHelper.getGattServices();
         foreach (BluetoothHelperService s in services)
         {
             Debug.Log("Service : " + s.getName());
             foreach (BluetoothHelperCharacteristic item in s.getCharacteristics())
             {
                 Debug.Log(item.getName());
             }
         }
         bluetoothHelper.StartListening();
     }
     catch (Exception ex)
     {
         Debug.Log(ex.Message);
     }
 }
Example #2
0
    void Start()
    {
        timer = 0;
        try{
            Debug.Log("HI");
            BluetoothHelper.BLE          = true; //use Bluetooth Low Energy Technology
            bluetoothHelper              = BluetoothHelper.GetInstance();
            bluetoothHelper.OnConnected += () => {
                List <BluetoothHelperService> services = bluetoothHelper.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 += () => {
                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(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);
        }
    }