title: How can I receive data from a BLE Device?
body: <p>So, I am developing a Java BLE Android Module using Eclipse (to code the module and Appcelerator (to make the Android App). I am trying to receive data from a BLE Device and show it on an Android Phone. I can scan the device and connect to it.</p>
  <p>But I really, really can't receive any data from it.
  I have tried at least 10 different stuff but...
  The main problem is that I don't know the BLE API very well, and I am a little noobie in Java. Can anyone please help a poor soul to actually read the data from the device?</p>
  <p>The main problem is setting the Bluetooth Characteristic UUID (which I have). I just don't know how to do it...
  Bellow are the codes for the Module...</p>
  <pre><code>public class AndroidbleModule extends KrollModule {
      
    public static final String LCAT = &quot;BLE&quot;;
    private BluetoothManager btManager;
    private BluetoothAdapter btAdapter;
    private BluetoothDevice btDevice;
    private TiApplication appContext;
    private Activity activity;
    private KrollFunction onFound;
    private KrollFunction onConnections;
    private BluetoothLeScanner btScanner;
    private UUID uuid;
  
    BluetoothGatt bluetoothGatt;
    BluetoothGattCharacteristic btChar;
    BluetoothGattCallbackHandler btData;
    KrollDict kd;
    Boolean isConnected = false;
    BluetoothGatt connectedGatt;
          
    private ScanCallback scanCallback = new ScanCallback() {
    @Override
    public void onScanResult(int callbackType, ScanResult result) {
  
    BluetoothDevice device = result.getDevice();
      if (device != null) {
      BluetoothDeviceProxy btDeviceProxy = new 
    BluetoothDeviceProxy(device);
      if (device.getName() != null) {
        Log.d(LCAT, &quot;Found: &quot; + device.getName() + &quot; &quot; + 
    device.getAddress());  
      ArrayList&lt;String&gt; ids = new ArrayList&lt;String&gt;();    
      if (device.getUuids() != null) {
               for (ParcelUuid id1 : device.getUuids()) {
      ids.add(id1.toString());
      }
      }
      btDevice = device;
      kd = new KrollDict();
      kd.put(&quot;name&quot;, btDevice.getName());
      kd.put(&quot;macaddress&quot;, btDevice.getAddress());
      fireEvent(&quot;nb_DevicesFound&quot;, kd); 
                       
      btScanner.stopScan(scanCallback);
        }
       }
      }
    };
      
    @Kroll.method
    public boolean connect()
    {
     try {
      bluetoothGatt = btDevice.connectGatt(appContext, true,
      new BluetoothGattCallbackHandler(AndroidbleModule.this));
      if (bluetoothGatt != null) {
      System.out.println(&quot;*****     *****     Connected to: =====&gt;&gt;&gt;&gt;&gt;    &quot; + btDevice.getAddress() + &quot; &quot; + btDevice.getName());
      this.fireEvent(&quot;nb_onConnect&quot;,null);
      isConnected = true;
      bluetoothGatt = connectedGatt;
          }
    } catch (Exception e) {
      isConnected = false;
      this.fireEvent(&quot;nb_NoConnection&quot;, null);
      }
     return true;
    };
      
    @Kroll.method
    public void readData() 
    {
    System.out.println(&quot;WHAT THE HELL DO I DO????&quot;);
    }
  
  }
  
  public final class BluetoothGattCallbackHandler extends 
    BluetoothGattCallback {
  
  private static final String LCAT = AndroidbleModule.LCAT;
  private KrollProxy proxy;
  private static final String UUID_SERVICE_TS002004 = &quot;6E400001-B5A3-F393-E0A9-E50E24DCCA9E&quot;;
  private static final String UUID_CHARACTERISTIC_WRITE_TS002004 = &quot;6E400002-B5A3-F393-E0A9-E50E24DCCA9E&quot;;
  private static final String UUID_CHARACTERISTIC_NOTIFY_TS002004 = &quot;6E400003-B5A3-F393-E0A9-E50E24DCCA9E&quot;;
  BluetoothGattCharacteristic btCharacteristic;
  
  public BluetoothGattCallbackHandler(KrollProxy proxy) {
      super();
      this.proxy = proxy;
    }
  
    @Override
    public void onConnectionStateChange(final BluetoothGatt gatt,
      final int status, final int newState) {
      KrollDict kd = new KrollDict();
      kd.put(&quot;newState&quot;, newState);
      kd.put(&quot;status&quot;, status);
      if (proxy.hasListeners(&quot;didConnectionStateChange&quot;)) {
          proxy.fireEvent(&quot;didConnectionStateChange&quot;, kd);
      }
      gatt.discoverServices();
      }
  
    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
         super.onServicesDiscovered(gatt, status);
         Log.i(LCAT,&quot;onServicesDiscovered&quot;);
         if (status != BluetoothGatt.GATT_SUCCESS) return;
         btCharacteristic = 
  gatt.getService(UUID.fromString(UUID_SERVICE_TS002004)).getCharacteristic(UUID.fromString(UUID_CHARACTERISTIC_NOTIFY_TS002004));
         gatt.setCharacteristicNotification(btCharacteristic,true);
  
         BluetoothGattDescriptor descriptor = btCharacteristic.getDescriptor(UUID.fromString(UUID_CHARACTERISTIC_WRITE_TS002004));
          
  descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
         gatt.writeDescriptor(descriptor);
    }
  
    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt,
      final BluetoothGattCharacteristic characteristic) {
      byte[] data = characteristic.getValue();
      Log.i(LCAT, &quot;Char changed &quot; + data.toString());
      for (BluetoothGattDescriptor descriptor : 
   characteristic.getDescriptors()) {
   descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
      }
    }
      
    @Override
    public void onCharacteristicRead(BluetoothGatt gatt, 
    BluetoothGattCharacteristic characteristic, int status) {
          super.onCharacteristicRead(gatt, characteristic, status);
          Log.i(LCAT,&quot;onCharacteristicRead&quot;);
      }
      
    @Override
    public void onDescriptorRead(BluetoothGatt gatt, 
    BluetoothGattDescriptor descriptor, int status) {
         super.onDescriptorRead(gatt, descriptor, status);
         Log.i(LCAT,&quot;onDescriptorRead&quot;);
    }
  }
  </code></pre>
  <p>I expect to some good soul that will go to Heaven to have mercy on me and help me get those sweet bytes of data.</p>