Answer the question
In order to leave comments, you need to log in
Why is there an error when using BlueSwift?
I use the BlueSwift library to work with BLE.
Copied the example. Does not work. When trying to connect to the device - throws an error.
Source:
//
// ViewController.swift
// ESP32_BLE
//
// Created by Victor on 14.11.2019.
// Copyright © 2019 Snufkin52. All rights reserved.
//
import UIKit
import BlueSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
let connection = BluetoothConnection.shared
private var loading = false;
lazy var characteristic = try! Characteristic(uuid: "cc46b944-003e-42b6-b836-c4246b8f19a0", shouldObserveNotification: true)
lazy var service = try! Service(uuid: "9a8ca9ef-e43f-4157-9fee-c37a3d7dc12d", characteristics: [characteristic])
lazy var peripheral: Peripheral<Connectable> = {
let configuration = try! Configuration(services: [service], advertisement: "1004FD87-820F-438A-B757-7AC2C15C2D56")
return Peripheral(configuration: configuration)
}()
@IBAction func connect(_ sender: Any) {
connection.connect(peripheral) { [weak self] _ in
self?.loading = false
}
}
@IBAction func write()
{
let command = Command.utf8String("HELLO")
peripheral.write(command: command, characteristic: characteristic) { error in
print("Did write")
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question