We use MVVM architecture which is build on the above architecture components. here is a great tutorial for getting started with android tutorial
here is an overview about bluetooth in general.
We use both Bluetooth classic and Bluetooth Low Energy in our application.
Bluetooth classic is needed because the vending machine can't advertise when connected in LE mode. We need to keep receiving advertisements even when another user is vending so that users can still "see" the vending machine in app. Thus the device will keep sending advertisements in classic mode even when connected in LE mode.
there are two files dedicated for scanning and connection+communication respectively which was created referencing SimpleBluetoothLeTerminal
project file | referenced from |
---|---|
DeviceScanner | DeviceFragment |
DeviceCommunicator | TerminalFragment |
The VendingActivity handles the Bluetooth classic scanning.
There are multiple states which control the process flow and also used for better retry if required
Vending State | DeviceScannerState | Description |
---|---|---|
Init | ... | |
Scanning | Starts scanning | |
None | ... | |
DeviceInfoSet | Device MAC address loaded | |
ScanMode | Scan mode switch on | |
DeviceNearby | Device found nearby via classic Bluetooth scan | |
DeviceNotNearby | Device not found ... | |
DeviceBusy | Device not found via BLE scan | |
DeviceIdle | Device found via BLE scan | |
DeviceDiscovered | ... | |
ConnectionRequest | Connection request created | |
Connecting | Trying to connect to device | |
Connected | ... | |
ReceivedOtp | OTP received from device | |
ReceivedOtpWithBag | OTP + BAG receive from server | |
Vending | The device starts vending.. | |
VendingDone | Device vending done this state is skipped for now | |
ReceivedLog | LOG received from device | |
ReceivedLogAck | LOG ACK received from server | |
VendingComplete | ... |