Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi there!

I'm creating windows application in C++, which connect's PC with mobile via bluetooth and winsock. Allow's you to call and send messages from mobile via computer.

I'm using AT command's to tell mobile what i want to do. Pair with mobile device and force a call with At command
ATD+420******;
works perfect, but all commands for handling SMS like
AT+CMGL, AT+CMGF, AT+CMGS etc.
return's ERROR.

Here is code which connects PC with mobile via bluetooth and socket:
SOCKADDR_BTH RemoteEndPoint;
	RemoteEndPoint.port = 0;
	RemoteEndPoint.addressFamily = AF_BTH;
	RemoteEndPoint.btAddr = m_foundDevices[m_deviceIndex].Address.ullLong;
	RemoteEndPoint.serviceClassId = HandsfreeServiceClass_UUID;
	int BTHAddrLength = sizeof(RemoteEndPoint);

	// Create the socket.
	if ((m_localSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM)) == INVALID_SOCKET)
	{
		// handle error.
	}

	// Connect the socket.
	if ((iResult = connect(m_localSocket, (SOCKADDR *)&RemoteEndPoint, sizeof(RemoteEndPoint))) == INVALID_SOCKET)
	{
		// handle error.
	}

Notice line
RemoteEndPoint.serviceClassId = HandsfreeServiceClass_UUID

I think the problem is here, becouse u cant send sms from Handsfree, but when i use another UUID, it doesnt even pair with mobile.

=== Here is just for info, how am i sending and receiving data from mobile ===
char recvbuf[DEFAULT_BUFLEN] = "";
const char *sendbuf = "AT+CMGL\r";
int len = (int)strlen(sendbuf);
if ((iResult = send(m_localSocket, sendbuf, len, MSG_OOB)) == SOCKET_ERROR)
	{
		// handle error. return ~0
	}

	if ((iResult = recv(m_localSocket, recvbuf, recvbuflen, 0)) == SOCKET_ERROR)
	{
		// handle error. return ~0
	}
// Here recvbuf == "\r\nERROR\r\n"

Thank you for any advices! If you have any question's about problem, i'll kindly explain.
Regards,
Filip.

What I have tried:

Use another phones, with other OS. <- Didn't work.
Use another UUID's <- Didn't work.

Googling a lot of hour's, didn't find any solution.
Posted
Updated 12-Jul-17 22:20pm

1 solution

Sending modem commands to a bluetooth device sounds a bit weired.

I think you are using bad commands, so read the article Send and Read SMS through a GSM Modem using AT Commands to learn more about this issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900