Bluetooth BLE problem with services



  • Hello,
    I’m working on a BLE communication between a wipy3.0 mounted on an expansionsboard v3.1 (as a GATT Server) and a lopy4 mounted on an expansionsboard v3.1 (as a GATT Client). I have a weird issue with services read by the Client. When I change the UUID of the services on the server, the Client show again the old UUID. If I add new services, the Client detects only the services of the first code. However, if I change the values of the characteristics, I can see the new characteristics of the Client.
    I used a mobile app to use my phone as a client. With the app, I can receive the data from the server and I have a good number of services with correct names and characteristics. So I think this issue comes from the Client.
    I try a factory hard reset but it changes anything.
    Does anyone have an idea? Does someone have the same issue?

    ################ BLE SERVER - Wipy  ########################
    from network import Bluetooth
    import pycom
    
    pycom.heartbeat(False)
    #pycom.rgbled(0x00007f)  # Blue
    
    def conn_cb(bt_o):
        events = bt_o.events()
        if  events & Bluetooth.CLIENT_CONNECTED:
            print("Client connected")
            pycom.rgbled(0x007f00) # green
        elif events & Bluetooth.CLIENT_DISCONNECTED:
            print("Client disconnected")
            pycom.rgbled(0x7f0000) # red
    
    
    def char1_cb_handler(chr, data):
        # The data is a tuple containing the triggering event and the value if the event is a WRITE event.
        # We recommend fetching the event and value from the input parameter, and not via characteristic.event() and characteristic.value()
        events, value = data
        if  events & Bluetooth.CHAR_WRITE_EVENT:
            print("Write request with value = {}".format(value))
        else:
            print('Read request on char 1')
    
    def char2_cb_handler(chr, data):
        # The value is not used in this callback as the WRITE events are not processed.
        events, value = data
        if  events & Bluetooth.CHAR_READ_EVENT:
            print('Read request on char 2')
    
    
    bluetooth = Bluetooth()
    bluetooth.set_advertisement(name='WiPy1', service_uuid=b'1234567890123456')
    bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
    bluetooth.advertise(True)
    
    
    srv1 = bluetooth.service(uuid=b'1234567890123456', isprimary=True)
    chr1 = srv1.characteristic(uuid=b'ab34567890123456', value=25)
    char1_cb = chr1.callback(trigger=Bluetooth.CHAR_WRITE_EVENT | Bluetooth.CHAR_READ_EVENT, handler=char1_cb_handler)
    
    srv2 = bluetooth.service(uuid=1234, isprimary=True)
    chr2 = srv2.characteristic(uuid=4567, value=0x1234)
    char2_cb = chr2.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char2_cb_handler)
    
    
    ################ BLE CLIENT - Lopy4  ########################
    from network import Bluetooth
    import time
    
    import ubinascii
    import sys 
    
    bluetooth = Bluetooth()
    
    # scan until we can connect to any BLE device around
    bluetooth.start_scan(-1)
    adv = None
    while True:
        adv = bluetooth.get_adv()
        if adv and bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'WiPy1':
            try:
                connection = bluetooth.connect(adv.mac)
                print("Connected to device with addr = {}".format(ubinascii.hexlify(adv.mac)))
                services = connection.services() 
                print("List of services : ",services)
                for service in services:
                    print("Service : ",service.uuid(),) 
                    chars = service.characteristics()
                    for char in chars:
                        if (char.properties() & Bluetooth.PROP_READ):
                            print('Characteristic : ',char.read()) 
                connection.disconnect()
            except:
                print("Error while connecting or reading from the BLE device")
            break
    
    


  • I solved the issue. I updated with the software Pycom Upgrade and I erased the NVS and CONFIG partitions.


Log in to reply
 

Pycom on Twitter