Skip to content

Bluetooth Component

Nevada Kent edited this page Sep 11, 2019 · 3 revisions

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

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.

Static Config

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.

Roaming Config

Starting the Adapter

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 com.mastercard.gateway.ats.ATSBluetoothConfiguration

// Port for adapter to listen on for incoming ATS connections
val listeningPort = 12345
  
// Bluetooth device to connect to
val btDevice: BluetoothDevice = getDesiredBluetoothDevice() // user-defined method to get bluetooth device

val staticConfig = ATSBluetoothConfiguration.Static(listeningPort, btDevice)

val adapter = new ATSBluetoothAdapter()
adapter.start(staticConfig)

For Roaming Configuration:

import com.mastercard.gateway.ats.ATSBluetoothConfiguration
 
// IP-address of the ATS server
val atsIpAddress = "1.1.1.1"
 
// Port on ATS server to connect to
val atsPort = 6556
 
// Bluetooth device to connect to
val btDevice = getDesiredBluetoothDevice() // user-defined method to get bluetooth device
 
val roamingConfig = ATSBluetoothConfiguration.Roaming(atsIpAddress, atsPort, btDevice)
 
val adapter = new ATSBluetoothAdapter()
adapter.start(roamingConfig)

Stopping the Adapter

You can stop the adapter and disconnect from the reader/ATS with a single line:

adapter.stop()

Selecting a Bluetooth Device

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.

val supportedDevices: List<BluetoothDevice> = ATSBluetoothAdapter.getSupportedDevices()
Clone this wiki locally