Skip to main content

Bike Parking Guide

Simple guide for implementing bike parking functionality using the MOSA SDK. This guide focuses on SDK method calls from the mobile app's perspective.

Overview​

Bike parking allows users to lock their bikes at parking locations and unlock them later. The flow involves:

  1. Locking: User parks bike at a dock
  2. Unlocking: User retrieves bike from dock

Locking a Bike​

Step 1: Request Lock Key​

Request a bikeLock key for the parking area:

lifecycleScope.launch {
val unlockKey = sdk.requestUnlockKey(
type = MOSADockUnlockKeyType.BikeLock,
areaId = "area-123"
)

if (unlockKey != null) {
lockBike(unlockKey)
}
}

Step 2: Execute Lock Operation​

Call unlockSmartLock() with the lock key and parking location type:

private fun lockBike(unlockKey: MOSADockKey) {
lifecycleScope.launch {
sdk.unlockSmartLock(
unlockKey = unlockKey,
gfaLocationType = MOSADockLocationType.PARKING,
callback = object : MOSADockSDKCallback {
override fun onNFCScanCompleted(mosaTag: MosaTag) {
// NFC scan completed
}

override fun onBleConnecting() {
// BLE connecting
}

override fun onBleConnected() {
// BLE connected
}

override fun onKeySent() {
// Key sent to dock
}

override fun onDockUnlocked() {
// Dock unlocked
}

override fun onDockChainInserted() {
// Chain inserted - bike is locked
}

override fun onDockSecured() {
// Dock secured - operation complete
}

override fun onError(error: MosaError) {
// Handle error
}

// Implement other callbacks...
}
)
}
}

Callback Sequence for Locking​

The expected callback sequence:

  1. onNFCScanCompleted - NFC tag read
  2. onBleConnecting - BLE connection started
  3. onBleConnected - BLE connected
  4. onKeySent - Lock key sent to dock
  5. onDockUnlocked - Dock unlocked
  6. onDockChainInserted - Chain inserted (bike locked)
  7. onDockSecured - Dock secured (operation complete)

Unlocking a Bike​

Step 1: Request Unlock Key​

Request a bikeUnlock key. The SDK uses the existing session from the previous lock operation:

lifecycleScope.launch {
val unlockKey = sdk.requestUnlockKey(
type = MOSADockUnlockKeyType.BikeUnlock,
areaId = "area-123" // areaId from session
)

if (unlockKey != null) {
unlockBike(unlockKey)
}
}

Step 2: Execute Unlock Operation​

Call unlockSmartLock() with the unlock key and parking location type:

private fun unlockBike(unlockKey: MOSADockKey) {
lifecycleScope.launch {
sdk.unlockSmartLock(
unlockKey = unlockKey,
gfaLocationType = MOSADockLocationType.PARKING,
callback = object : MOSADockSDKCallback {
override fun onNFCScanCompleted(mosaTag: MosaTag) {
// NFC scan completed
}

override fun onBleConnecting() {
// BLE connecting
}

override fun onBleConnected() {
// BLE connected
}

override fun onKeySent() {
// Key sent to dock
}

override fun onDockUnlocked() {
// Dock unlocked
}

override fun onDockChainRemoved() {
// Chain removed - bike ready to take
}

override fun onError(error: MosaError) {
// Handle error
}

// Implement other callbacks...
}
)
}
}

Callback Sequence for Unlocking​

The expected callback sequence:

  1. onNFCScanCompleted - NFC tag read
  2. onBleConnecting - BLE connection started
  3. onBleConnected - BLE connected
  4. onKeySent - Unlock key sent to dock
  5. onDockUnlocked - Dock unlocked
  6. onDockChainRemoved - Chain removed (bike ready to take)

Complete Example​

Here's a complete example combining both operations:

class BikeParkingActivity : AppCompatActivity(), MOSADockSDKCallback {
private lateinit var sdk: MOSADockSDK

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

sdk = MOSADockSDK.builder()
.setActivity(this)
.setApiKey("your-api-key")
.setUserId("user-123")
.build()
}

fun parkBike() {
lifecycleScope.launch {
val unlockKey = sdk.requestUnlockKey(
type = MOSADockUnlockKeyType.BikeLock,
areaId = "area-123"
)

if (unlockKey != null) {
sdk.unlockSmartLock(
unlockKey = unlockKey,
gfaLocationType = MOSADockLocationType.PARKING,
callback = this@BikeParkingActivity
)
}
}
}

fun retrieveBike() {
lifecycleScope.launch {
val unlockKey = sdk.requestUnlockKey(
type = MOSADockUnlockKeyType.BikeUnlock,
areaId = "area-123"
)

if (unlockKey != null) {
sdk.unlockSmartLock(
unlockKey = unlockKey,
gfaLocationType = MOSADockLocationType.PARKING,
callback = this@BikeParkingActivity
)
}
}
}

// Implement callbacks...
}

Required Parameters​

Lock Operation​

  • Key Type: bikeLock
  • Area ID: ID of the parking area
  • Location Type: PARKING / .parking / parking

Unlock Operation​

  • Key Type: bikeUnlock
  • Area ID: ID of the parking area (from session)
  • Factory Dock ID: Obtained from NFC scan (handled internally)
  • Location Type: PARKING / .parking / parking

Next Steps​