Skip to content

Instantly share code, notes, and snippets.

View ryanjjones10's full-sized avatar

Ryan Jones ryanjjones10

  • San Francisco, CA
View GitHub Profile
func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?){
peripheral.discoverCharacteristics(nil, forService: peripheral.services![0])
}
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?){
for characteristic in service.characteristics! {
let thisCharacteristic = characteristic as CBCharacteristic
if thisCharacteristic.UUID == txCharacteristic{
self.currentCharacteristic = thisCharacteristic
let openValue = "1".dataUsingEncoding(NSUTF8StringEncoding)!
self.peripheral.writeValue(openValue, forCharacteristic: self.currentCharacteristic, type: CBCharacteristicWriteType.WithResponse)
}
}
if let error = error {
import CoreBluetooth
import UIKit
class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate {
var centralManager: CBCentralManager!
var peripheral: CBPeripheral!
var currentCharacteristic: CBCharacteristic! = nil
var readRSSITimer: NSTimer!
var RSSIholder: NSNumber = 0