Create a RFCOMM Server using Qt for symbian

1.1k Views Asked by At

I´m new on Qt, Symbian devices and Bluetooth.

I have to set up a RFCOMM server to receive connection from a bluetooth device (its a pinpad) that only support SPP profile.

I searched on google and found some examples, like this: http://doc.qt.nokia.com/qtmobility/btchat.html

Tried everything but I can´t connect them. Both devices was paired, but when I try to connect it fails.

When I asked to the manufacturer, they said that it was happening because the SPP Server on my celphone was not avaiable to listen for incoming connections.

I´m creating the RFCOMM server and registering the service just like the example, but it still not working.

Someone can help me?

I'm using Qt with QtMobility 1.2.0 and my cellphone is a Nokia 500 (Symbian^3).

Here is my code:

void bluetooth::startServer()
{
   QString deviceName;
   QBluetoothLocalDevice localDevice;

   if (rfcommServer)
      return;

   localDevice.powerOn();

   localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);

   deviceName = localDevice.name();

   rfcommServer = new QRfcommServer(this);

   connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(vConectou()))  ;

   if( rfcommServer->listen(localDevice.address(), 
                             quint16(rfcommServer->serverPort()) ) )
      emit vExibeMsg("Listening"); 
   else
      emit vExibeMsg("Error"); 

   serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, 
                             (uint)0x00010010);

   QBluetoothServiceInfo::Sequence classId;

   classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));

   serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);

   serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Test Server"));
   serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, 
                             tr("Test Bluetooth"));
   serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, deviceName );

   serviceInfo.setServiceUuid(QBluetoothUuid(QBluetoothUuid::Rfcomm));

   serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, 
                             QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));       

   QBluetoothServiceInfo::Sequence protocolDescriptorList;
   QBluetoothServiceInfo::Sequence protocol;

  /* 
   protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
   protocolDescriptorList.append(QVariant::fromValue(protocol));

   protocol.clear();

   protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
            << QVariant::fromValue(quint8(rfcommServer->serverPort()));

   protocolDescriptorList.append(QVariant::fromValue(protocol));

   protocol.clear();

   protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));

   protocolDescriptorList.append(QVariant::fromValue(protocol));
  */ 

   protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
            << QVariant::fromValue(quint8(rfcommServer->serverPort()));

   protocolDescriptorList.append(QVariant::fromValue(protocol));

   serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, 
                              protocolDescriptorList);

   if( serviceInfo.registerService() )
   {
      emit vExibeMsg("Waiting for connections...");
   }
   else
   {
      emit vExibeMsg("Error to create the service");
   }
}
0

There are 0 best solutions below