连接蓝牙,配网

This commit is contained in:
fengjignqi
2026-06-04 14:30:24 +08:00
parent 0f9c8c7329
commit 7e63101fc9
7 changed files with 850 additions and 180 deletions

View File

@@ -0,0 +1,125 @@
package com.ckkj.water.espBle;
import android.os.Build;
import com.espressif.provisioning.ESPConstants;
/**
* @author fengxiaoyang
* @date 2026/6/4
* @description 蓝牙配网配置管理类
*/
public class ProvisionConfig {
/**
* ESP BLE Service UUID
*/
public static final String SERVICE_UUID =
"0000ffff-0000-1000-8000-00805f9b34fb";
/**
* ESP BLE Characteristic UUID for writes
*/
public static final String CHARACTERISTIC_UUID =
"0000ff01-0000-1000-8000-00805f9b34fb";
/**
* ESP BLE Characteristic UUID for notifications
*/
public static final String NOTIFY_UUID =
"0000ff02-0000-1000-8000-00805f9b34fb";
/**
* 设备传输的协议类型
*/
public static final String TRANSPORT_BLE = "ble";
/**
* 设备前缀 (用于过滤设备)
*/
public static final String DEVICE_PREFIX = "PROV_";
/**
* 安全类型 - SECURITY_0 (无安全)
*/
public static final int SECURITY_0 = ESPConstants.SecurityType.SECURITY_0.ordinal();
/**
* 安全类型 - SECURITY_1 (推荐)
*/
public static final int SECURITY_1 = ESPConstants.SecurityType.SECURITY_1.ordinal();
/**
* 默认安全类型
*/
public static final int DEFAULT_SECURITY = SECURITY_1;
/**
* 连接超时时间 (毫秒)
*/
public static final int CONNECTION_TIMEOUT = 30000;
/**
* 配网超时时间 (毫秒)
*/
public static final int PROVISION_TIMEOUT = 120000;
public static final int ERROR_NOT_INITIALIZED = 1000;
public static final int ERROR_INVALID_DEVICE = 1001;
public static final int ERROR_CONNECT_TIMEOUT = 1002;
public static final int ERROR_CONNECT_FAILED = 1003;
public static final int ERROR_NOT_CONNECTED = 1004;
public static final int ERROR_SESSION_FAILED = 1005;
public static final int ERROR_WIFI_CONFIG_FAILED = 1006;
public static final int ERROR_WIFI_APPLY_FAILED = 1007;
public static final int ERROR_PROVISION_FAILED = 1008;
public static final int ERROR_PROVISION_TIMEOUT = 1009;
public static final int ERROR_WIFI_SCAN_FAILED = 1010;
/**
* 配网版本 (可根据实际固件调整)
*/
public static final String VERSION = "v1.1";
/**
* 生成蓝牙扫描过滤器
* @return 服务UUID数组
*/
public static String[] getScanServiceUuids() {
return new String[]{SERVICE_UUID};
}
/**
* 生成设备前缀过滤器 (用于过滤非ESP设备)
* @return 设备前缀
*/
public static String getDevicePrefix() {
return DEVICE_PREFIX;
}
/**
* 获取当前Android版本号
* @return Android版本号
*/
public static int getAndroidVersion() {
return Build.VERSION.SDK_INT;
}
/**
* 检查是否为Android 10及以上版本
* @return true 表示支持
*/
public static boolean isAndroid10OrAbove() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
}
}