Pairing Device via BLE

Overview

BLEManager is a CoreBluetooth-based manager that handles Bluetooth Low Energy (BLE) communication with IV cameras. It provides functionality for discovering, connecting, and configuring cameras via BLE.

Table of Contents

  1. Enums
  2. Data Structures
  3. Properties
  4. Methods
  5. Usage Examples
  6. Implementation Details

Enums

CameraConnectionStatus

public enum CameraConnectionStatus {
    case connected
    case notConnected
    case none
}

AuthorizationStatus

public enum AuthorizationStatus {
    case allowed
    case notAllowed
    case none
}

WiFiConnectionStatus

public enum WiFiConnectionStatus: Int {
    case notConnected
    case connected
    case failed
}

Data Structures

WifiNetwork

public struct WifiNetwork: Codable, Equatable {
    public var ssid: String
    public var securityProtocol: Int
    public var rssi: Int
}

BLECamera

public struct BLECamera: Equatable {
    public var name: String
    public var identifier: UUID
    public var rssi: Int
    public var cameraDid: String?
    public var signal: Signal
    
    public enum Signal: Int {
        case poor = 0
        case weak
        case good
        case excellent
    }
}

WiFiDetailModel

public struct WiFiDetailModel: Codable {
    public var ssid: String
    public var password: String
    public var sessionKey: String
    public var env: String
    public var region: String
}

BLEManager Public Properties

Property Type Description Observable
instance BLEManager Singleton shared instance of the BLE manager No
bleCameraDID String The Device ID (DID) of the currently connected BLE camera No
cBManagerState CBManagerState Current state of the CoreBluetooth manager (poweredOn, poweredOff, etc.) ✅ Published
wifiList [WifiNetwork] List of available WiFi networks discovered by the camera ✅ Published
wifiConnctionStatus WiFiConnectionStatus Current status of WiFi connection (connected, notConnected, failed) ✅ Published
authorizationStatus AuthorizationStatus Bluetooth authorization status (allowed, notAllowed, none) ✅ Published
cameraConnectionStatus CameraConnectionStatus Current connection state with the camera (connected, notConnected, none) ✅ Published
noCameraFound Bool Flag indicating if no cameras were found during scanning ✅ Published
cameraList [BLECamera] List of discovered BLE cameras during scanning ✅ Published
bleCameraDIDFetched Bool Flag indicating whether the camera DID has been successfully retrieved ✅ Published
scanWifiSuccess Bool Flag indicating if WiFi scanning was successful ✅ Published

Property Details

Observable Properties

Marked with ✅ Published - these properties can be observed using Combine or SwiftUI for reactive updates:

// SwiftUI Example
@ObservedObject var bleManager = BLEManager.instance

// Combine Example
cancellable = bleManager.$cameraConnectionStatus
    .sink { status in
        print("Connection status changed to: \(status)")
    }

Initialization

public func initCBCentralManager()
Initializes the CoreBluetooth central manager.

Scanning

public func startScan()

Starts scanning for BLE cameras.

public func stopScan()

Stops scanning for BLE cameras.

Connection Management

public func connectToCamera(camera: BLECamera?)

Connects to a specific camera.

public func disconnect()

Disconnects from the current camera.

WiFi Operations

public func updateWifiInfo(wifiInfo: WiFiDetailModel)

Updates WiFi configuration information on the camera.

public func sendWiFiScanCommand()

Initiates WiFi network scanning.

public func getWiFiList()

Retrieves list of available WiFi networks.

Usage Examples

Basic Setup

let bleManager = BLEManager.instance
bleManager.initCBCentralManager()

Discovering Cameras

bleManager.startScan()

Connecting to a Camera

if let camera = bleManager.cameraList.first {
    bleManager.connectToCamera(camera: camera)
}

Configuring WiFi

let wifiInfo = WiFiDetailModel(
    ssid: "MyNetwork",
    password: "securepassword",
    sessionKey: "session123",
    env: "production",
    region: "US"
)
bleManager.updateWifiInfo(wifiInfo: wifiInfo)

Implementation Details

CoreBluetooth Integration

Implements CBCentralManagerDelegate and CBPeripheralDelegate Handles all BLE lifecycle events Manages service and characteristic discovery State Management

Uses @Published properties for reactive updates Maintains connection state machine Implements timeout handlers for operations Error Handling

Monitors CoreBluetooth state changes Handles peripheral disconnections Provides status flags for error conditions Data Processing

Handles chunked WiFi data transmission Converts between BLE data and native Swift types Implements custom WiFi network parsing Thread Safety

All BLE operations performed on dedicated queue State updates published on main thread