@Override
  public synchronized void onDataAvailable(BluetoothGattCharacteristic characteristic) {
    // UART RX
    if (characteristic.getService().getUuid().toString().equalsIgnoreCase(UUID_SERVICE)) {
      if (characteristic.getUuid().toString().equalsIgnoreCase(UUID_RX)) {
        final byte[] bytes = characteristic.getValue();
        final String data = new String(bytes, Charset.forName("UTF-8"));

        mReceivedBytes += bytes.length;

        final UartDataChunk dataChunk =
            new UartDataChunk(System.currentTimeMillis(), UartDataChunk.TRANSFERMODE_RX, data);
        mDataBuffer.add(dataChunk);
        final String formattedData = mShowDataInHexFormat ? asciiToHex(data) : data;

        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                if (mIsTimestampDisplayMode) {
                  final String currentDateTimeString =
                      DateFormat.getTimeInstance().format(new Date(dataChunk.getTimestamp()));

                  mBufferListAdapter.add(
                      new TimestampData(
                          "[" + currentDateTimeString + "] TX: " + formattedData, mRxColor));
                  // mBufferListAdapter.add("[" + currentDateTimeString + "] RX: " + formattedData);
                  // mBufferListView.smoothScrollToPosition(mBufferListAdapter.getCount() - 1);
                  mBufferListView.setSelection(mBufferListAdapter.getCount());
                }
                updateUI();
              }
            });

        // MQTT publish to RX
        MqttSettings settings = MqttSettings.getInstance(UartActivity.this);
        if (settings.isPublishEnabled()) {
          String topic = settings.getPublishTopic(MqttUartSettingsActivity.kPublishFeed_RX);
          final int qos = settings.getPublishQos(MqttUartSettingsActivity.kPublishFeed_RX);
          mMqttManager.publish(topic, data, qos);
        }
      }
    }
  }
 private String generateHashKey(BluetoothGattCharacteristic characteristic) {
   return generateHashKey(characteristic.getService().getUuid(), characteristic);
 }