0

我正在尝试通过低功耗蓝牙 (BLE) 从 Lopy 向我的 Windows PC 发送数据。在 PC 上,我看到 Lopy,我可以连接他。但几秒钟后,Lopy 断开了连接。

这是我的代码:

bluetooth = Bluetooth()
bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890123456')

def conn_cb (bt_o):
    events = bt_o.events()   # this method returns the flags and clears the internal registry
    if events & Bluetooth.CLIENT_CONNECTED:
        print("Client connected")
        pycom.rgbled(0x00ff00) 
    elif events & Bluetooth.CLIENT_DISCONNECTED: 
        print("Client disconnected")
        pycom.rgbled(0xFF0000)

bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)

bluetooth.advertise(True)

srv1 = bluetooth.service(uuid=b'1223190123456', isprimary=True)
chr1 = srv1.characteristic(uuid=b'ab3451230123456', value=5)
while True:
    print("Send Data")
    chr1.value("here is the data need to be send  it should be a very very long string")
    time.sleep(3.050)

def char1_cb_handler(chr, data):
4

0 回答 0