@@ -29,6 +29,7 @@ class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread
2929 uint8_t fromRadioBytes[meshtastic_FromRadio_size] = {0 };
3030 size_t numBytes = 0 ;
3131 bool hasChecked = false ;
32+ bool phoneWants = false ;
3233
3334 protected:
3435 virtual int32_t runOnce () override
@@ -38,10 +39,10 @@ class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread
3839 for (uint8_t i = 0 ; i < queue_size; i++) {
3940 handleToRadio (nimble_queue.at (i).data (), nimble_queue.at (i).length ());
4041 }
41- LOG_WARN (" Queue_size %u" , queue_size);
42+ LOG_DEBUG (" Queue_size %u" , queue_size);
4243 queue_size = 0 ;
4344 }
44- if (hasChecked == false ) {
45+ if (hasChecked == false && phoneWants == true ) {
4546 numBytes = getFromRadio (fromRadioBytes);
4647 hasChecked = true ;
4748 }
@@ -98,9 +99,12 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks
9899{
99100 virtual void onRead (NimBLECharacteristic *pCharacteristic)
100101 {
101- while (!bluetoothPhoneAPI->hasChecked ) {
102+ int tries = 0 ;
103+ bluetoothPhoneAPI->phoneWants = true ;
104+ while (!bluetoothPhoneAPI->hasChecked && tries < 100 ) {
102105 bluetoothPhoneAPI->setIntervalFromNow (0 );
103106 delay (20 );
107+ tries++;
104108 }
105109 std::lock_guard<std::mutex> guard (bluetoothPhoneAPI->nimble_mutex );
106110 std::string fromRadioByteString (bluetoothPhoneAPI->fromRadioBytes ,
@@ -111,6 +115,7 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks
111115 bluetoothPhoneAPI->setIntervalFromNow (0 );
112116 bluetoothPhoneAPI->numBytes = 0 ;
113117 bluetoothPhoneAPI->hasChecked = false ;
118+ bluetoothPhoneAPI->phoneWants = false ;
114119 }
115120};
116121
@@ -186,7 +191,12 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks
186191 new meshtastic::BluetoothStatus (meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED));
187192
188193 if (bluetoothPhoneAPI) {
194+ std::lock_guard<std::mutex> guard (bluetoothPhoneAPI->nimble_mutex );
189195 bluetoothPhoneAPI->close ();
196+ bluetoothPhoneAPI->hasChecked = false ;
197+ bluetoothPhoneAPI->phoneWants = false ;
198+ bluetoothPhoneAPI->numBytes = 0 ;
199+ bluetoothPhoneAPI->queue_size = 0 ;
190200 }
191201 }
192202};
0 commit comments