0

I am trying to send data from the Lopy to my Windows PC over Bluetooth Low Energy (BLE). On the PC, I see the Lopy and I can connect him. But a few seconds later the Lopy disconnects.

This is my code:

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):
wovano
  • 4,543
  • 5
  • 22
  • 49
Ani
  • 1

0 Answers0