c++ - Qt - disconnection from BLE device -
i'm trying understand why reconnection ble device fails qt. system ubuntu 14.04 built-in bt adapter, using qt 5.5.0 beta (happened qt 5.4.0).
basically i'm trying reconnect ble device, either same or different one, after deciding disconnect ble device. note first connection fine , works should be. error i'm getting right after doing m_control->connecttodevice();
qlowenergycontroller::unknownerror
.
stub of connection part (based on example code):
m_control = new qlowenergycontroller(qbluetoothaddress(connection_string), this); connect(m_control, signal(servicediscovered(qbluetoothuuid)), this, slot(servicediscovered(qbluetoothuuid))); connect(m_control, signal(discoveryfinished()), this, slot(servicescandone())); connect(m_control, signal(error(qlowenergycontroller::error)), this, slot(controllererror(qlowenergycontroller::error))); connect(m_control, signal(connected()), this, slot(deviceconnected())); connect(m_control, signal(disconnected()), this, slot(devicedisconnected())); m_control->connecttodevice();
and disconnection part:
if (m_control->state() != qlowenergycontroller::unconnectedstate) { m_control->disconnectfromdevice(); } delete m_control; m_control = null;
the way reconnect reset bt adapter or reset remote bt device. i'm unable scan device after software disconnection, i'm guessing it's still paired pc.
am doing wrong in process?
did subscribe notifications? see disconnection part no unsubscribing part. wonder if because previous connection has put peripheral state not suitable new connection.
you need unsubscribe notification: //disable notifications if (m_notificationdesc.isvalid() && m_service) { m_service->writedescriptor(m_notificationdesc, qbytearray::fromhex("0000")); } else { m_control->disconnectfromdevice(); delete m_service; m_service = 0; } }
Comments
Post a Comment