BLE challenge response smartphone authentication - android

I want to build a simple challenge response protocol in order to authenticate a user to an Arduino via the smartphone (Android and iOS) using BLE. I'm having problems seeing how this would be implemented with BLE. What I want to do:
Arduino sends/broadcasts a challenge
Smartphone receives challenge and computes response
Smarpthone sends response to Arduino
The way I thought about implementing this is to have the Arduino (peripheral and server) start advertising when a button is pressed. Ideally an event would be triggered on the smartphone (central and client) when a certain service shows up. Then the smartphone connects to Arduino, reads the challenge characteristic and writes the response to it. Is this a good approach?
It appears though that it is not possible to trigger an event when a BLE service appears and I would continuously need to scan with the smartphone which is very battery intensive. Not sure how to get around this? Geofencing is not really an option since it can be inside. Maybe detecting if the user is walking, biking, standing still? Any suggestions are greatly appreciated =).

On iOS BLE connectivity looks like this:
initialize CBluetoothManager,
start discovering devices through bluetooth.
when found particular peripheral that u're intrested in, connect to it via core manager and store this peripheral variable in ur Class,
then.. u should STOP discovering cuz it's terrible for batteries ;) (as u said),
after device's found, you can search through services, characteristic and at the end through descriptors <-- IN THIS ORDER otherwise u won't get any of these,
ofc, from now on you're able to store each of these vars in your Class and work with them as you wish to. BLE on iOS's based on delegates and it's own lifecycle, each time when there will be something to read the event will trigger. When you will want to send some msg to Arduino back it shouldn't be a problem. In the partial answer for your question about
'when a certain service shows up. THEN the smarphone connects to
Arduino.'
you have to make steps ABOVE in order to read services. Hope that helps.

Related

Is it possible to use bluetooth as proximity detector?

Actors:
Server: is a rooted Android device, that never sleep (never goes in standby)
Client: is one of many non-rooted smartphone, Android or IOS
Scenario:
The server is fixed in a place.
Server need to know when some client is near, without user intervention, identifying that device.
The client is switched on but can be in standby (with screen off).
I can install custom app both to client and server.
Target to achieve:
When a client comes near the server, the server knows it, without user intervention.
Detection does not need user intervention, but maybe is possibile the first time that users has to do some configuration to register the server bluetooth.
Questions:
Is it possibile to achieve it?
Both for Android and IOS clients?
Which solutions does I have to implement?
Thank you in advance
Just an idea but with ble you can do an advertisement with a packet of data.
Have an app that advertises some data for the client app.
Then on the server application receive these values by performing a ble scan.
Within this scan you can see the device address, scan record data(advertisement) and the RSSI. The rssi is the received power. From this you should be able to infer distance. As if the RSSI is lower then the device is further away thus a proximity detector. So if the RSSI is above a certain value add this device to a list to say they are in your detector range.

Does Android app needs to perform Central and Peripheral roles at same time to send and receive data over BLE?

Currently, I am developing an app which is communicating with one BLE Hardware which is receiving commands and responding back the command response. To Simulate hardware, We have developed one iOS Simulator app, which is working in Peripheral and responding back on requested command. But Somehow, As and when I try to write to the write characteristics, I got the status = BluetoothGatt .GATT_REQUEST_NOT_SUPPORTED in the onCharacteristicWrite callback. But somehow, I came to know that we need to implement the Central and Peripheral roles into Android app.
But I am still not sure, Do we need to implement Peripheral role as well to send and receive data in multiple packets.
I am developing the app using following nice blog post:
- https://medium.com/#avigezerit/bluetooth-low-energy-on-android-22bc7310387a
- https://android.jlelse.eu/android-bluetooth-low-energy-communication-simplified-d4fc67d3d26e
- https://www.bignerdranch.com/blog/bluetooth-low-energy-on-android-part-2/
And using following repo as learning point of view:
- https://github.com/bignerdranch/android-bluetooth-testbed/tree/a/android-ble-part-3
Thanks in advance!
Typically your phone app is the central and it communicates with a peripheral device over Bluetooth. If you want to send data to the peripheral, you can write a characteristic in the phone app, given writing is enabled for that characteristic. Your central can get data from the peripheral in 2 ways: it can either read a characteristic (if it's enabled) from the peripheral or receive notifications from the peripheral (if it's enabled). So if all you have is a central (phone app) and a peripheral (some kind of Bluetooth device) and you want to send data back and forth, you don't need to have both central and peripheral roles in the phone app. If you have some special stuff going on, it might be different for you, I don't know. I'm talking about a typical setup.
If you want to send commands to the peripheral, you could write those commands to a characteristic. The peripheral could in turn respond with notifications. This is basically the way I develop a Bluetooth solution, but it can be different depending what you want to achieve.
It takes two devices to communicate with each other.
Device A:
It will be Peripheral device which will be advertising the data. i.e.: Beacons, BLE Hardware
Device B:
It will be Central device which will send request for read,write. i.e.: Mobile
Setup for Device A:
If you don't have Peripheral, there is a way to make your android mobile to act like a Peripheral if your device is supporting that advance feature.
So before beginning, you may simply check that by using following app:
https://play.google.com/store/apps/details?id=com.kyriakosalexandrou.bluetoothsupportcheck
To make your device act like Peripheral, you may install following app which simply simulates the GATT and advertising:
https://play.google.com/store/apps/details?id=com.ble.peripheral.sim
Important: Setup service and characteristics based on your requirements, make sure characteristic is write enabled if you want write data on it.

Get descriptor value from a BLE node

I am a newbie to Android app coding and I am currently writing an Android app to scan BLE beacons nearby and get the data inside the beacon. Currently I am using LightBlue Explorer which is an iOS app as a BLE beacon for broadcasting data.
I want my app to receive data broadcasted by the beacon. First of all, should I use 'descriptor' as a place for putting the data? (Since I can set the characteristic user description and descriptor value inside LightBlue Explorer) If so, how can I get the value of a descriptor in my app? For now, I can get the service and the characteristics of that beacon. Thanks a lot!
I am not familiar with beacons, but i have worked on BLE devices. SO i might say you a thing or two to start conversation thread.
BLE devices around you gives out broadcast information regarding the device itself necessary for establishing the connection with device itself.
So you cant directly access the data within the device without prior connection.
This is called Generic Access Profile (GAP)
Once after establishing the connection with the device and the app(Mobile) you have to use Generic Attribute Profile (GATT) to get data necessary for the device.
You can receive data after connection by two ways.
1) Write & Notify
2) Write & Read
1) In this you have to write necessary command on the specified write characteristic for specific service on the device and device will push the necessary data on the specific Notify characteristic. Make sure the notify characteristic is enabled
2) In this you have to write necessary command on the specified write characteristic for specific service on the device and then you have to request read to the device from the app, then from the read port you can get the data given by the device.
I hope you get kinda of idea about BLE working. I have worked on BLE devices on Android side.
If any doubts just reply to thread.
To others if any correction you feel is needed, please reply.
Thank You.

Android: bluetooth listen thread for incomming data only

i am working on an android app in which I need to only listen for incoming devices an log the data they are sending using Bluetooth, device sending data is basically a digital Bluetooth enabled thermometer which just sends the data. Problem is i don't know where to start as i m new to android programming. Just a step by step Procedure would be enough to guide me on the right track . i tried Bluetooth chat example but i didn't took me any where also i wasn't able to understand it.
Regards,
Rafiq Ahmed
First thing you need is to know how to make the connection with the thermometer. I suppose that, since the device is paired to the smartphone, you only must to manage the connection as a server (On the android-phone). Here you got a summarize:
Change Bluetooth permissions:
http://developer.android.com/guide/topics/connectivity/bluetooth.html#Permissions
Enable and set up the bluetooth: http://developer.android.com/guide/topics/connectivity/bluetooth.html#SettingUp
Find the device: http://developer.android.com/guide/topics/connectivity/bluetooth.html#FindingDevices
Connect with it: http://developer.android.com/guide/topics/connectivity/bluetooth.html#ConnectingAsAServer
And manage the connection:
http://developer.android.com/guide/topics/connectivity/bluetooth.html#ManagingAConnection
And last thing, I recommend you to pair the device before running the application, at the adjust menu of your mobilephone. Since that, follow the previous steps and all will be fine. If you have some doubt ask me, I had the same troubles about bluetooth connections with arduino and HC-06 bluetooth device
Hope it helps

Adapting Android Bluetooth Chat for multiple devices

I'm doing a college project on Bluetooth for Android, and I'm trying to understand how to manage communication between multiple connected devices. Eventually I'm going to develop a multiplayer Bluetooth Game.
Currently I've adapted Android's sample app BluetoothChat to connect my three Nexxus One phones.
1 connects to 2 who connects to 3
1 sends its messages successfully to 2. 3 sends its messages successfully to 2 as well. 2 can send its messages successfully to 1 and 3, as it shares a ConnectedThread with both. But I can't figure out how to handle getting communication from 1 to 3.
Does anyone have any examples of communication between multiple devices or has done this themselves? Thanks
One way is to annotate your messages with the sender and receiver, so that when 2 gets the message, it knows to deliver it on to 3. When 3 gets a message, it checks the receiver attribute to know it is from device 1. This extra layer allows you to send and receive messages through other devices and still be able to know who it is from.
First, though, you'll need to figure out how to make every device know about every other device on the network. If you're just connecting in a line, like 1-2-3-4, then every time a device enters the network, you could send an updated list through the network, but what happens if 2 drops out? Do you just quit the game? Wait for it to be re-paired? In this case, it may be better to look at a peer-to-peer network, or the typical client server architecture where you let one device be the host, especially if this is intended to later be a multiplayer game.
Hope that helps!
It is possible to have multiple Bluetooth sockets in use simultaneously so you may also consider configuring to act as a server, like an IRC or XMPP server, which brokers all communication from any client to another.
If you're going for fault-tollerance (for example server socket goes down) then upon connecting to the server, it might provide a list of recently-seen Bluetooth devices which you could fall-back on in the event the server goes down.

Categories

Resources