I want to scan some device with BLE.
I only want to show my device, so for know I get the name of the device and if it is the good one I put it in my list.
if (device.getName().contains(DEVICE_NAME)) {
mDevices.put(device.hashCode(), device);
invalidateOptionsMenu();
}
My problem is that if I change the name of my device this check will be false.
So I look if it was possible to get some uuid of some services that I add to do the check with something that would not change.
And the only way is to connect to the device doing a
device.connectGatt(this, false, mGattCallback); and after with the gatt I discover service but, is it possible to discover some services from a device without connectiong to it ?
I am not with the android background, but I have understanding of how BLE works.
Take a look at all standard GATT characteristics here and all the standard GATT services here.
The characteristic Device Name (UUID is 0x2A00) is bundled into Generic Access service (UUID is 0x1800).
The GAP is always broadcasted within the advertisement packet from the GATT Server.
A GATT Client should run a discovery scan to receive the advertisement and parse the advertisement packet to receive the GAP descriptor. While you are doing this, technically speaking the connection is yet to be made.
Addressing to:
If I change the name of my device this check will be false, So I look if it was possible to get some uuid of some services that I add to do the check with something that would not change.
Assuming that you want your app to connect only to a particular set of device that has some unique identification. Say for example, a BLE-enabled digital pen configured by you should only connect to your app and no other device gadget should be able to connect with your app. If that is the use case and if you have the liberty to configure the GATT server on the BLE device then you can add some custom characteristics in GAP service on GATT server which will be unique to those devices. Needless to say, you will have to generate a 128-bit custom UUID for that characteristics and the UUID will be known to your application as well. This is more like a work-around solution.
Take a look at scan filter in android.
It allows you to scan by service UUID, which needs to be sent through advertisement by BLE peripheral. I haven't worked on android, but I am certain that the ScanFilter would allow you to to filter by either a 16-bit or a 128-but UUID.
Kindly refer Bluetooth Development Portal for more details.
Related
I want to make two Android apps using BLE & GATT Protocol. Implementation like that role of the first app is GATT Client and the role of the second app is GATT Server ( or how to make the mobile phone a GATT Peripheral?) using Kotlin/Java. Both the apps will execute on a same mobile device and when I send an advertisement from one app the second app will receive this broadcast.
Is there any tutorial or article link other than the android official document where it is clearly explained? Or how should i implement this?
You can implement GATT client and GATT server concurrently. In most cases you don't need to know that the same app or another app runs the other role as well, so just develop like you usually would have done if you only implemented one role. Just keep in mind that a GATT client cannot communicate with a GATT server on the same device; it must be another physical device.
I want to connect and stream the multiple Bluetooth low energy sensors by matching their gatt profiles. All the sensors devices are of the same type but different mac address. So I want to connect those sensors to my mobile application and stream those data to our other application through the serial port. I know the Bluetooth can connect to 7 devices at a time.
But for connectivity with Android devices, it is not stated properly and still in a dilemma. Or else is it possible to connect external Bluetooth module to the android box to connect it to multiple devices? If yes then to do this what are the changes I need to perform on my system? How many devices can be used to communicate with the Android device at the same time? Can the android box act as a master that collects all the data from the peripherals and stream via the serial port. We have completed our process for a single sensor. Or is there any other possibility to stream multiple ble sensor data to another device through serial port write. please guide me through this process.
Execute connectGatt one time for every device, which will then give you one BluetoothGatt object per device. The callback object can be the same, or a separate instance per device, it depends on the use-case but most probably the devices serve different purposes so you'll have separate specific instances per device.
As long as you have a BluetoothDevice object, you can make a GATT connection to it. You can get it either using Bluetooth device address (which can sometimes be problematic since the API misses the random / public address type bit) or by a scan. You can have one outstanding GATT operation at a time, per BluetoothGatt object, so yes you can read / write characteristics to both devices simultaneously.
Feel free to post some source code for more analysis.
I read about P2P connections with wifi on the official android tutorial. It allows me to connect devices who are in close proximity. The problem is that
I want to be able to decide which device becomes the group owner
I don't want to use the device name as an ID for each peer in the network. I would like the group owner to setup a channel name which can be recognized by others. Each peer can connect to the channel name and choose a name (not their device name).
Maybe the standard direct wifi implementation as put forth in the tutorial isn't the exact tool I'm looking for. Maybe a third party library could help?
Basically the API has the functionality to do just this (though the implementation is not the most robust one, so do expect issues when developing & using the API):
Use the CreateGroup to create the group
Start local service advertisement with the group owner (set the Service type and/or the instance name to identify the 'channel name')
Start and Do remember to keep peers discovery active with your GO (otherwise other devices can not discover it)
Start Peer discovery with other devices, and once you find peers, then start Service discovery and discover the 'channel name' services yor GO is advertising
We developed a Hotel Menu Order project in android. Now We have created the project successfully. We are using java, Jax-rs for web service, Mysql for database and Rest for communication.
Now we want to add some more features in our app. When the customer conforms their order that order should show to kitchen and admin. When we google for some example we found one way. That is Google Cloud Messaging. But this is online sevice. We can not use this service.
Because we are using in offline services. We use one centralized server in the hotel and all the devices will connect with WiFi. There is no internet connection.
In this case how to notify the user a row is updated in Database. Please let us know how to achieve this.
Via SMS, what you can do is that you can send the sms to the devices using thrid party services like twilio, on client side i.e. device end you can get the sms broadcast validate the number and the sms content, read the content and update the application DB and the UI accordingly.
Or if one device has internet then what you can do is send GCM notification to that device, and from that device you can update the other devices through wifi direct. But wifi direct has some limitation, I think using SMS is a better option.
u can use Google Cloud Messenger services, by which google provide free message service to your client. http://hmkcode.com/android-google-cloud-messaging-tutorial/ this example will help u to understand better.
I am developing USB to serial app, where mobile will attached with USB hub, and this hub is connected with with other devices through CP2102 cable. I am able to identify all devices and can read and write also. But the problem is all have same Vendor and product ID and other information also. And USB port number is also changing if we disconnect and connect.
So is there any way to identify the attached devices. Let me know if any other information required here.
I am using this example for development.
http://code.google.com/p/usb-serial-for-android/
Take a look at AN721, there is a tool that goes with this document that Silicon Labs provides to so you can customize your device's VID and PID, serial number and device strings. Serial number might be the easiest way to make your development devices unique, if you change the VID/PID then you'll need to create a custom driver with those new settings to get your device back.