Difficult To Connect Thermal Printer via Web Bluetooth
Asked Answered
P

2

3

Right now I am developing web which has ability to connect thermal printer. I am using angular framework, and I successfully connect the thermal printer with USB using library ng-thermal-printer. But I want to my web also being able to connect thermal printer via web bluetooth which is BLE (Bluetooth Low Energy). As far as I know, BLE has specification in term of GATT and has services and characteristics in it.

The progress I did so far, I can connect and send a value to the thermal printer device in a Service and a Characteristic, let's say Service with UUID AS and Characteristics with UUID AC, using my android phone with the help of application named nRF Connect. Targeting Service AS and send hexadecimal value at charateristic AC make me successfully print something on the thermal paper.

But there is a problem. After knowing the right service and characteristic. I implemented it in my project. But, my chrome browser console showed error:

  1. Origin is not allowed to access any service... and it told me to add optionalServices when requestiDevice()
  2. After I added Service AS in property optionalServices, the console showed error DOMException: Connection failed for unknown reason. The errors showed both in chrome PC and chrome android.

NB:

  • I have enabled Experimental Web Platform features on chrome
  • I have enabled Use the new permissions backend for Web Bluetooth on chrome
  • I have enabled Allow invalid certificates for resources loaded from localhost. on chrome
  • I have enabled Enable new USB backend on chrome
  • I have used https.

Additional question. is bluetooth connection that application nRF Connect used different from BLE? if so, why it displays services and characteristics?

Promycelium answered 12/6, 2021 at 10:13 Comment(0)
P
5

I have fixed this problem.

There are 2 devices that I use, my pc and my android phone. Actually, my PC's Bluetooth does not support BLE. This is why I keep struggling to debug as my chrome for desktop keeps being not responding after trying to connect my thermal printer.

Basically, error number 2 appears because I sent an encoded string value, not a UInt8Array value.

Eventually, I use 2 web APIs. web Bluetooth API for connecting my PWA to my thermal printer from mobile and web Serial API for connecting my PWA to my thermal printer from the desktop. The library, ng-thermal-printer, is good for my project. I just need to extend the driver.

Promycelium answered 14/6, 2021 at 10:38 Comment(2)
i wonder how you did itLynda
@Lynda I only use that library. Serial for non-ble device and ble for ble device. because in my case if i use ble for non-ble device, edge and chrome are getting freezePromycelium
N
3

I'd recommend you try sending those hex values directly from the about:bluetooth-internals page and see if you can reproduce the connection error from there as well. See https://web.dev/bluetooth/#tips

If so, check out https://www.chromium.org/developers/how-tos/file-web-bluetooth-bugs to learn how to properly file a chromium bug so that the team can fix the underlying issue.

If not, could you share your JS code so that we can help you diagnose what could be going wrong in your code?

Nassir answered 14/6, 2021 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.