/SesameSDK_iOS_with_DemoApp

SesameSDK3.0は、iOS/Android/Embedded向けのBluetooth/AIoT(Internet of Things)ライブラリであり、オープンソース、使いやすく、強力、かつ永続的に無料です。公式のセサミアプリもこのSesameSDKを使用しており、このSDKを用いてあなたのアプリにもセサミアプリが持つ全ての機能を組み込むことができます。

Primary LanguageSwiftMIT LicenseMIT

img

SesameSDK3.0 for iOS

Contents

Overview

SesameSDK is an open-source, free, easy-to-use, and powerful Bluetooth/AIoT library for Apps on iOS/macOS/watchOS/iPadOS. The official Sesame application also uses this SesameSDK to build and realize all its features. Things you can do with SesameSDK:

  • Register Sesame devices (Sesame 5, Sesame 5 pro, Sesame Bike2, BLE Connector1, Open Sensor1, Sesame Touch 1 Pro, Sesame Touch 1, Sesame Bot1, WIFI Module2, Sesame 4, Sesame 3, Sesame Bike1)
  • Lock, unlock, or operate
  • Obtain historical records
  • Update SesameOS over the air(OTA)
  • Various device settings
  • Get battery level

Requirements

.


Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It integrates with the Swift build system to automatically carry out the process of downloading, compiling, and linking dependencies. To integrate SesameSDK into your Xcode project using Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/CANDY-HOUSE/SesameSDK_iOS_with_DemoApp.git", .branch("master"))
]

img

Manually

If you don't want to use any dependency manager, you can manually integrate SesameSDK into your project. img

Usage

1. Add Permissions

<key>NSBluetoothAlwaysUsageDescription</key>
<string>To connect Sesame Smart Lock and lock/unlock the door.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app would like to make data available to nearby bluetooth devices even when you're not using the app.</string>

2. Initialization

Please start the Bluetooth scan at the appropriate time

CHBluetoothCenter.shared.enableScan { res in }

Callback when the Bluetooth status changes

public protocol CHBleStatusDelegate: AnyObject {
    func didScanChange(status: CHScanStatus)
}

The list of scanned Sesame devices will be passed back to the caller at a frequency of once per second.

public protocol CHBleManagerDelegate: AnyObject {
    func didDiscoverUnRegisteredCHDevices(_ devices: [CHDevice])
}

3. Connect to Device

Before establishing a connection, you should first confirm that the device's status is connectable

if sesame5.deviceStatus == .receivedBle() {
    sesame5.connect() { _ in }
}

At this point, you will receive the Sesame device's connection status callback

public protocol CHDeviceStatusDelegate: AnyObject {
    func onBleDeviceStatusChanged(device: CHDevice, status: CHDeviceStatus, shadowStatus: CHDeviceStatus?)
    func onMechStatus(device: CHDevice)
}

4. Register Device

When the connection status changes to ready to register, you can register the device to complete the pairing. Registration is a necessary step to bind the device

if device.deviceStatus == .readyToRegister() {
    device.register( _ in )
}

After registration, you can get paired devices through the CHDeviceManager

var chDevices = [CHDevice]()
CHDeviceManager.shared.getCHDevices { result in
    if case let .success(devices) = result {
        chDevices = devices.data
    }
}

After completing the registration and pairing, you can now control the Sesame device via Bluetooth

Design

Regarding the design details of SesameSDK, please refer to the following design diagrams and flowcharts.

Bluetooth State Transition Flow Chart

BleConnect

Framework Diagram

framework_diagram

Sequence Diagram

Sequence_diagram

Class Diagram

Class_diagram