找回密碼
 註冊
搜索
查看: 2664|回復: 0

[教學] 如何在Android BLE 發送數據 ESP32 ?

[複製鏈接]
發表於 2020-4-28 16:47:38 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
上篇 Android BLE ESP32的onCharacteristicChanged沒有回撥及getDescriptor null

接著就是要寫入數據到 ESP32 了

  1. public boolean send(byte[] data) {
  2.     if (mBluetoothGatt == null || mBluetoothGattService == null) {
  3.         Log.w(TAG, "BluetoothGatt not initialized");
  4.         return false;
  5.     }

  6.     BluetoothGattCharacteristic characteristic =
  7.             mBluetoothGattService.getCharacteristic(UUID_SEND);

  8.     if (characteristic == null) {
  9.         Log.w(TAG, "Send characteristic not found");
  10.         return false;
  11.     }

  12.     characteristic.setValue(data);
  13.     characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
  14.     return mBluetoothGatt.writeCharacteristic(characteristic);
  15. }
複製代碼


這時必須給予BluetoothGattServicer及BluetoothGattCharacteristic的UUID
就可以了

這時就會遇到下篇的問題
如何在Android BLE 發送到 ESP32 超過20個字元的數據?
展示影片


參考文章
https://stackoverflow.com/questions/24135682/android-sending-data-20-bytes-by-ble

來源
http://www.netyea.com

 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-6-16 03:28 , Processed in 0.032452 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表