Support for Bluetooth LE notifications?



  • Re: Bluetooth characteristic notifications

    Hi, I'm new to Pycom devices - I've had a couple of LoPy dev boards for a week or two and they seem great. I'm looking to use them in a commercial project that requires BLE notification support.

    I have programmed a LoPy to advertise a BLE service and characteristic with Read, Indicate & Notify properties. (Bluetooth server / peripheral)

    I am testing the connection using generic BLE apps (BLE Scanner for Android & LightBlue Explorer for iOS) to connect to the LoPy and read the values. The apps can connect and read the values from the LoPy, and the apps appear to show that I can successfully subscribe to notifications. However, it seems that the notification isn't triggered from the LoPy when the value changes. What I'd expect to see is that once the mobile app registers for notifications then any subsequent change in value on the LoPy side would trigger the new value to be sent to the mobile app, but only manually triggered reads seem to be working.

    Is sending notifications from a Bluetooth LE client supported yet? I can't find any reference in the docs or forum.

    Thanks



  • @wituwitu Did you find a way to solve this problem ? I'm having the same issue, I'm pretty sure I'm doing something wrong but I cannot find a solution



  • @scott (https://forum.pycom.io/post/9457) I tried running this code (I'm working on communication between LoPy4 and Android) but an error is raised:

    OSError: Erorr while sending BLE indication/notification

    Anyone got a fix?



  • @bucknall - I’m having exactly the same issue as described here. Was this bug fixed? Notify does not seem to alert the client that the value has changed.



  • @ledbelly2142 I haven't looked at power consumption yet.

    For testing I'm using these apps: BLE Scanner for Android & LightBlue Explorer for iOS. I'll be making my own apps for the final product.



  • @scott
    This seems like a really cool application for the LoPy. How much power do you see with "always on" GATT server consuming?
    Are you using a generic iOS or Android app to read the sensor data?

    Cheers



  • This issue appears to be resolved as of firmware release v1.7.7.b1

    A xxPy device running as a GATT server now successfully pushes notifications to clients. Thanks Pycom team!



  • Thanks @bucknall,

    I've created an issue here: https://github.com/pycom/pycom-micropython-sigfox/issues/40

    I've also been discussing it on a related issue here: https://github.com/pycom/pycom-micropython-sigfox/issues/37

    It looks like the missing functionality (i.e. not supporting BLE notifications when running as a BLE server) may be linked to the soon-to-be-implemented BLE characteristic descriptors. Hopefully BLE server-side notifications will work once the descriptor functionality has been implemented - although that hasn't been made clear yet.

    Thanks!



  • Hi @scott can you please create an issue on our github repo to add this to the on-going bus/issues please?

    https://github.com/pycom/pycom-micropython/issues

    Thanks!

    Alex



  • Here's some steps to reproduce on the LoPy (firmware version: 1.7.6.b1).

    Sample code:

    from network import Bluetooth
    import pycom
    import time
    
    print('Advertising Bluetooth...')
    bluetooth = Bluetooth()
    bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890abcdef')
    
    def conn_cb (bt_o):
        events = bt_o.events()
        if  events & Bluetooth.CLIENT_CONNECTED:
            print("Client connected")
        elif events & Bluetooth.CLIENT_DISCONNECTED:
            print("Client disconnected")
    
    bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
    bluetooth.advertise(True)
    
    #Create service and characteristic
    srv1 = bluetooth.service(uuid='0000000000000000', isprimary=True)
    chr1 = srv1.characteristic(uuid='0000000000000002', properties=Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value='InitialValue')
    
    #Create callback for read events on the characteristic
    def char1_cb(chr):
        events = chr.events()
        if events & Bluetooth.CHAR_READ_EVENT :
            print('Bluetooth.CHAR_READ_EVENT')
    
    chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char1_cb)
    
    #Update the characteristic value very few seconds
    i=0
    while True:
        val = 'Value{}'.format(i)
        print('Setting value: {}'.format(val))
        chr1.value(val) #Set the characteristic value - should trigger notification is a client has registered for notifications
        time.sleep(3)
        i+=1
    

    Steps to reproduce:

    1. The above code running on a LoPy advertises a BLE service and characteristic with Read, Indicate & Notify properties. The LoPy is acting as the Bluetooth server / peripheral in this case. The value of the characteristic will be changed every few seconds.
    2. Connect to the Lopy using a BLE app on a smartphone (e.g. BLE Scanner for Android or LightBlue Explorer for iOS).
    3. Test that manually triggering a read value works - it should
    4. Press the button on the app to subscribe to notifications. Expected: Every update in value on the LoPy should be notified to the app. Actual: No value updates are notified to the app. Only manually triggered reads seem to work.

    Is this a known issue or am I missing something?
    Thanks!



Pycom on Twitter