October 22, 2013

Querying RSSI by the App

I have mentioned before that we have 2 ways to check for signal strength (which then approximates distance) of the bluetooth communication in our system, particularly between the App and the Rpi.

    1. Query done by Rpi
    2. Query done by Android App

I have not yet checked on how I can get the first step done programmatic-ally, for the purpose of integrating it into our Server program. This example showed how it is done via terminal : forum link.

However, I have a written a simple app for the 2nd method. This App catches the RSSI values of every bluetooth devices it found during 'discovery' by requesting an extra field in ACTION_FOUND intents of the discovery : EXTRA_RSSI. This value (of data type Short) contains the RSSI value of the remote devices found.

Here is the snippet on how it is done:

// Create a BroadcastReceiver for ACTION_FOUND
BroadcastReceiver receiver;
receiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
           
    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
           
    // Get the BluetoothDevice object from the Intent
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
               
    // Add the name and address to an array adapter to show in a ListView
     mArrayAdapter.add(device.getName() + "\n" + device.getAddress() + "\n" + rssi + " db" + "\n" );
              
    //add notify discovery is done
    Toast.makeText(getApplicationContext(),"Bluetooth devices discovery done...", Toast.LENGTH_SHORT).show();
       
     }
     }
};

In short, we can get the signal strength of any discovered bluetooth devices, without even having to connect to those devices. Hence, 'signal strength' or more correctly, 'distance between the user and the door' verification can be done first before 'key' verification. Refer HERE to see the methods we proposed earlier.

Here is the updated version of the App (remove the RSSI values display through toast, put them into the list view instead).



Downloads:
Apk
MainActivity (main code)
Project files (all)



October 11, 2013

Measuring distance between user and the door



We have no way of measuring distance directly between the user (the phone) and the door. However, we can safely approximate the distance by querying the "strength" of the received signal of the Bluetooth communication. The term is called Bluetooth Received Signal Strength Indication (RSSI). RSSI is the relative received signal strength in arbitrary units.

In short, the closer the distance, the bigger the strength of the received signal, the bigger the RSSI numbers.

In our case, we have two ways to implement this:
  1. The Rpi does the query for signal strength and responses (to command the microcontroller to unlock the door) only when the signal strength is within the safe operating range.
  2. The App (instead of the Rpi), which initiates the connection, sends the signal ("within range" or "not within range") along with key based on the received signal strength (Android is able to provide this automatically on each Bluetooth connection or we can use one of the public methods to query manually) of the Rpi.
However, both methods relies heavily on the actual Bluetooth devices that we are using. We need to do some test on our own to approximate better (sadly we only have one Bluetooth dongle that works with Rpi at this moment).

This is one example I've got from the net which should give us some approximations:

          RSSI              Position
          38                   Phone touching Bluetooth dongle
          25                   Phone an inch away
          10                   Phone about 6 inch away
          0                     From 2 feet to opposite side of room
          -3                    In next room (with a wall between)
          -10                  2 walls away

source:
Link1
Link2
Link3





October 10, 2013

Unlocking : sending keys and verification

In the last meeting, we discussed on how we can implement the verification of the key in the most efficient way, while not risking the security aspect of the system.

We agreed that we would be implementing a distance measuring mechanism (I'll write about it in another post), in which the door is to be set "ready to be unlocked" only when the user is within the safe distance from the door (2-3 meters).

This adds another type of verification which is the distance between the user and the Rpi itself.

The figure above shows how Rpi is used to validates both 'distance' and 'key'. Alternatively, 'distance' can be validated via the Android App itself.