iphone - hm-10 to iOS via Bluetooth -
i develop app sending , receiving between arduino , iphone via ble
i doing code.
func peripheral(_ peripheral: cbperipheral, diddiscovercharacteristicsfor service: cbservice, error: error?) { print("\(service)") if let characterarray = service.characteristics [cbcharacteristic]!{ cc in characterarray{ if(cc.uuid.uuidstring == "ffe1"){ print("connect") peripheral.readvalue(for: cc) } } } } func peripheral(_ peripheral: cbperipheral, didupdatevaluefor characteristic: cbcharacteristic, error: error?) { print("\(characteristic)") let text = "hello world" let senddata = text.data(using: .utf8)! peripheral.writevalue(senddata, for: characteristic, type: cbcharacteristicwritetype.withoutresponse) print("\(characteristic.uuid.uuidstring)") if (characteristic.uuid.uuidstring == "ffe1"){ let value = characteristic.value!.withunsafebytes { (pointer: unsafepointer<int>) -> int in return pointer.pointee } print("xx \(value)") } }
on serial monitor (arduino), can receive data iphone when type on serial monitor , send it. nothing changes on xcode debugger
Comments
Post a Comment