SEQUENTIAL bidirectional P2P with NFC on Gingerbread - android

I have the following scenario
Phone A prepares an NDEF message and Phone B registers foreground
dispatch.
Phone A pushes the NDEF. Phone B receives this and processes it.
Phone A now registers for foreground dispatch and disables NDEF
push.Phone B replies with an NDEF push.
ALL this is to be done in one swipe. How can I do this?
Right now, I have to pull the devices away for the 2nd part to work. I
have seen the sample on p2p exchange, but in that case, both the
message contents are known in advance. Here, the reply depends on the
request.
Secondly, will there be a proper NFC API with the ability to create
LLCP sockets?
Cheers,
Earlence

Related

Many empty PDUs in ESP32 Upgrade over BLE

I am doing a firmware upgrade of a BLE peripheral device based on ESP32 from an Android central.
The firmware file is sent in parts of 512 bytes each. The ESP32 device (the GATT server) sends a notification to the central (GATT client) and the central sends the next part, followed by a write command to the peripheral. Then the next notification is sent and so on.
The upgrade works, however, it takes a long time to complete (~10-12 min for a 600kB file).
I sniffed the traffic with Wireshark and it turned out there are 15-20 empty PDUs between the sending of each notification by the peripheral and the start of sending the part by the central. I searched what may be the problem on the server side but could not find anything relevant.
Maybe something is happening on the Android central that delays the sending process? Or maybe I am missing something with the ESP32? Here is a Wireshark capture (I’ve underlined in red where the sending should start):
EDIT: I haven't added extra sleep on server and if I had, there would be no empty server PDUs, correct?
I tried what you suggested, to use just android's internal mechanism for confirmation and the download is now about 3x faster. Thank you! However, in the captures there are some strange (to me) things like a lot of 26-byte response packets from the server to the master (captures below). Why is that and is it possible to combine them into 3 packets, the way they were sent from the master?
Also, about he explanation in the link you gave:
The Bluetooth controller sends a "number of packets complete" event back to Android's Bluetooth stack over HCI which indicates that the Link Layer of the remote's device has acknowledged a packet.
I didn't quite get that. If its a Write_No_Response from the master, how does the remote device acknowledge receiving a packet?
And is this Android flow control mechanism a possible explanation of my original problem with the empty packets?
Seems like the Android device is not fast enough, or you have added an extra sleep.
Assuming the peripheral can handle the data, you can quite reliably send write commands without using a notification acknowledging scheme. See onCharacteristicWrite and onNotificationSent are being called too fast - how to acquire real outgoing data rates?. Basically just wait for onCharacteristicWrite before sending the next one.

Android WiFi (sending and receiving data without specifying recipient)

I want to make an application is via WiFi would send and receive data without sending them to a specific recipient. I explained to the example of a simple chat: The user sends a message via WiFi, but without a specific destination. As a result, his report available to all users nearby. Similarly other users can receive and send messages. I also want to realize the function of repeater, where each user's device not only receives a message from the other devices, and retransmits them to others allowing increase the coverage area of WiFi connection.
But at the moment it is not possible to send data without a specific recipient. The same WiFi Direct necessarily require pairing before data transfer. Can not specify that the recipient is unknown.
Recently I heard the news about the technology WiFi Aware, which involves greater interaction between WiFI devices. Please reply, WiFi Aware allows to do what I described above? Namely - the transfer of data and we will without a clear indication of the recipient and the need to do additional work (eg preliminary pairing between devices).
If WiFi Aware allows to do what I described - when it is expected to release its API? In particular, for Android devices. And if not - you can tell me how to implement what I need? And in general - it is technically possible?
Thank you for your time and sorry for my bad English.
You should try to look into nsd via wifi-direct. This Network Service discovery via Wifi-Direct. What this helps you to achieve is broadcast information to all listening devices.
On the device which wants to convey the information you addLocalService and on the other devices you should discoverServices. In the ServiceInfo object you can the pass the information you want to communicate to the other devices who are listening for services. Please try to study from the link attached above.
I am not very sure about how repeater will work with this.

Send a Android BLE GATT Notification

I´m currently developing an BLE application, based on the Gatt sample project provided by Google.
What I want to realize is to send a notification from my Android device(smartphone) to another BLE device(e.g. TI CC2540). There are many discussion about how to receive a notification on the Internet.
However, I can't find out any discussions about sending a notification. So is there any method to sending a notification through Android device? Thank you in advance.
Technically, there is a difference between the Central/Peripheral classification, which belongs to the GAP, and the Client/Server one, which belongs to the GATT. A Central (one that scans and connects) is usually a Client, and the Peripheral (one that advertises) is usually a Server, but not necessarily.
The smartphone is the Central (it can be Peripheral as of Android 5.0 but I doubt that's the case for you), and usually it's the Client because it connects to GATT Servers located on Peripherals such as your sensor (or whatever you are building).
So, if you want to send a Notification from your device you need 2 things:
Create a GATT Server on your smartphone.
Design your Peripheral to execute GATT Client procedures (Discover Characteristics, Read/Write etc).
This may not be necessary, as #istirbu pointed out. If your application is already up-and-running, your smartphone Central is a Client. The equivalent of a Notification at Client-side is the Write Command (without response). So use that.
Notifications are used by the peripheral device to send back information to the client (eg Android device). There is no need to send a notification to the device from GATT perspective, you can perform a write operation on a characteristic. As a result of that write, or any periodic operation, the peripheral device will send back (notify) some info to the client on the same or other characteristic that you have subscribed for.

Android Beam - payload transfer from both devices when only one Touch To Beam?

Ok, I watched the Google I/O from 2011 presentation on NFC on peer to peer.
The demo was done on Gingerbread and using the application Sticky Notes found
Now in this demo, both device the onNewIntent() was called at the same time so both devices are trying to share information to one another.
On ICS and above, you have Android Beam..
With Android Beam, you have to touch to trigger the onNewIntent() event that will send the NDef message across.
Now the problem with this is that now to trigger the onNewIntent() on both devices, both user on each device has to "Touch To Beam" at the same time.
Is there a way that when you Touch To Beam on one device, both can have the onNewIntent() to be called?
I am trying to develop an app that will exchange data to each other but for it to work in a nice friendly fashion I need the devices to share the data at the same time once the Touch To Beam has been initiated on one device. I do hope this is possible.
Edit: It looks like this might not be possible to do :(
As far as I can tell, the feature you want is not available over NFC itself. The touch-to-beam/SNEP/NPP transfer is one direction only on Android. The user that clicks his screen will push an NDEF message to the other phone.
What I believe they've done in the video is set up a bluetooth connection with the NDEF message to make the transfer (as you saw in the stickynotes demo). Unfortunately there is no nice API for this.
However, the EasyNFC project promises to be able to allow you to create a bluetooth connection and socket between two phones/applications. Check it out here
I had a try and didn't really like the Touch-to-Beam UI that was still required in the set up of the bluetooth connection. It also didnt really suit my needs, as I wanted to transfer phone to computer and didn't really want to implement NFC P2P and a bluetooth connection.
Did you try this:
Use the Touch to Beam on phone-1 to "PUSH" the data, while on the other (phone-2), use the NDEF_DISCOVERED/TECH_DISCOVERED intent to trigger/start the data capture/reception. I vaguely remember one of the above intents were triggered when a PUSH is done. Although, every transmission requires a "Touch" to start the beaming.
When you think in general, Android should not allow the NFC data transfer in both direction at the same time. Lets think of a scenario where I want to send a thing to my friend with NFC. What is actively open on my friend's phone is not important. I should send this thing even the same app is not open on the receiver side. There may be another app in my friends phone that tries to send another thing to me. When we touch our phones, Android Beam (TM) appears and he data is sent from the phone that is touched.
In you case I think you should disable Android Beam (TM) by setting setNdefPushMessage(null) and do sending both ways using the old way.
https://developer.android.com/preview/api-overview.html
I think it will be available in L!!!
NFC enhancements
Your app can invoke the Android Beam on the user’s device to share data by calling android.nfc.NfcAdapter.invokeBeam(). This avoids the need for the user to manually tap the device against another NFC-capable device to complete the data transfer.

Android NFC still weak of API on 4.0.3

I found many weak points of Android NFC:
ndef.connect()
cannot work for NFC phone itself, only for tag. It's no way to check the connection status when other phone close to the back.
NDEF cannot interactively send/receive in two way. On the device, tap the screen to raise a message send, and then disconnected, no way to get back data immediately.
NFC api does NOT support card mode. This is so weakness point. There's so many situations need the Phone act as RFID card. Among of them, sometimes no need security element. Once the UID available, server-end can do authentication and rest of things.
I am asking for how to check the connection status after NDEF message has been sent or received complete ?
You can register your app's activity to receive a callback when NDEF push via Android Beam is completed using NfcAdapter.setOnNdefPushCompleteCallback().

Categories

Resources