我正在使用BLE应用与Raspberry Pi 3通讯。使用iOS应用,我想发送信号,而树莓必须接收信号。 Python代码正在等待通知。
关于iOS应用程序和Raspberry Pi的各个方面,我都有几篇文章,但没有一篇可以一起工作。
iOS代码:
@IBAction func ButtonSet1 (_ sender: Any) { // Button defenition SET
let string = "1"
let data = string.data(using: String.Encoding.utf8)
let characteristic = servoCharacteristic
//get right on out of _characteristics! array
_peripheral?.writeValue((data)!, for: characteristic!, type: CBCharacteristicWriteType.withResponse)
print(data!)
}
Python 3代码:
from bluepy import btle
class MyDelegate(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
def handleNotification(self, cHandle, data):
print("A notification was received: %s" %data)
p = btle.Peripheral("44:00:10:28:63:ac")
p.setDelegate( MyDelegate() )
# Setup to turn notifications on, e.g.
svc = p.getServiceByUUID("d0611e78-bbb4-4591-a5f8-487910ae4366")
ch = svc.getCharacteristics()[0]
print('ch.valHandle')
while True:
p.waitForNotifications(1)
# handleNotification() was called
if p==1:
print('1')
else:
print('0')
pass
p.disconnect()
在双方,我都没有任何错误,但是他们彼此之间没有沟通。