don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
941 stars 601 forks source link

The plugin ble.write in versions after iOS 17 reported an error #1000

Closed zhanLaiDong closed 2 months ago

zhanLaiDong commented 4 months ago

Hello author, first of all, thank you for your contribution. After the iOS version was updated to 17, an error occurred in ble.write when Bluetooth was connected to the printer for printing. May I ask how to solve this problem? I cannot know exactly what information the user has lost, and I cannot reproduce it. I am very anxious. Please, thank you very much f1d49c2e470a7e90ce20351b1e4a7907

Could not find service with UUID FFF0 on peripheral with UUID AC9E3C01-1EC0-1172-6E27-36A516479242

zhanLaiDong commented 4 months ago

Hello, when I tried to connect to the printer using ble.connect, I tried the success callback function, but later when I used ble.isConnected to check the connection status with the printer, it showed that it was not connected. The device's status kept showing that it was connected. After disconnecting, I tried to connect again, but it still failed to print. These are all accidental occurrences. May I ask what the problem is? Please advise. Thank you 微信图片_20240107162817

zhanLaiDong commented 4 months ago

Please, brothers, wish you all a safe life

peitschie commented 4 months ago

Hi @zhanLaiDong

Can you paste what your javascript code wiring all this together looks like? In the above console screenshot there, it says the state is connecting still.

The device's status kept showing that it was connected

The phone may be connected but the app is not aware of this. Standard practice is to always call ble.connect on app launch and after any kind of disconnect.

zhanLaiDong commented 4 months ago

Hello, the current issue is that the customer did not continue printing for a short period of time after using Bluetooth to connect to the printer. For example, after about 20 minutes, this problem may occur again when printing. This is a random occurrence. The more printers and mobile phones there are around the customer, the higher the probability of errors. Thank you  

幸运信息 @.***

 

------------------ 原始邮件 ------------------ 发件人: "Philip @.>; 发送时间: 2024年1月8日(星期一) 上午9:55 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [don/cordova-plugin-ble-central] The plugin ble.write in versions after iOS 17 reported an error (Issue #1000)

Hi @zhanLaiDong

Can you paste what your javascript code wiring all this together looks like? In the above console screenshot there, it says the state is connecting still.

The device's status kept showing that it was connected

The phone may be connected but the app is not aware of this. Standard practice is to always call ble.connect on app launch and after any kind of disconnect.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

zhanLaiDong commented 4 months ago

Also, restarting the printer has no effect. Only after the app kills the process and reopens it can it print normally

幸运信息 @.***

 

------------------ 原始邮件 ------------------ 发件人: "don/cordova-plugin-ble-central" @.>; 发送时间: 2024年1月8日(星期一) 上午9:55 @.>; @.**@.>; 主题: Re: [don/cordova-plugin-ble-central] The plugin ble.write in versions after iOS 17 reported an error (Issue #1000)

Hi @zhanLaiDong

Can you paste what your javascript code wiring all this together looks like? In the above console screenshot there, it says the state is connecting still.

The device's status kept showing that it was connected

The phone may be connected but the app is not aware of this. Standard practice is to always call ble.connect on app launch and after any kind of disconnect.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

zhanLaiDong commented 4 months ago

After each printing of the app, it needs to be disconnected because there are multiple phones sharing the same printer device, so it cannot be kept connected all the time, which means other phones cannot connect to the printer

peitschie commented 4 months ago

@zhanLaiDong without examples of how the javascript connection loop there is working, it's fairly difficult to guess what's going on.

zhanLaiDong commented 4 months ago

This is a normal printed code, but there may be occasional printing errors. Please check, thank you code.docx

peitschie commented 4 months ago

So, a few things:

  1. The service can fail to be found if the printer is no longer connected by the time you attempt to write. This might be what's happening here, as you can see the CBPeripheral state is connecting in your screenshots above.
  2. I notice your doPrint method is allowing both a Write and WriteWithoutResponse method to be the writeService, however, you only ever call ble.write. This means that if you find WriteWithoutResponse for some reason, the write call will fail because you should be using ble.writeWithoutResponse

As an aside, the whole approach there to finding the characteristic is very unusual. Usually, the service and characteristic UUIDs are a fixed part of the contract, and don't need to be extracted like you are doing here.

peitschie commented 2 months ago

Closing this out due to inactivity. Feel free to re-open if there is still an unresolved issue here.