How to send string messages via bluetooth in flutter? - ios

I want to send messages between two phones via bluetooth
I am using flutter_blue_plus package and i am not understanding on how to send string messages and receive them, what characteristic to use or descriptor or service.
If its possible i want to listen to the messages received by the other device connected via bluetooth.
I also wanted to know if nearby connections api can be use to connect phones to bluetooth low energy devices?
i want to try both since bluetooth low energy is the priority, i am skeptical about nearby connection api.
D/uuid (17373): 00001101-0000-1000-8000-00805f9b34fb
I/flutter (17373): STATE_CONNECTED
W/BluetoothAdapter(17373): getBluetoothService() called with no
BluetoothManagerCallback
D/STATUS_CONNECT(17373): java.io.IOException: read failed, socket
might closed or timeout, read ret: -1
I/flutter (17373): FC:02:96:56:FE:55
I/flutter (17373): STATE_DISCONNECTED
Why am i getting disconnected as soon as i connect? is that because of my phone? I am trying to connect to my other phone
also is i think thats the reason its throwing read failed exception

Related

IOS BLE - Why can`t I recieve all the data from peripheral?

I`m building an app that receives data from custom BLE device continuously and sometimes the app misses some data? the connection persists(no disconnection occurs) but some data is being missed.
How can that be? does the BLE protocol guarantee that the master will receive all the data?
How can I improve that and make sure that all data will be received?

Can iBeacon communicate with a remote server for publishing messages

I'm trying to develop a solution, where iBeacon has to be used as an alerting mechanism. This iBeacon has to receive alerts or messages from a remote server and then publish the same to its nearables.
Is this a possible usecase where iBeacon has to receive request from a remote server? As a disclaimer, I new to this technology and let me know if my understanding is wrong.
I believe you are approaching this problem from the wrong angle. Essentially you would like to receive a message when you encounter certain iBeacon signals. iBeacons are "dumb" devices, meaning they can only broadcast a data packet, they cannot receive any information and cannot broadcast anything different than the iBeacon protocol packet.
That being said, if you had a remote server that stored these messages, you ask the server what the most recent message is associated with the beacon you have just encountered. That way you can change the messages dynamically on the server based on what you need your user to know.
So essentially, because each beacon can be uniquely identified based on UUID, major, minor, you can store your messages based on this so that you can ensure the user is receiving the correct message when they encounter the beacon by sending these identifiers up to your server in order to retrieve the message.

OBD-II iOS WiFi Connection

I am trying to write an iOS application that connects to an OBD-II Interface over WiFi (specifically the OBDLink MX WiFi Scan Tool). I have written some basic socket code taken and I am able to open a socket to 192.168.0.10:35000. I receive the NSStreamEventOpenCompleted for both input and output streams.
The first event that fires shortly after is the NSStreamEventHasBytesAvailable. I attempt to read the stream, but the length comes back 0. My question is what is the flow of execution for communicating with these devices? I have tried to issue an ATZ\r command, but nothing is happening (no stream events are firing).
How do I know if if I am connected and the OBD-II interface is ready?
The usual command terminator is ˋ\r\nˋ, so first try sending ˋATZˋ with this command. Only send, after you have received the HasSpace notification from the ˋNSOutputStreamˋ.
Another alternative to communicate with this device would be this Car Diagnostics API, access to the API can be found on
https://github.com/HellaVentures/Car-Diagnostic-API

Ios Peripheral Device in BACKGROUND

We need in our project to detect the proximity of an iPhone that is running a custom APP that is using Bluetooth LE.
The detector (Scanner, Central...) will be implemented using a BLE Integrated Circuit (from Texas or Nordic). I mean that the scanner is not another IOS device... running Core Bluetooth as a Central..
For the detector to guess the proximity, the idea is very simple, just advertise a service with an UUID proprietary.
While in foreground all works OK, and the UUID and a Local name are advertised (The UUID in the main advertise packet, and the Local Name in the SCAN Response packet....), and our scanner is able to decide if this iOS device is running our App.
The problem arises when going to background .....
The iOS stops broadcasting UUID and Local Name. (As the documentation of Core Bluetooth Explains... I Know...)
At this moment (Background), IOS begin to broadcast a SPECIAL MANUFACTURER DATA in the main advertise packet, and nothing in the SCAN Response packet)
The data packet we see using a Bluetooth Sniffer is :
0x14 (length of packet not including this byte).
0xFF (Manufacturer specific data AD Type).
And then :
0x4C, 0x00 (this data is the manufacturer identifier, if the packet is compliant with BLE 4.0 specification).
0x01, 0x00,0x00, 0x00, 0x00,0x00,0x80, and ten 0x00 more....
I know Apple says that while in background ONLY ANOTHER IOS DEVICE SEARCHING FOR A SPECIFIC SERVICE CAN DISCOVER IT. (Really I do not know how they can achieve that, unless they connect to the peripheral and retrieve the services, or if the peripheral knows about other IOS device is scanning because of it´s Address in the SCAN REQUEST and then changes the advertisement data in background).
The main questions are :
Is there any documentation or knowledge of what this manufacturer data means....Perhaps it would be possible to the scanner to know based on this info that this is an iOS device advertising in background and then connect to look if the custom service is there. (Not a quick and clean solution...but I do not see any other workaround....)
Does anybody worked with this scenario...and found a clean solution .....
I have heard from people that forces the application not to go to background.
This limitation, will stop a lot of possible projects.

CoreBluetooth[WARNING] Unknown error: 14 on iPhone 5

I am able to connect to a peripheral device using BLE, but shortly after reading some characteristics, the framework returns:
CoreBluetooth[WARNING] Unknown error: 14
and the peripheral is disconnected.
Looking at the BT Core_V4.0 spec, I am not sure what the error means. Is the 14 a hex value? does it mean the following error according to the spec: (Part D Section 2 - Error Codes)
2.20 REMOTE DEVICE TERMINATED CONNECTION DUE TO LOW RESOURCES (0X14)
The Remote Device Terminated Connection due to Low Resources error code indicates that the remote device terminated the connection because of low resources.
I tried changing the battery but did not have a different effect.
Also, I don't know how to catch these CB errors, I only see them logged, but when the device disconnects, it does not provide an error (it is null).
I do not directly control the source code for the peripheral but can ask for a bug fix. So any hints are appreciated it.
Thanks,
You cannot intercept these CB errors, they are just traces from lower layer BLE.
Error 13 for instance is when the length of written data is not as specified in the GATT database.
Error 14 means the connection was closed by other side (peripheral). I have seen this several times. Some times I read data too fast (You are not allowed to request next access before previous has been answered, there is only 1 "resource" in BLE per connection. Maybe this is what you also see?
As always it is best to get the TI BTLE USB Dongle with sniffer sw installed and then use the TI RF Sniffer tool in BLE mode with that dongle. You get a lot of information you can debug from in those traces. Like see if there are more than one read or write request without response.

Resources