LeandroSQ / android-ble-made-easy

An Android Library for handling Bluetooth Low Energy on Android Easy
MIT License
88 stars 29 forks source link

Not able to scan And print #4

Closed iAmAndroidDeveloper closed 3 years ago

iAmAndroidDeveloper commented 3 years ago

@LeandroSQ after integration of your library i am not able to scan and get BLE devices. I checked increase time out as well

i am creating demo for print 58mm BLE printer i find name and mac address from other app but i dont what i need to pass as "characteristic" for write to printer?

i create receipt format but dont know hot to send this to BLE printer and after compete print disconnect with printer

can you please help me for that

Thanks.

LeandroSQ commented 3 years ago

Hello there, first of all thank you for the interest in the project, I appreciate it!

After reading your issue, I believe that your printer uses classic bluetooth to pair and receive print commands. Therefore you will not be able to scan, connect and neither communicate with it.

The library is tailored around the poorly functional BLE on Android, but unfortunatelly it wasn't made with Classical bluetooth in mind. But there are plenty of libraries that would be useful for your application.

For further information here is an article about the differences between BLE and Classical bluetooth

If you want to contribute to the project, by creating such support for Classical bluetooth, just create a PR and I will help as I can.

iAmAndroidDeveloper commented 3 years ago

@LeandroSQ Thanks for your feedback

iAmAndroidDeveloper commented 3 years ago

@LeandroSQ Now i am able to connect with BLE printer

connection?.let { // According to the 'active' boolean flag, send the information to the bluetooth device val result = it.write("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "Testing") Above line write (Print) some time only but connection create successfully every time any idea about that?

        if (result) {
         } else {
         }

}

LeandroSQ commented 3 years ago

Do you know the model of the printer that you are using?

iAmAndroidDeveloper commented 3 years ago

Please check I add images that I usedIMG_20210615_171119.jpgIMG_20210615_171107.jpgIMG_20210615_171100.jpg

iAmAndroidDeveloper commented 3 years ago

Some time able to printer and one more things that not able to print full string it's just print 1 line max rest of skipped

iAmAndroidDeveloper commented 3 years ago

I think see this was the main problem that receipt not print bulk data. Below loops not able to wait for for process

gatt.services?.forEach { service -> service.characteristics.forEach { characteristic -> if (characteristic.uuid == characteristicUuid) { characteristic.value = message return gatt.writeCharacteristic(characteristic).also { if (!it) log("Could not write to device ${device.address}") this.finishOperation() } } } }

LeandroSQ commented 3 years ago

I searched your printer model, and it seems that it makes uses the classic bluetooth

Being that clear, I do not recommend this Library to interface with your printer, since it wasn't made for that purpose. Unfortunatelly, I do not possess any bluetooth printer to verify that, so I'll list some libraries that I believe could help you far better:

iAmAndroidDeveloper commented 3 years ago

I Need library or code for only BLE device for Bluetooth(Pair and connect) i already done and its working fine, that's why i finding something that support all BLE printers and do print without any configs or issues

I used your library for only purpose of print and its already work when you give a chunks of data with used of using some millisecond's of delay (Like Handler or Somethings)

iAmAndroidDeveloper commented 3 years ago

@LeandroSQ after some days research finally got success to BLE search, and print text-image-Qr code without skipping any byte data