迅鸣物联网文档

迅鸣物联网文档


Android BLE锁SDK 说明

[TOC]

Android BLE锁SDK 使用说明

仅支持Android6+

用到的权限

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

下载地址

  1. [SDK](https://xunmingiot.oss-cn-beijing.aliyuncs.com/Android/classes.jar "SDK")
  2. [DEMO](https://xunmingiot.oss-cn-beijing.aliyuncs.com/Android/demo.zip "DEMO")

使用方法

import com.xunmingiot.blesdk.ble.BleLockListener;
import com.xunmingiot.blesdk.ble.OpenApi;
public class OpenActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "OpenActivity";
    private EditText edTextMac;
    private EditText edTextPwd;
    private Button btnStart;
    private TextView resE;
    private TextView resM;
    private String mac = "AA:BB:11:22:33:12";
    private String pwd = "00000000";
    private final BleLockListener bleLockListener = new BleLockListener() {
        @Override
        public void onReadBleLockStatus(Map<String, String> res) {

        }

        @Override
        public void onUnlock(Map<String, String> res) {

        }

        @Override
        public void onFail(Map<String, String> res) {

        }

        @Override
        public void onReadConfig(Map<String, String> res) {

        }

        @Override
        public void onSetConfig(Map<String, String> res) {

        }

        @Override
        public void onSetPassword(Map<String, String> res) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("开锁");
        setContentView(R.layout.activity_open);
        initView();
    }

    private void initView() {
        edTextMac = (EditText) findViewById(R.id.ed_text_mac);
        edTextPwd = (EditText) findViewById(R.id.ed_text_pwd);
        btnStart = (Button) findViewById(R.id.btn_start);
        resE = (TextView) findViewById(R.id.res_e);
        resM = (TextView) findViewById(R.id.res_m);
        btnStart.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_start:
                //获取mac和pwd
                // 1. mac地址
                // 2. password
                // 3. bleLockListener
                // 4. 扫描超时时间(ms) 可不传默认25s
                // 5. config 配置(16进制字符串20位)
                // 6. 新旧密码8位字母/数字,区分大小写
                OpenApi.openLock(OpenActivity.this, mac, pwd, bleLockListener, 10000);
                OpenApi.getLockStatus(this, mac, password, bleLockListener);
                OpenApi.getLockConfig(this, mac, password, bleLockListener);
                String config = "11044C100A000103200B";
                OpenApi.setLockConfig(this, mac, password, config, bleLockListener);
                String oldPwd_1 = "11111111";
                String newPwd_1 = "00000000";
                OpenApi.setLockPassword(this, mac, oldPwd_1, newPwd_1, bleLockListener);
        }
    }

    private String isMac(String mac) {
        if (BluetoothAdapter.checkBluetoothAddress(mac)) {
            return mac;
        } else {
            return null;
        }
    }
}

已暴露openApi接口

  • openLock(Context ctx,String mac,String pwd,BleLockListener listener,int timeout)
  • getLockStatus(Context ctx,String mac,String pwd,BleLockListener listener,int timeout)
  • getLockConfig(Context ctx,String mac,String pwd,BleLockListener listener,int timeout)
  • setLockConfig(Context ctx,String mac,String pwd,String config,BleLockListener listener,int timeout)
  • setLockPassword(Context ctx,String mac,String pwd,String newPwd,BleLockListener listener,int timeout)

config解析

11044C100A000103200B

  • 11 :11/10 是/否开启设备主动断开蓝牙连接
  • 044C: 16进制(0-65535)主动断开蓝牙连接的时间,单位10ms(044C->1100->11秒)
  • 10: 11/10 是/否开启开锁重试
  • 0A:16进制 开锁重试次数(0-255)(0A->10次)
  • 0001:16进制 每次开锁保持时间(单位10ms)范围0-65535
  • 0320:16进制 蓝牙广播频率(单位0.625ms) 不可超过5s,正常使用在500ms-1000ms
  • 0B: 16进制 信号发射功率 决定蓝牙设备的信号强度 范围 1-15,功率过高,频率过快会增加待机电量损耗,正常使用11

onFail错误码

  • 0004: 扫描超时
  • 0003: 非正常于设备断开连接
  • 0001:密码错误
  • 0002: 锁被卡住(用于钛丝锁未拉开钛丝的情况)

注意

  • Android 需要检查Location权限,请自行向用户申请权限
  • 若开启蓝牙主动断开,则主动断开时间应大于开锁重试次数于每次开锁保持时间的乘积,否则会出现提示开锁失败但是锁过会儿才打开的情况

页面列表

ITEM_HTML