-
Notifications
You must be signed in to change notification settings - Fork 0
Bluetooth Component
An ATS server communicates to card readers on it's network via a persistent socket connection. Since bluetooth readers do not inherently have exposure to the network ATS is on, an IP adapter is required to proxy traffic to/from the reader's bluetooth connection. One component of the ATS SDK is an adapter for supported bluetooth-enabled card readers; specifically the Miura M010 and M020. This adapter allows the reader to communicate to ATS and operates completely separate from the ATS Client communication layer.
Generally if you are using a stock Mirua M20 the bluetooth protocol should be: com.miura.shuttle
or com.miura.mpi
Static Configuration
In this configuration, the mobile device has a static IP and is listening for ATS requests on a user-defined port. ATS can be configured to connect to this IP/port for a defined card reader. When the adapter receives the connection request from the ATS server, a bluetooth connection is created with the user-defined card reader.
Notable behavior:
As soon as the adapter is started in this configuration, it begins listening on a
Server Socket on the provided port number. Once an incoming connection is made from ATS, a bluetooth connection is attempted with the reader. If the bluetooth connection fails, either during initial attempt or mid-transaction, the connection with ATS will be closed but the adapter is still 'running'. ATS may be configured to retry after a period of time, so it is expected that another incoming socket connection follows shortly thereafter. You must deliberately 'stop' the adapter if you wish to prevent any more incoming connections from ATS.
Roaming Configuration
Using the roaming configuration, the adapter opens a bluetooth connection with the reader then connects directly to the ATS server. In this connection model, the mobile device does not require a static IP address and can connect the reader into a pool of devices on ATS. Further transactions can be processed with this reader by sending an AcquireDevice request to ATS. This configuration behaves similarly to wifi-connected readers.
Notable behavior: When the adapter is started in roaming configuration, connection attempts are made on the provided bluetooth reader. Once connected, the adapter will attempt an outbound connection to ATS to establish a communication channel. If at any point either of these sockets encounters an error, the adapter will retry the connection until the adapter is manually stopped. With the reader in this connection mode, it is entirely possible for other terminals on the network to acquire it for transactions.
The adapter can be started from anywhere within your app. If a persistent connection to a reader is required while an app is in the foreground, it is best to start the adapter in your custom Application class. To start the adapter, you must pass in a configuration object.
For Static Configuration:
import ATS_Device_SDK
let device = "Miura Device"
let protocol = "com.miura"
let port = 12345
let mode = ATSBluetoothAdapter.Mode.static(port: port)
var adapter = ATSBluetoothAdapter()
adapter?.start(deviceNamed: device, usingProtocol: proto, mode: mode)
For Roaming Configuration:
import ATS_Device_SDK
let device = "Miura Device"
let protocol = "com.miura"
let port = 12345
let atsHost = "1.1.1.1"
let mode = ATSBluetoothAdapter.Mode.roaming(atsIP: atsHost, atsPort: port)
var adapter = ATSBluetoothAdapter()
adapter?.start(deviceNamed: device, usingProtocol: proto, mode: mode)
adapter?.log.levels = .debug
adapter?.eventHandler = { _, event in
switch event {
case .started:
// handle the message
case .atsConnected:
// handle the message
case .deviceConnected:
// handle the message
case .deviceDisconnected:
// handle the message
case .atsDisconnected:
// handle the message
case .stopped:
// handle the message
case .error:
// handle error
}
}
You can stop the adapter and disconnect from the reader/ATS with a single line:
adapter.stop()
The mobile device in use may have several bluetooth devices in it's paired list. To help provide the user with a more concise list of supported bluetooth readers, you may request a short list from the adapter. This list will only contain devices that are currently known to be supported by the adapter and can then be displayed to the user in app configuration or setting screens.
ATSBluetoothAdapter.listDevices()