TShopping

 找回密碼
 註冊
搜索
查看: 2150|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 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, 2024-4-26 11:56 , Processed in 0.064224 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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