diff --git a/esp3d/src/modules/bluetooth/BT_service.cpp b/esp3d/src/modules/bluetooth/BT_service.cpp index f0b0af24..28ce805a 100644 --- a/esp3d/src/modules/bluetooth/BT_service.cpp +++ b/esp3d/src/modules/bluetooth/BT_service.cpp @@ -71,6 +71,7 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { BTService::setClientAddress(str); String stmp = "BT Connected with "; stmp += str; + esp3d_log_d("BT Connected with %s", str); esp3d_commands.dispatch(stmp.c_str(), ESP3DClientType::all_clients, no_id, ESP3DMessageType::unique, ESP3DClientType::system, ESP3DAuthenticationLevel::admin); @@ -83,6 +84,7 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { ESP3DClientType::system, ESP3DAuthenticationLevel::admin); BTService::setClientAddress(""); + esp3d_log_d("BT Disconnected"); } break; default: break; @@ -124,7 +126,7 @@ bool BTService::begin() { ESP3DMessageType::unique, ESP3DClientType::bluetooth, ESP3DAuthenticationLevel::admin); initAuthentication(); - + _started = res; return res; } @@ -150,7 +152,6 @@ bool BTService::reset() { * Check if BT is on and working */ bool BTService::started() { - _started = btStarted(); return _started; } @@ -222,6 +223,7 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) { } for (size_t i = 0; i < len; i++) { _lastflush = millis(); + esp3d_log_d("BTService::push2buffer: %c", sbuf[i]); if (esp3d_string::isRealTimeCommand(sbuf[i])) { flushChar(sbuf[i]); } else { @@ -237,8 +239,11 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) { size_t BTService::writeBytes(const uint8_t *buffer, size_t size) { if (availableForWrite() >= size) { + esp3d_log_d("BTService::writeBytes: %d bytes", size); return SerialBT.write(buffer, size); } else { + esp3d_log_d("BTService::writeBytes: %d bytes, not enough space", + size); size_t sizetosend = size; size_t sizesent = 0; uint8_t *buffertmp = (uint8_t *)buffer; @@ -278,11 +283,18 @@ const char *BTService::hostname() { return _btname.c_str(); } bool BTService::dispatch(ESP3DMessage *message) { if (!message || !_started) { + if (!message){ + esp3d_log_e("BTService::dispatch: No message"); + } else { + esp3d_log_e("BTService::dispatch: BT not started"); + } return false; } if (message->size > 0 && message->data) { size_t sentcnt = writeBytes(message->data, message->size); if (sentcnt != message->size) { + esp3d_log_e("BTService::dispatch:%s sent %d bytes, expected %d bytes", + (const char *)message->data,sentcnt, message->size); return false; } esp3d_message_manager.deleteMsg(message);