简体   繁体   English

Android Ble 服务器 - 只允许以前连接的设备连接

[英]Android Ble Server - Allow only previously connected device to connect

I have an android BLE client and an android BLE server.我有一个 android BLE 客户端和一个 android BLE 服务器。

After the initial connection, I want the server to allow only the previously connected client device to connect.初始连接后,我希望服务器只允许之前连接的客户端设备连接。

How to achieve this?如何实现这一目标?

What I have considered so far:到目前为止我考虑过的:

1. Bond the devices via android Bluetooth settings 1.通过android蓝牙设置绑定设备

Is it possible to allow only bonded devices to connect to the server?是否可以只允许绑定设备连接到服务器? If so, how?如果是这样,如何?

2. Some sort of whitelist 2.某种白名单

  • Mac Address (problematic, as mac addresses are not static) Mac 地址(有问题,因为 mac 地址不是静态的)
  • device name设备名称
  • IRK IRK

Is it possible to implement such a whitelist?有没有可能实现这样的白名单? If so, how?如果是这样,如何?

3. Only advertise for first connection 3. 只为第一次连接做广告

Only advertise for first connection, then remember the server device on the client side and try to connect to the server without advertising.只为第一次连接做广告,然后记住客户端的服务器设备并尝试连接到服务器而不做广告。 This does not seem to work.这似乎不起作用。

Id recommend your second option.我推荐你的第二个选择。 With ble to create a connection you scan devices and then after the scan you can make the GATT connection to them.通过 ble 创建连接,您可以扫描设备,然后在扫描后您可以与它们建立 GATT 连接。 So if you only want previously connected device to make this connection just filter then on the scan callback.因此,如果您只希望以前连接的设备进行此连接,则只需在扫描回调上进行过滤即可。 As you can filter by MAC address.因为您可以按 MAC 地址过滤。 This can be done by storing your list of MAC addresses in the global settings so the data does not reset when the app reopens.这可以通过将您的 MAC 地址列表存储在全局设置中来完成,以便在应用程序重新打开时不会重置数据。 Just add a list of strings with your devices and filter by that.只需在您的设备中添加一个字符串列表并以此过滤即可。

You will also need a one off state for the initial connection.您还需要为初始连接设置一次性状态。 So that if there are no entries in your list then scan freely without a filter.因此,如果您的列表中没有条目,则无需过滤器即可自由扫描。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM