I would have to build two apps (Android and iOS) and control some equipment via Bluetooth. For clarification, i cannot just use OS device discovery to connect to the equipment because there's hundreds of them and their position is very important (as well as the user's position when issuing commands), thus it's less of a hassle for operators to just point the phone's camera at a QR code and connect than having to go through a long list of devices with mangled names.
I haven't found many details about specifically using a QR code for bluetooth connections, but i figured that people experienced with this kind of communication will be able to say if it can be done. Please correct me if i'm wrong, but my understanding is that a bluetooth socket is not that different from a TCP one and a connection could be established by knowing the server's credentials.
Can I use a QR code to store device credentials that I can use to establish a connection? It doesn't really matter how much information needs storing, the QR code can contain any sensitive information.
Is there anything more, apart from the UUID, that would need storing on the QR code?
Is it simpler to configure the device as a server and the phone as a client for this specific request? There will be multiple operators that will need to work with these devices.
This is specific to Android and iOS, but if the points above were possible, would I get an OS pop-up window for each connection? Would skipping the discovery step save the operator the hassle of having to confirm the connection to the OS?
If the target device is configured as a server, each with its UUID as the QR code, can i scan that code and open a socket to that very device without manually connecting to it from the phone's menu?
Related
So far I am able to do things two different ways.
I can advertise a service on the Pi, connect from an Android app, and read/write characteristics. From my understanding, this communication is not encrypted.
I have been able to do the same thing adding pairing and bonding to the mix. I advertise a service on the Pi with an agent, connect from an Android app, and as soon as I try to read/write a characteristic I get a prompt on my phone asking to pair. From my understanding, after pairing is succesful the communication is encrypted.
That last part is great. However, I am looking to pair without bonding, mainly because I don't want to end up with a huge list of devices on my bluetooth settings. Android seems to use this term interchangeably, which just makes everything more confusing.
I know it's possible to do it as per this video. I just haven't figured out how to actually do it myself.
Any help is appreciated.
This is totally possible according to the Bluetooth protocol specification. If at least one device sets "bonding flags" to "no bonding" in the AuthReq field of the Pairing Request or Pairing Response, no bonding information shall be permanently stored.
If you're using BlueZ, I'm not sure if it allows you to configure this though.
For Android, people report that Android does not respect this flag and creates a bond anyway (Why does Android bond even when asked not to bond?).
Technically speaking, pairing is the process of exchanging the keys with a remote device, while bonding is the process of storing these keys. Some devices use the terminology "pairing" to indicate the the keys are exchanged and the connection is encrypted, but the keys will not be stored for future use. On Android this is not possible as far as I'm aware, and you always need to store the keys. This can be seen in the link below (see the section Bonding with a BLE Device):-
The Ultimate Guide to Android BLE
Some other useful links:-
Android BluetoothDevice API
Should One Create a Bond with a BLE Device
BLE Pairing and Bonding
I use the technic described here to capture the Bluetooth paquets exchanged between my Android phone and a device (a very simple device).
I can capture a lot of scanning and the pairing between the two devices, but I can't see any of the later exchanges, only the scanning.
Moreover, just after the pairing there is a huge gap in the time, and other gaps later when I think data are exchanged between the device.
For exemple, the timeline is in this form:
0-8s: scanning (LE Set Scan)
8-15s: pairing
80-120s: scanning
180-200s:scanning
I'm sure that the gaps correspond with data exchanges, but I don't know why I can't see the paquets.
I've tried simple file exchange between the phone and a computer, and I've been able to see the paquets containing the file.
I assume you are using the BLE and you are sniff the air log. According to your description, you can scan the advertisement(and scan) and the pair procedure(I assume after the pair you can see nothing).
Did you entered the LTK(long term key)? it is just something like the link key in the classic Bluetooth, with out this you can not decrypt the encrypted packages. The best method to observer the log would be check the btsnoop.log.
You said you can see the paquets between PC and your mobile phone, should be you are using classic Bluetooth actually? or you did not pairing?
Background
I have an idea for an app on vacation that needs to communicate to other phones with the same app. While on vacation those phones might not all have internet as roaming can be very expensive. The data is not a lot: like 500 kB max would suffice (in json).
Every phone has a bit of info that all the other phones would like to know, but if it helps the info can be stored on 1 phone (master phone from now on) and shared later to the other phones when back home over internet.
Phones
Android, iPhone and Windows Phone
We can't assume they have NFC, IR or zigbee. Just the hardware almost every phone has like bluetooth, camera, microphone etc.
My ideas
QR codes that changes, based on new info: If the first phone is scanned the second phones QR code has data from the 1st phone and itself and the 3rd phone has data from the 1st, 2nd and 3rd (itself) until it reaches that master phone that holds all data.
Data transmission trough sound that we can't hear (or we can). Con is that I don't know if something like this exists for mobile platforms and writing it is like a 3 year master thesis project.
http://nearbytes.com
https://applidium.com
https://developer.chirp.io/
Bluetooth. Can we connect like 8 devices? Would it work consistent (connecting even my headphones can be a hassle, what about 8 phones who try to connect simultaneously)
All of these ideas have big cons. Maybe I'm overlooking a better way.
I will add a bounty to the question for the best solution
An answer that explains it with a little bit of code reference (link is ok) is always better than just: "use bluetooth man"
TL;DR
The easiest (and most supported) way of getting multiple devices to connect to each other is using WiFi. Since your goal is to achieve data transfer with no internet, the most appealing solution would be to use a Peer-to-Peer network structure.
The two major smartphone OS's (Android and iOS) have API's and documentation on creating and transferring data over a Peer-to-Peer network.
Android WiFi P2P
Apple Multipeer Connectivity
These two also have a means to encrypt the data being transferred.
Windows doesn't seem to have an API to allow multiple peers connected, but their Proximity Class will work for one device at a time.
I can give a few outlines over the different options in each major OS:
Android
Android's WiFi P2P (peer-to-peer) API was created for transferring data without internet or another network.
From their documentation:
The Wi-Fi peer-to-peer (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot (Android's Wi-Fi P2P framework complies with the Wi-Fi Directâ„¢ certification program). Wi-Fi P2P allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth.
Google even has Documentation and training on this API.
iOS
Apple's Multipeer Connectivity.
Very similar to Android's P2P API, they claim:
The Multipeer Connectivity framework provides support for discovering services provided by nearby iOS devices using infrastructure Wi-Fi networks, peer-to-peer Wi-Fi, and Bluetooth personal area networks and subsequently communicating with those services by sending message-based data, streaming data, and resources (such as files).
Here is a decent looking tutorial on using Multipeer Connectivity.
--EDIT--
Another iOS way of doing this, which is a bit of a mis-utilization(?) of the tool, is by using GameKit.
However, I think that to get it to work for your purposes might result in a bit of a hack, since the "players" have to be using Game Center.
Windows
The only way (apparently) to connect phones in Windows Phone, is by using Proximity, however, that only gives you the option of connecting no more than two phones together.
They state:
Proximity is a great way to create a shared app experience between two instances of your app running on two different devices.
Those are options in each of the major mobile device OS's.
App usage could be something like:
Decide which device was going to be the "master", so that other devices can connect to it. It isn't required to know this before deploying the app, but there should be a way for the user to decide whether he is going to be a client (receiving data) or the server (pushing data).
Once it was decided between the group of devices which was going to be pushing data, that device would have to be registered as the server (in the Android P2P API, you can establish a "group owner"), and then start looking for peers by initializing the service.
Then, once the devices are connected to the master device, you can start pushing data. An additional bonus is that when using Android WiFi P2P, all communication is encrypted with WPA2, and with iOS, you can enable encryption using MCEnableEncryption (however they state that is slows down data transfer rate).
Now you would just have to pick one method to go with, and make sure that all the phones ran that OS. Because these three methods of connectivity won't work together.
All of the three methods listed are done programmatically, so there should be no strange or odd things that your user will have to do. Searching for other devices, connecting, and transferring data can all be done within your app.
More help can be provided if the question is narrowed down to specific problems, but this should be enough data to get you started.
Don't try QR or sound. I think it would be very painful to transmit 500kb of data.
Bluetooth seems like a good solution but maybe, as you already said, hard to configure.
What do you think about wifi?
At least every Android and iPhone device can create a mobile wifi hotspot. By using this, you can easily setup a environment where 8 devices are in the same LAN (without using the internet by any of your devices).
Now your "master phone" runs a simple server to synchronize data (just like an internet server would do). Every of the seven clients could receive the ip adress of you master by scanning a simple QR code or sending a short message and afterwards configure itself accordingly.
Have you checked Alljoyn?
As quoted:
"Developers can write applications for interoperability regardless of transport layer, manufacturer, and without the need for Internet access"
You can create a Wifi connection between your devices. Than after connection it creates local network between your devices. Inside this network you, of course, can interact between your devices using TCP/IP connection. It works both on Android and iOS. Simply lauch your app as server on the one device
EDIT
Note, you have to connect your devices using any network. It is possible to connect the devices by initializing your device as WiFi-router. It can be both Android and iOS. If it is possible, you can connect your devices to any wifi connection.
Than, launch your app as Server-socket, the others as clients.
for Android (java) server use this link:
https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html
try (
ServerSocket serverSocket = new ServerSocket(portNumber);
Socket clientSocket = serverSocket.accept();
PrintWriter out =
new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
) {
for android device client:
try (
Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(kkSocket.getInputStream()));
)
The same idea is for iOS (Objective-C):
server
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html#//apple_ref/doc/uid/CH73-SW8
and client:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html#//apple_ref/doc/uid/CH73-SW4
A better way could be use Ble.
It's easiers to connect the phones because you don't need user confirmation.
Seems like you can connect up to 20 devices Maximum number of peripherals on CoreBluetooth?.
To transfer 500KB should require few minutes (may be between 2 and 5).
You can track an Android device without Internet via GPS.
Connection without The Internet:
SMS
USSD
DTMF (very slow)
How to design a tracking device on USSD is mentioned at
M2M IoT Cookbook
How to develop a device based on Wireless Wide Area Network modules
You also can use the Android phone as a data logger and store under the Micro SD Card and read the card by:
Replacing the SD card to your PC
Streaming the data local by Bluetooth
Forwarding the data at home by Wi-Fi
Or Possibly:
Your app can use SMS API to transmit the DATA or other SOURCES.
I'm asking because I've been facing that issue for weeks.
I need to develop an Android application that can be able to perform an Bluetooth Connection and send data to an Bluetooth Hardware.
Ok, so here's the point:
is it possible to perform a RFCOMM connection to an 'unknown' device?
I mean, is it possible to do this without having any information about the hardware code?
Because i'm only able to modify the AndroidDevice (cellphone) code, for SENDING purposes.
I want to send a byte and make sure it was received, but there's only a sending code.
Could we have some more details? Is the other device accessible by you, as in can the other device know information about the Android device? And what do you mean by a "sending code"?
The Android device can pick up any active Bluetooth device in its range, and know the name and address of those devices. So, if the Android device doesn't know anything about the Bluetooth device it wants to connect to, you can always sort through the list of devices in range, and get its hardware code through that.
See the documentation about Bluetooth, specifically the Finding Devices section:
http://developer.android.com/guide/topics/connectivity/bluetooth.html
I've done a fair amount of Bluetooth work with Android devices and Arduinos, and the Bluetooth library might be a bit of a pain to work with, but it is powerful.
With bluetooth the two devices have a UUID. If you a writing a program that runs on both devices you have them listen for that UUID. When they connect as a client or a server you have a dataInputStream and a dataOutputStream. Then you can push and pull bytes out of those.
I have a task to integrate a Bluetooth device into my application. Now my requirement is very specific. The device has a specific communication protocol which relies on certain ACKs but I figured it would make my development much easier if there was a program that let me test communication with the device.
I was wondering if there was a program for Linux, or perhaps a simple Android program which let me communicate with any Bluetooth device with a series of pings using data I enter and simply log the responses.
EDIT: I might not have been clear enough in my question.
I have a scale that I need to integrate into my application, and the scale has a protocol similar to this:
Get a specific byte string from device
Transfer data
Transfer packet for disconnection
Receive acknowledgement for disconnect packet
Disconnect
Now when I have to issue a POST request from my application, I usually build a test script online so I can test if the POST works properly.
I was wondering if there was something similar I could do with the device.
Thanks
Your question is not clear enough. To communicate with a BT device, you need to know what profile your device supports. Depending on that, you can find a way in Android or Linux or windows to communicate with the device.
The simplest way is to open an RFCOMM channel from android/PC and transfer data to and from the device. For this the device has to support the serial port profile (SPP). If you want to do this in Android, look for the BluetoothChat example from google.
If you want to use a PC/mac/linux look at the Bluez python module. It's really simple to use. There are plenty of other options too..
I was looking for something like SENA BTerm. It lets me connect to any device and send whatever data I wish.
It is an extremely useful tool for testing my code.
http://www.sena.com/download/manual_bterm/overview.html is where you can find it.