Can't connect to fsc-bt986
Opened this issue · 2 comments
mingchi21 commented
Board
XIAO-ESP32C3
Device Description
Bare XIAO-ESP32C3 board
Hardware Configuration
None
Version
v3.3.2
Type
Question
IDE Name
Arduino 2.0
Operating System
Windows 10
Flash frequency
160 Mhz
PSRAM enabled
yes
Upload speed
921600
Description
I hava a thermal printer with fsc-bt986 module, which is tested that is workable with Android.
And I am trying to connect to the thermal printer by ESP32, but get error response.
Sketch
pClient = BLEDevice::createClient();
String mac_addr = String(szMacAddress);
pClient->connect(*Server_BLE_Address);
if (!pClient->isConnected())
{
Serial.println("Connect failed");
return false;
}Debug Message
- Created client, connecting to dc:0d:30:73:95:59
[ 50524][D][BLEClient.cpp:944] handleGAPEvent(): BLEClient
[ 50524][I][BLEClient.cpp:983] handleGAPEvent(): BLEClient
[ 50524][I][BLEDevice.cpp:683] removePeerDevice(): remove: 0, GATT role client
[ 50525][D][BLESecurity.cpp:192] resetSecurity(): resetSecurity: Resetting security state
[ 50525][D][BLEClient.cpp:406] onDisconnect(): BLEClientCallbacks
[ 80522][D][BLEClient.cpp:944] handleGAPEvent(): BLEClient
[ 80523][D][BLEUtils.cpp:2190] gapEventToString(): gapEventToString: Unknown event type 38 0x26
[ 80523][D][BLEClient.cpp:944] handleGAPEvent(): BLEClient
[ 80523][E][BLEClient.cpp:854] connect(): Connection failed; status=13 Operation timed out.
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
lucasssvaz commented
Are you using some library to connect to it ? Could you please provide a minimal sketch to reproduce this issue ?
mingchi21 commented
I just figure out how to connect to fsc-bt986.
I try to connect fsc-bt986 by MAC address, but failed
BLEAddress *Server_BLE_Address;
bool connect_ble(const char *szMacAddress)
{
pClient = BLEDevice::createClient();
String mac_addr = String(szMacAddress);
Server_BLE_Address = new BLEAddress(mac_addr);
pClient->connect(*Server_BLE_Address); // this is fail
if (!pClient->isConnected())
{
Serial.println("Connect failed");
return false;
}
return true;
}
And try to connect by BLEAdvertisedDevice, this will work
char targetMacAddr[20];
static BLEAdvertisedDevice *myDevice;
/**
* Scan for BLE servers and find the first one that advertises the service we are looking for.
*/
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
/**
* Called for each advertising BLE server.
*/
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.print("BLE Advertised Device found: ");
Serial.println(advertisedDevice.toString().c_str());
if(!strncmp(advertisedDevice.getAddress().toString().c_str(), targetMacAddr, 18))
{
Serial.println("Found device, Stop ble scan");
BLEDevice::getScan()->stop();
myDevice = new BLEAdvertisedDevice(advertisedDevice);
} // Found our target
} // onResult
}; // MyAdvertisedDeviceCallbacks
bool connect_ble(const char *szMacAddress)
{
pClient = BLEDevice::createClient();
strncpy(targetMacAddr, szMacAddress, 18);
targetMacAddr[18] = 0;
if(myDevice != NULL)
{
delete myDevice;
}
myDevice = NULL;
BLEScan *pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setInterval(1349);
pBLEScan->setWindow(449);
pBLEScan->setActiveScan(true);
pBLEScan->start(5, false);
timeout = 5;
while(myDevice == NULL){
delay(1000);
if(--timeout == 0){
return false;
}
}
pClient->connect(myDevice); // This is OK
if (!pClient->isConnected())
{
Serial.println("Connect failed");
return false;
}
return true;
}
Conclusion:
For fsc-bt986 module:
pClient->connect(BLEAddress); // this is fail
pClient->connect(BLEAdvertisedDevice); // this is OK