Is there a way to test SocketMobile integration without actual scanner? - socketscan

I have Android and iOS React Native app that requires user to scan barcodes. I am now working on integration with SocketMobile scanner.
Is there a way to test integration without actual scanner device? Maybe there's some kind of emulator?

Using the SDK you can enable a "SoftScan" device, which uses the built-in camera. The SoftScan device behaves just like a physical device and can be configured using the same APIs.
Enabling SoftScan
After ScanAPI is initialized; most likely inside ScanApiHelperNotification.onScanApiInitializeComplete()
mScanApiHelper.postSetSoftScanStatus(kSktScanEnableSoftScan, callback)
Once SoftScan is enabled, you will immediately receive a device arrival notification - in the same way you receive a device arrival notification when a physical device is connected via Bluetooth.
The SoftScan device does not support all the properties of a physical device and will return an unsupported error if you try to get/set one of the properties it does not support.
SoftScan uses the Barcode Scanner app, so make sure it is installed on your device

Related

BLE: Reconnect Android central to iOS peripheral

After days of research and trial and error my colleagues and I have to hope that the StackOverflow community has a working solution.
We got an Android Smartwatch. We developed an app which acts as the BLE central. The App shows a QR-Code encoding an UUID which is unique for every Smartwatch. While showing that QR code it's actively scanning for a device advertising a service with that UUID.
We also developed an iOS app which can scan that QR code and start advertising with the service UUID it received. The Android Smartwatch then connects very quickly to the iOS device.
One purpose of the Smartwatch is to show push notifications from the iOS device. So when the connection is successfully established, the Smartwatch-App subscribes to the ANCS Data Source and Notification Source characteristics. This initiates "Just Works" pairing, so you just have to click on "Pair" on the iOS device. Afterwards you have to allow that iOS notifications are shared to the Smartwatch and then the Smartwatch successfully receives notifications.
ANCS is also the reason why the iOS device MUST BE in the peripheral role.
Until here everything works fine.
When the user leaves the bluetooth range or dis- and enables bluetooth on the iOS device, an automatic reconnect should be triggered. It DOES reconnect when the iOS app is in foreground. Unfortunately it DOES NOT work when the iOS-App is in background. This is probably related to the fact, that the iOS device is not advertising with the required UUID when the app is in background as described in the CoreBluetooth documentation:
All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special “overflow” area; they can be discovered only by an iOS device that is explicitly scanning for them.
We tried many different ways to reconnect from the Android Smartwatch to iOS. From my understanding it should be working when making the first connectGatt with autoConnect=false and when the connection is lost, calling connectGatt on the lost device with autoConnect=true, but it never reconnects. At least not within 15 minutes. Scanning again also wouldn't work, as the UUID is not advertised in background anymore.
We also tried to additionally let the Android device act as peripheral, so the iOS can connect to it. After connecting we wrote data to an "INITIATE_ANCS"-characteristic and let the Android device call connectGatt on the device which was passed to onCharacteristicWrite. This led to interesting behavior:
- The connection was working, we could read a Smartwatch-Characteristic from iOS.
- When subscribing to the ANCS characteristics, it initiated pairing. But instead of "Just Works" pairing it showed a 6-digit code on the iOS device which we had to type onto the Smartwatch.
- The pairing was inititated on every new connect and it always created a new device in the systems device managers on both Android and iOS.
- The pairing WAS NOT inititated when the iOS app was in background.
We really did a thorough research and couldn't find a solution. Did we understand something wrong on how BLE for iOS and Android works? We really hope to find an expert here that has the knowledge what has to be done to make the reconnect work.
Edit:
The Android device is running on Android 5.1.1 and currently it's no option to update.
The iOS testing device is running iOS 13.3 and it should be compatible with iOS 13+

BLE Pairing with Android things acting as Peripheral

I'm using Android Things 1.0.4 in a prototype where it acts as BLE peripheral device: advertising services and running a GATT server.
I encounter an issue in the BLE pairing process when trying to bond the Android Things board (Raspberry Pi 3) and a smartphone.
Since the device has no display, I set using BluetoothConfigManager:
IoCapability = BluetoothConfigManager.IO_CAPABILITY_NONE
which results in the error AUTH_FAILED every time.
Instead,
IoCapability = BluetoothConfigManager.IO_CAPABILITY_OUT
logs the pairing key and prompts the smartphone to enter it during pairing, but it results in the REMOVED error.
Questions:
Is Android Things in peripheral role capable of handling BLE pairing or not yet?
Are there more things that need to be implemented in the app's code to replicate the full-fledged Android logic?
Here's the source code of the Android Things app to test BLE pairing and bonding
The same code stripped from Android Things specific elements completes BLE pairing and bonding successfully when running on an Android phone as Peripheral (server), and an Android device or iPhone as Central (client).
Generally speaking, if you attempt to read an encrypted GATT characteristic before pairing (which triggers the pairing logic automatically), this results in GATT error 137 returned from the read request (AUTH_FAIL). This is because the device doesn't have enough time to finish setting up the bond before a response is sent by the Bluetooth stack. Retying the read request again generally succeeds.
I have not tested this with an iOS client device, but it certainly holds true with an Android client connecting to an Android (Things) peripheral. As such, I would recommend a few things:
Have the client (mobile) device explicitly initiate pairing, and Android Things should simply react to these incoming requests in the BluetoothPairingCallback. This lets the mobile device decide the pairing type based on the reported capabilities of the IoT device.
Separate the pairing flow from the GATT flow. Pair to the discovered device separately from making any attempts to read the characteristics. This tends to be the best way to avoid timing problems.
Regarding capability choices, this depends on your device. In my experience, if you choose IO_CAPABILITY_NONE this results in PAIRING_VARIANT_CONSENT inside of onPairingInitiated() and the pairing operation succeeds once finishPairing() is called. If you adjust your capabilities, you should be prepared for any number of the variants requiring you to display a PIN for the mobile device to enter. I have not not personally tested these paths.

Sample code for Xamarin Cross Platform bluetooth connection

I have traied meny examples to connect Zebra IMZ320 Blutooth using Iphone on Xamarin Cross-Platform
I followed CoreBluetooth Namespace
enter link description here
and also using Plugin.BLE
but I couldnt connect my device eny one has success experience in connect Bluetooth printer using Xamarin cross platform ios
CoreBluetooth.framework is for Bluetooth Low-Energy:
Communicate with Bluetooth 4.0 low-energy devices.
The Core Bluetooth framework provides the classes needed for your apps
to communicate with devices that are equipped with Bluetooth low
energy wireless technology.
According to the specifications of the Zebra IMZ320, the communication mode are:
Secure Bluetooth 2.0, 802.11a/b/g/n (optional) or USB (client)
connectivity; Wi-Fi®-certified connectivity
That is not Bluetooth Low-Energy (which has been introduced in Bluetooth 4.0). You won't be able to find the printer with a Bluetooth Low-Energy scan, because the behavior, logic and implementation (protocols, norms, GATT, Peripheral/Service/Characteristic) are totally different.
Also, the description page of the Zebra IMZ320 gives a link (FAQ - Creating & Registering An IOS App) to how develop apps for it.
You need to use ExternalAccessory.framework for it.
If your app communicates with a Zebra product via Bluetooth using the
External Accessory Framework, and you plan to distribute the app via
the App Store or Volume Purchase Program Store, then you must register
the app with Zebra.
This page is general (and not specific to that printer). But according to the specs, it's not Bluetooth Low-Energy compliant (while others products might be, that's why there is a paragraph talking about CoreBluetooth in it).
That's normal behavior (using ExternalAccessory vs CoreBluetooth framework), because each one of them has a specific meaning and use.
Conclusion:
Use ExternalAccessory.framework, it is also available on Xamarin.

Is there any standard way to make our own BLE accessory device auto re-connectable in iOS /Android?

I'm wondering whether or not we can make a specific BLE peripheral device with having this ability to be supported by iOS/Android for automatic scanning for automatic reconnecting, i.e without using any extra app.
I think some standard BLE accessory devices (like Heart sensor) are already known by smartphones, so after first-time pairing, the smartphone's OS itself will scan for finding them again automatically for re-connecting each time when the connection gets lost.
Yes. If the device is a HID device then the system will auto connect to the device until you disable it in Android and unpair it in iOS.
But what's the purpose if you don't have an app?

Qt bluetooth server

Im running Qt on ubuntu. I want to write a simple program that recieves a line from android device(this device already has a program to connect and send info) over Bluetooth. How do i start a bluetooth server in QT? I tried to find examples, but all of them act like a client that looks for connection. My program should wait for connection and once it gets a connection, it waits for incoming messages and reads them.
The Bluetooth API provides connectivity between Bluetooth enabled devices.
You can find Bluetooth examples in Qt website here, also see some Bluetooth examples in Qt Creator examples.
Bluetooth chat example and Bluetooth file transfer example is works for you.
The Bluetooth chat example may be used with various Bluetooth terminal applications. For example you could compile the Qt BT chat example on your computer and connect to it from your cell phone running a Bluetooth Terminal application.
In order to do that all that is needed is to change the UUID values as described here and here. That is, in the chatserver.cpp file of the example one needs to change:
static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8");
Becomes:
static const QLatin1String serviceUuid("00001101-0000-1000-8000-00805F9B34FB");
You may also want to do the same thing in the chat.cpp if you are planning on using the client mode as well (in this case make sure to change the reversed UUID also, as described in this bug).

Resources