From 0efa4dfdfad5647abb73d38deb3e8ab5f444e5cb Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期五, 20 三月 2026 17:29:33 +0800
Subject: [PATCH] 2026年03月20日17:29:31

---
 app/src/main/java/com/hdl/photovoltaic/utils/BleWifiConfiguratorUtils.java |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/BleWifiConfiguratorUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/BleWifiConfiguratorUtils.java
index 3ad54ca..3de6a4a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/BleWifiConfiguratorUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/BleWifiConfiguratorUtils.java
@@ -325,8 +325,9 @@
 
         if (bluetoothGatt != null) {
             bluetoothGatt.disconnect();  // 鍏堟柇寮�杩炴帴
-            bluetoothGatt.close();
-            bluetoothGatt = null;
+//            bluetoothGatt.close();
+//            bluetoothGatt = null;
+            Log.d(TAG, "Connecting to 鍏堟柇寮�鏃ц摑鐗欒繛鎺�");
         }
         BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress);
         // 鑷姩杩炴帴 = false锛岄伩鍏嶇郴缁熺紦瀛樿繛鎺�
@@ -369,9 +370,15 @@
                 gatt.discoverServices();
             } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                 isConnected = false;
+                if (bluetoothGatt != null) {
+                    bluetoothGatt.close();
+                    bluetoothGatt = null;
+                }
                 if (connectListener != null) {
                     callbackHandler.post(() -> connectListener.onDisconnected());
                 }
+
+                Log.d(TAG, "Connected to GATT server, onDisconnected");
             }//
         }
 
@@ -457,6 +464,7 @@
                 }
             }
         }
+
         @Override
         public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
             //todo 鍚庨潰鍏肩敤mtc鍒嗗寘鐨勶紝鐩墠榛樿璁剧疆512瀛楄妭
@@ -520,7 +528,7 @@
                 // 绗� 4 姝ワ細鍐欏叆鎻忚堪绗﹀埌璁惧
                 //鈫� 鍙湁鍐欏叆鎴愬姛鍚庯紝鍛婅瘔璁惧绔紝璁惧鎵嶄細寮�濮嬪彂閫侀�氱煡锛�
                 bluetoothGatt.writeDescriptor(descriptor);
-                Log.e(TAG, "writeDescriptor success");
+                Log.d(TAG, "writeDescriptor success");
             }
         }
     }
@@ -542,7 +550,7 @@
      */
     @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
     public void writeCredentials(String data, WriteListener listener) {
-        Log.e(TAG, "writeCredentials :鍑嗗鍐欏叆");
+        Log.d(TAG, "writeCredentials :鍑嗗鍐欏叆");
         this.writeListener = listener;
         if (!isConnected || characteristic == null) {
             if (listener != null) {
@@ -556,7 +564,7 @@
 
     @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
     private void writeCharacteristic(BluetoothGattCharacteristic characteristic, String value) {
-        Log.e(TAG, "writeCharacteristic :寮�濮嬪啓鍏�");
+        Log.d(TAG, "writeCharacteristic :寮�濮嬪啓鍏�");
         if (!this.getMissingPermissions().isEmpty()) {
             callbackHandler.post(() -> this.writeListener.onWriteFailed(-2)); // 娌℃湁鏉冮檺
             return;
@@ -564,7 +572,7 @@
         characteristic.setValue(value.getBytes(StandardCharsets.UTF_8));
         characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
         bluetoothGatt.writeCharacteristic(characteristic);
-        Log.e(TAG, "writeCharacteristic :寮�濮嬪畬鎴�");
+        Log.d(TAG, "writeCharacteristic :寮�濮嬪畬鎴�");
     }
 
     // ==================== 宸ュ叿鏂规硶 ====================

--
Gitblit v1.8.0