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)
Related
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
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"));
I just used an arduino code to send text data to an android application which I made in app inventor. I used Bluetooth module HC-05 for connectivity.It almost works but instead of sending few characters, it sends junk data. Here's the arduino code:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("h");
delay(500);
Serial.println("s");
delay(500);
Serial.println("o");
delay(500);
}
And here's the App blocks and Design:
And here's the screenshot when I ran the app:
I click "Show" and I get these random junk data. And the next time I click show, I don't get any data at all. Can anybody explain how to solve this ?
For Junk values, Try to change the baud rate!
I think you are sending a data from BT device to android device only one time. try running the code continuously in arduino device.
while(1){
loop();
}
Check if you connected BT module to USART0 (RX0, TX0) port
try change baud rate, usually HC05 has 9600, but it may have also 19200 and sometimes 115200.
note, that HC05 has 3.3V, and almost all Arduino boards are 5V. So you need to use level shifters. Else specify what board and module you use
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
I am willing to create a server and client program on my android mobile devices.
The devices communicate with each other on the same wifi network, therefore, some simple scanning mechanism must be implemented - The client phones search for a server phone through some kind of broadcast.
What I did:
My protocol - the client phone broadcasts a message port p on the wifi, the server listens on port p. when the server gets the broadcast message it sends a message back, therefore discovering itself to the client.
My code -
I have opened a broadcast socket on my app, it sends a broadcast message.
Meanwhile there is a python script on my PC that listens and replies - I use python so that my testing will be easier - Wireshark on the PC and I can see everything.
What happens:
When I use one of my Galaxy S phones - it works and I get a response.
When I use the other Galaxy S phone - it doesn't work.
Now this is what I know:
The phone that works actually has Nexus ROM on it Ver. 4.1.1
The phone that doesn't work has 2.3.3 regular galaxy ROM
The python code says it receives both of the broadcasts sent from both phones, and replies to both of them without raising any exception.
So far I was thought the problem may be
1. the older version'd phone.
2. the windows firewall
3. the router firewall
So I have opened Wireshark, and Indeed I saw that both phones are sending their broadcasts - it was logged on Wireshark.
But the python script only responded to the first one.
So this is why 1 & 3 are irrelevant - if the router firewall was blocking my UDP I would have still seen the python server response, same with the older versioned phone.
To get rid of 2 i just disabled the windows firewall - still same problem.
Does anyone has a clue to why this effect might happen?
Thanks!
Edit
My python code:
def scan(data, addr, sock):
print "received scan message:", data, addr
name = u"name".encode("utf-16-le")
data = "DISC" + short2bytes(len(name)) + name
print "sending back %s to %s" % (data, addr)
sock.sendto(data, addr)
if __name__ == "__main__":
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(('', UDP_PORT))
while 1:
data, addr = sock.recvfrom(1500)
print "received packet " + data
if data.startswith("SCAN"):
scan(data, addr, sock)
edit 2:
Okay! Seems like my code and protocol DID work.
As it turns out the 2.3.3 phone had some severe ARP problems.
After some resets it works flawlessly!