Bluetooth SPP: Bluetooth SPP Pro (Android) vs. Microchip SmartData (iOS) - android

All,
I am attempting to communicate, over an SPP profile, with an RN4678 Bluetooth chip connected to a microcontroller.
I never have a problem with the Android app. I can always pair (if not paired), connect, send messages to the chip, and disconnect. An example session is below:
%CONNECT,AB9876543210%
%RFCOMM_OPEN%
%TEST% <-- Message sent using the keyboard ("Byte Stream Mode" option)
%RFCOMM_CLOSE%
%DISCONN%
With the iOS app, I can always pair (if not paired), connect, and disconnect. However, if I cannot send a message to the chip. An example session is below:
%LCONNECT,499B107AB1B5,1%
%LSECURED%
<-- Here I try to send a message, but it is never received
%DISCONN%
The funny thing is that if I first connect/disconnect using the Android, and then I connect using the iPhone/iPad, reception is successful !!!!
%LCONNECT,499B107AB1B5,1%
%LSECURED%
%TEST% <-- Yeah !!! Microcontroller receives the message
%DISCONN%
As far as I know, that path for the processing is the same ... In other words:
if(msg equals "RFCOMM_OPEN" or msg equals "LSECURED")
go to state that monitors incoming messages
I, therefore, kindly ask the following:
1 - Have you encountered anything similar? Do you have any hints? What could the Android App possibly do that the iPhone app is not doing? What am I overlooking or not understanding?
2 - Are you aware of an app that works for both iOS and Android? What I mean, designed by the SAME guy/company?
If you need more info, please ask. I simply did not want to be too 'verbose'.
Thank you for your assistance.
Sincerely,
Vincenzo

All,
At my job we have been playing with two RN modules: the RN4677 (we started with this module) and the RN4678.
The module allows the user to enter (and exit) a command mode. The RN4677 allows bidirectional communication with a manager while still in command mode. The RN4678 does NOT allow bidirectional communication with a manager while still in command mode.
All I needed to do was exit command mode (by issuing the command '---\r'). Now both modules work with Windows/Android/iOS ...
To summarize:
command "$$$\r" to enter command mode
various commands, requests for settings, ...
command "---\r" to exit command mode (a must for RN4678)
Everything will now work fine for both modules
I must say ... that was painful to troubleshoot ...
Sincerely,
Vincenzo

Related

Is it possible to android to lost part of a command writen to a characteristic via BlueTooth via BLE?

I'm developing an adaptation for an android app, to communicate with a remote control, which has some pre defined commands.
I've followed this implementation to do the Bluetooth communication and it's working fine for sometime.
This app should communicate with the remote control every 5 minutes or less, and I've been using the app for almost 6 months now. The last week I've some command clashes problem and looking at the logs I couldn't identify why did that happened. The last time that this had happened the app was running for more than 24h, communicating with the remote control, without any communication issue.
Two of it's commands have some similar characters, the first one that have to be done, to establish the connection.
OK_CONN
And an sniffer command which keeps the pilot awake listening for some sensor data:
N
Looking at the logs I can see the answer for command N, after applying the command OK_CONN.
Is it possible for a Bluetooth command to lost part of it's data, during an established communication or am I doing something wrong when writing to a characteristic? Should I change the command names to avoid this kind of clash?
I'm using android 9, at a Sony XPeria XZ phone.
Edit to clarify #Emil comment
07:02:12.880 [BleThread] writing <OK+CONN> to characteristic
07:02:12.368 [Binder:19249_F] [onCharacteristicChanged():274]:
n command confirme
Looking at the logs I see that the last written command as an ok_conn but it has written only the N, this is been show as the last line, it has confirmed to receive the n command alone, instead of receiving the full data of ok_conn.
By name clashes I mean that maybe the last N of the ok_conn command is been accepted as the command.
I just realized what's going on, you can post that as an answer #Emil, my problem was at the logic that sends the first command, sometimes I send this command and the micro controller is not started yet, that's probably the reason of it getting only part of the command.
Not sure what you mean by name clashes, but Android will always write what you told it to write, without packet loss, as long as you follow the rules to never have more than one outstanding operation (always wait for callback before you send the next operation) and that your data must fit within the maximum length for the corresponding operation.

Bluetooth SPP profile on SIM800H

I'm having issues when trying to use bluetooth on my project. On previous version I used the HC-05 module for bluetooth and it gives me a simple serial connection right after any device connects. Now the project evolved and we opted on using SIM800H because it gives us GSM+Bluetooth.
When I connect any android device it gives me some profiles but never SPP. I can pair normally but when using any SPP server app (https://stackoverflow.com/a/4037619/2637661) I can never send or get data from my device. If I start the connection from the Android app, it says that it's connecting while the SIM800 gives me the URC and I respond:
+BTCONNECTING: "34:c7:31:aa:37:5b","SPP"
AT+BTACPT=1
OK
+BTCONNECT: 1,"Android",34:c7:31:aa:37:5b,"SPP"
But it stays on server mode and I can't use the commands AT+BTSPPSEND or AT+BTSPPGET, as the documentation says.
On the other hand, if I start the connection from my device just like the docs say:
AT+BTCONNECT=1,4 // Device is 1 and SPP profile is 4
OK
AT+BTSPPSEND
>I type anything here + ctrl+z
SEND FAIL
and get nothing on the Android side.
Plus in both cases the connection drops after something like 30s and I can't reestablish it unless I turn the SIM800H off and on again.
Got no success using the APP mode either (sending the string "SIMCOMSPPFORAPP" right after connection succeeds for transparent communication).
The SIM800H firmware version is
AT+CGMR
Revision:1309B07SIM800H32_BT
and I tried using the following apps
Bluetooth Terminal
Bluetooth spp pro
BlueSPP
The GSM side works flawlessly and I can send/receive TCP messages everytime I try.
Does anyone have any kind of experience using this module? Thanks for reading!
UPDATE:
I'm using a simple sketch in order to talk with the module's serial, don't know if it's relevant but here it goes.
#define SIM800_POWER 23
void setup() {
Serial.begin(9600);
Serial1.begin(19200);
Serial.print("Setting all up");
pinMode(SIM800_POWER, OUTPUT);
Serial.print(".");
delay(500);
digitalWrite(SIM800_POWER, HIGH);
Serial.print(".");
Serial.println("OK");
}
void loop() {
if(Serial1.available()){
Serial.write(Serial1.read());
}
if(Serial.available()){
Serial1.write(Serial.read());
}
}
And what I get after trying Andrii's answer:
Setting all up..OK
AT
OK
AT
OK
AT
OK
AT+BTPOWER=0
OK
AT+BTPOWER=1
OK
AT+BTCONNECT=1,4
OK
+BTCONNECT: 1,"Will",d4:87:d8:77:37:0b,"SPP"
AT+BTSTATUS?
+BTSTATUS: 5
P: 1,"Will",d4:87:d8:77:37:0b
C: 1,"Will",d4:87:d8:77:37:0b,"SPP"
OK
AT+BTSPPSEND
> SIMCOMSPPFORAPP
SEND FAIL
Seems AT+BTSPPSEND without any parameters is only for AT-command send from client (your SIM800H) to server (other SIM800, not your Android device unless your Android device implements AT-command support). For data sending you should use AT+BTSPPSEND and after receiving > symbol send SIMCOMSPPFORAPP keyword and then, after receiving SEND OK response send command AT+BTSPPSEND=<LENGTH_OF_YOUR_DATA> and then, after receiving > symbol, send your data until Ctrl+Z code e.g.:
AT+BTSPPSEND
> SIMCOMSPPFORAPP
SEND OK
AT+BTSPPSEND=5
> HELLO
SEND OK
^Z
where HELLO - is your data, and 5 in AT+BTSPPSEND=5 is length of HELLO string. Details in SIM800H_BT_Application_Note.
UPDATE
Selected by bold small, but important part of answer (thanks to hlovdal)

Qt and Android characteristicChanged is not emitted

I have a problem with testing my application on Android platform. I have functional application on x86 architecture. This application can connect to Bluetooth LowEnergy device and communicate with it. BT device is HM-10 module - serial line.
But when I try the same application, but just compiled for Android, I'm not able to receive any data back. On the other hand I can see on remote device that all data from mobile terminal are sent.
What I suspect as a possible problem is that signal QLowEnergyService::characteristicChanged is not emitted. In the documentation http://doc.qt.io/qt-5/qlowenergyservice.html is written that you should register for changes, but at least on PC it is done automatically somehow.
Would anyone please help me ?
You have to do some magic
QLowEnergyDescriptor notification = _characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (!notification.isValid()) {
qDebug() >> "QLowEnergyDescriptor not valid";
}
connect(_service, &QLowEnergyService::characteristicChanged, this,
&Device::onCharacteristicChanged);
_service->writeDescriptor(notification, QByteArray::fromHex("0100"));

How do I using android, programmatically send a vibrate command to a connected bluetooth device?

I'm trying to achieve this goal: I have a bluetooth device connected to my android phone. Given this device can vibrate, is it possible to send a vibrate command to the device?
I have researched the bluetooth apis and the vibrate api on android developers' site but nothing clearly answers my question.
In bluetooth HFP (Handsfree) spec, there is no command (AT Command) to send vibrate to the peer device. As per the technical specification of bracelet "Vibration prompt for incoming phone" , once an AT command is send from phone to bracelet indicating a incoming call, bracelet generates vibration locally, phone does not ask/request to vibrate.
If you want peer device to vibrate,may be you have to use your own defined commands (AT command), with command recognized by the peer device.
I'm very glad to update this thread that I was able to programmatically vibrate the BT bracelet and in the right way using AT commands. So my application is based on Bluetooth Chat application in the Android samples. Here are the steps I followed:
connect the device to the phone
device follows BT Hands-Free profile specification. That requires "handshaking" by means of AT commands.
So I mimic this exchange of commands (with hard coded responses to bracelet's commands)
Once handshake is complete, I send AT command based on BT Hands-Free profile specification to RING and +CLIP:
On receiving the last set of response from application, the bracelet vibrates.
It seems simple, but without knowledge of BT Hands-Free profile specification, and sample AT commands this was nearly impossible.
#bt_user: Thanks for your pointer, that put me on the right track of R&D.
I was fiddeling with exaclty the same problem. After days of trial and error, I finally got it to work. I think it depends on the speed at wich you answer the HF's commands, as well as on the correct line-endings ([13][10]"COMMAND"[13][10]).
Here is my DroidScript which works. It's not cleaned up, but it works.
https://gist.github.com/t-oster/68a568ac4c4e133f67ac
The exact sequence, which works for my bracelet is:
CR is ASCII Code 13 and LF is ASCII Code 10
> AT+BRSF=0<cr>
< <cr><lf>+BRSF:0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND=?<cr>
< <cr><lf>+CIND: ("service",(0,1)),("call",(0,1))<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND?<cr>
< <cr><lf>+CIND: 1,0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CMER=3,0,0,1<cr>
> <cr><lf>OK<cr><lf>
from then on I can just send
<cr><lf>RING<cr><lf>
to make it vibrate.
i have developed a java android version
using parts from Thomas Oster and an example i found online
https://gist.github.com/shimondoodkin/a582d910045ab06ab68c

Writing a GSM emulator for use with Android

For some work I'm doing, I want to have an emulated GSM modem which will communicate with an Android-x86 virtual machine over a Unix socket. The VM should see the emulator as a real modem and use it to send SMS (as the first pass of functionality).
So far, I've put something together which handles some AT commands and just replies "OK" to all the rest. For some commands, like "AT+CRSM", I just have a table of responses gathered from running the official Android emulator and looking at the radio log. For others, I maintain some state and construct answers; those commands include:
CFUN?
CPIN?
CGREG?
CGREG?
COPS?
CGREG=
CREG=
CPIN=
COPS=
CRSM=
CSMS=
CGSN
CIMI
CSQ
Android will boot, and send commands to my emulated modem, which answers, however it doesn't seem to be fully functional. Android doesn't detect any radio signal strength, for instance, just showing an "x" in the signal bar.
Does anyone know of a similar project, or just what AT commands are absolutely necessary to get some basic functionality?
Well, I'll answer another of my own questions, it's easier that way.
I ended up implementing an emulator which maintains a little bit of state, such as whether or not unsolicited CREG and CGREG messages are enabled, the network registration status & network name format (for the COPS command), and a message reference counter for SMS.
It supports the following commands:
CFUN?
CPIN?
CGREG?
CREG?
COPS?
CGREG=
CREG=
CPIN=
COPS=
CRSM=
CSMS=
CMGS=
CGSN
CIMI
CSQ
All other messages just get an "OK" response.
With the stock AOSP Android source running in an emulator with the "-radio unix:/tmp/phone" switch, I can send SMS messages and decode the binary PDUs into real messages. I will continue to add functionality so SMS messages can be injected back to Android, and hopefully open-source the code at some point.

Categories

Resources