10 Replies Latest reply on May 25, 2018 11:39 PM by MUHAMMED SALIH T A

    IOS BLE Print (Printer disconnects)

    MUHAMMED SALIH T A

      I am using BLE print to connect and print with a zebra printer (zpl)

       

      my work flow is as follows
      Step 1. Scan printer,
      Step 2. Connect to the selected printer,

      Step 3. discoverServices

      Step 4. discoverCharacteristics,

      Step 5.  peripheral writeValue for Characteristic discovered

      Step 6 wait to complete and disconnect

      And this seems work fine, but in some devices after lots of successful prints just randomly loses connection, (ie the printer is not connecting to the iOS )

       

      is there any solution for this ?

        • Re: IOS BLE Print (Printer disconnects)
          Steven Si

          Does this problem occur while printing? Or do you mean that the printer was not detected during the scan? If the printer was not showing in scan, it could be the printer is connected to a different device, as it stops broadcasting once it's connected.

           

          If the disconnect occurs during the print, then we can use the following callback to monitor the disconnection and do remedy.

          - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
          
          1 of 1 people found this helpful
            • Re: IOS BLE Print (Printer disconnects)
              MUHAMMED SALIH T A

              Thanks, Steven

               

                   Actually, its scanning and discovered the device And trying to connect, but it does not get connected
              Once this happened, when we check the IOS Bluetooth list, it shows the same device twice. One as connected and one as not connected,
              Then we have to forget the device, turn on and off again(both printer and ios Bluetooth) 

               

               


              Any Idea ?

                • Re: IOS BLE Print (Printer disconnects)
                  Steven Si

                  The Bluetooth Classic and Low Energy (BLE) work independently. In iOS, if BLE is connected, the device will show up in the Bluetooth settings. When BLE is disconnected, the device will disappear from the Bluetooth settings.

                  For example, the upper on with an icon is the Bluetooth Classic. The lower one is BLE. If you see the BLE is connected in settings, it means the BLE device is already connected to your iOS througn an app. In that case, you cannot scan and connect to it through another app. The BLE will not show in the settings if is not connected or disconnected. Hope this helps.

                  1 of 1 people found this helpful
                    • Re: IOS BLE Print (Printer disconnects)
                      MUHAMMED SALIH T A

                      Hi Stephen

                       

                      The process we have in place at the minute is as follows:

                       

                      1. connect zebra zq520 to ipad via bluetooth - secure pairing code used

                      2. within our app we have a select printer function which allows us to ensure that the app only prints to correct printer (this was an issue at the start)

                      3. when we click print (for the first time) it then asks us to pair again by entering a pairing code

                      3. we then proceed to use our app and it prints many receipts

                      4. then randomly the app/ipad loses connection with the printer

                      5. the process we must go through each time then is to forget device in ipad bluetooth screen (2 devices show here one as connected and one as not connected). shut down the printer and power up and reconnect all over again

                       

                      My questions are:

                      1. should we be asked to pair twice ?

                      2. why are we seeing the device twice in the bluetooth screen ?

                      3. do we need to connect through ipad bluetooth or would it be better connecting directly from the app ?

                      4. any suggestions as to why we losing connection ?

                       

                      Any other suggestions / info you have would be greatly appreciated

                        • Re: IOS BLE Print (Printer disconnects)
                          Steven Si

                          From what you described above, it looks to me that you are using the Bluetooth Classic, not the Bluetooth Low Energy. This differs from the subject of this discussion thread. Am I right? I've never seen a Bluetooth Classic connection show twice in Bluetooth settings on iOS. Would you share a screenshot? I've no idear how this would happen. Would you be able to share the Xcode project here, so we can reproduce and debug?

                          1 of 1 people found this helpful
                            • Re: IOS BLE Print (Printer disconnects)
                              MUHAMMED SALIH T A

                              Hi Stephen

                                   I have copied the print section codes here
                                   https://github.com/mzalih/print
                                also the bluetooth settings looks like this

                              image1.JPG

                                • Re: IOS BLE Print (Printer disconnects)
                                  Steven Si

                                  I cannot reproduce the problem you have seen with your XCode project. As stated early, the BLE and Bluetooth Classic work independently. The Classic requires pairing to connect. Therefore there is an info icon next to the Classic connection on the Settings, to allow disconnect or forget. I don't know how you got two identical Bluetooth Classic showing on the Settings.

                                    • Re: IOS BLE Print (Printer disconnects)
                                      MUHAMMED SALIH T A

                                      The Xcode project contains the print code of my actual app,
                                      it's working as expected for me  most of the time


                                      and it starts to behave like not connecting  unexpectedly, then only the dual Bluetooth appears
                                      And how you tested? with paired the  Bluetooth or without pairing?

                                        • Re: IOS BLE Print (Printer disconnects)
                                          Steven Si

                                          Here are my observations.

                                          1. The ZPL used in the XCode is missing the "^XA" at line 27 in ViewController.m file. Without "^XA", the printer wouldn't print.

                                          2. I was able to build and run the test app on iPhone. Noticed that the "select printer" button may not work in the test app, as there is no tableView in the storyboard in the project. I was able to print by pressing "Print Now" button. But I noticed that whenever the "Print Now" button is pressed, a new CBCentralManager instance is created before disconnecting the previous connected peripheral. Even though the previously connected peripheral get disconnected implicitly when the previous instance of CBCentralManager get destroyed, because of the creation of the new instance of CBCentralManager. I would suggest to call  cancelPeripheralConnection to disconnect the peripheral if we don't need the connection. This way, we can reuse the same instance of CBCentralManager, by restarting a scan operation for new connection.

                                          3. Since I have many BLE printers surround me, I have to make a change in the didDiscoverPeripheral function in the test app to limit it only connects to the printer I want to print. So that the test app doesn't randomly connect to a printers. Though I've tried a number of times, I was not able to get to the situation as you described in you screenshot. Again, I do see two Bluetooth connection with the same name. But it is one for the standard Bluetooth Classic (with an info icon), one for the BLE (without the info icon).

                                           

                                          FYI - I've created a BLE demo app in Objective-C awhile ago. It's available on GitHub: ZebraPrinterBLEDemo. You may want to check it out. Hope it helps.

                                            • Re: IOS BLE Print (Printer disconnects)
                                              MUHAMMED SALIH T A

                                              Hi  Steven

                                               

                                              I am really sorry that the code  shared was not tested,
                                              I have created the sample code from copying only logic from my real project

                                               

                                              1. in original version we have ^XA, and I missed it in the real code

                                              2. I was creating the table view programmatically but forgot to add it to the view controller,

                                                   In our real application, we are disabling the print button, and enables back only after properly printed and after disconnected the   peripheral(also the same on print error), so the previous connection will be disconnected when printing again

                                              3. select printer option is handling the multiple printer problems for me

                                              In the real app before printing, we have multiple view controllers to pass through before printing,
                                              Also, this happens  after 50 - 100 prints when a print error occurs

                                               

                                              (Code updated)

                                              My printer was not with me now, I will check your code and will update accordingly if anything is needed

                                               

                                               

                                              Thanks