3

Have you ever seen the apple watch unlock a Mac? The idea is amazing, but I don't want a smart watch because I already have a phone which has similar capabilities AFAIK. Also, I moved from OSX to Linux recently :)

I don't know how the Apple watch manages to unlock the Mac. But I know what would be desirable from a user experience point of view:

  1. Needs to unlock quicker than I type my password
  2. Should work in absence of wifi/4G
  3. Should be power efficient

RFID

RFID would be nice, but no laptops that I know embed RFID readers.

Bluetooth based proximity detection

The challenge with classic Bluetooth is the requirement to constantly scan for near devices to measure the signal strenght (RSSI) from which we can infer the proximity.

Unfortunately discovery hops and listens 40 channels. And anyway the phones stop broadcasting when screen is off for a while. This is not good enough. I know because I tried:

import collection.JavaConverters._
import tinyb._

object Listener extends App {

  var running = true

  val BT_ADDR = sys.env.getOrElse("BT_ADDR", "XX:XX:XX:XX:XX:XX")
  val BT_RSSI_DBM_THRESHOLD = Integer.parseInt(sys.env.getOrElse("BT_RSSI_DBM_THRESHOLD", "-65")).toShort

  val manager = BluetoothManager.getBluetoothManager
  val lock = new Object

  while (true) {
    manager.getAdapters.forEach(a => {
      a.setRssiDiscoveryFilter(BT_RSSI_DBM_THRESHOLD)
      a.removeDevices()
    })

    System.err.println("scanning for " + BT_ADDR + " at minimum " + BT_RSSI_DBM_THRESHOLD + " dBm RSSI...")

    manager.startNearbyDiscovery(
      (device: BluetoothDevice) => {
        if (BT_ADDR.equals(device.getAddress)) {
          onProximity(device)
          manager.stopNearbyDiscovery()
          lock.synchronized(lock.notify())

        }
        else println(device.getName)
      }
      , 1000
      , false
    )
    lock.synchronized(lock.wait())
  }


}

I was looking at BTLE (Bluetooth Low Energy), and I'm having difficulty to understand the following:

Is there a way to establish from Linux a single low energy bluetooth connection to the Android phone which we can leave dormant all the time, and use it to wake the phone up and make it transmit some packets (so we can measure its RSSI power and infer proximity) on demand, only when strictly needed.

I.e. we'd limit transmissions to only these rare occasions:

  • Check when the user is away if we detect inactive mouse & keyboard for 1 minute,
  • Check if the user is near enough when GDM is active
  • No BT activity whatsoever otherwise

This approach is quick, energy efficient, and does not require network protocol, only some rare BT transmission.

But is this possible with Bluetooth LE? Any pointers to examples?

sscarduzio
  • 5,938
  • 5
  • 42
  • 54

1 Answers1

3

Yes this should be possible with Bluetooth Low Energy (with some caveats) as follows:-

  1. You need a BlueZ script/C program to constantly scan for your Android device.
  2. You need your phone's Bluetooth to always be turned on.
  3. You will need to pair at least once so that your Linux machine recognizes the changeable Bluetooth address of your Android device (see referenced links).

The BlueZ script program should be written so that as soon as your Linux system goes to standby, the program is launched as a daemon or background process that just starts scanning for Android devices and read their RSSI values. If your device is found and the RSSI value indicates that it is within range, this process will signal the Linux OS to wake up.

The caveats:-

  • BLE is not ideal for positioning/locationing; you can probably detect if you're a few metres away but it would be challenging to get an accuracy of a few centimeters.
  • Your BlueZ script needs to be constantly running as a daemon or background process, so if it is somehow killed or is inactive when the device goes to sleep, this will not work.
  • Bluetooth on your phone should be always on, which shouldn't have a big impact on the battery life but is also not recommended.

Some resources for you:-

It will not be a straight forward process and you'll probably have to try and fail along the way, but it will be a learning experience and you should be able to achieve what you want in the end.

I hope this helps.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
  • What if I stick a RFID tag on my laptop, and have Android to initiate a bluetooth connection in response to the RFID event (may require to write a tiny mobile app, I can do that)? Then I can avoid the constant BT broadcasting on the phone, and the constant polling on the locked laptop. WDYT? – sscarduzio Jan 28 '20 at 15:12
  • 1
    I have no experience with RFID neither on the Linux side nor the Android side, but if you are confident that you can get this functionality to work then the rest should be doable. The constant BT broadcasting on the phone is not really a major issue, BLE only consumes a fraction of what WiFi/Data do. Finally, you can set the tx power on the laptop side to -40dBm (using BlueZ) - this will definitely lower the range so that the machine will turn on only in close proximity. – Youssif Saeed Jan 29 '20 at 12:44