not receiving BLE notifications on pycom fipy



  • Hello,

    I am trying to receive bluetooth NOTIFY messages using the FiPy.

    The script I am running is as follows:

    from network import Bluetooth
    
    def mycb(chr):
        print("Callback succesful!")
    
    bt = Bluetooth()
    if not bt.isscanning(): #scan for devices
        bt.start_scan(-1)
    
    
    while True:
        adv = bt.get_adv()
        if adv and adv.mac == b"my_dev_mac":
            try:
                conn = bt.connect(adv.mac)
                services = conn.services()
                for service in services:
                        if service.uuid() ==  b'my_serv_uuid':
                            chars = service.characteristics()
                            for char in chars:
                                if char.uuid() == b'my_char_uuid':
                                    char.callback(trigger = Bluetooth.CHAR_NOTIFY_EVENT, handler=mycb)
    

    Using a different app (nRF on android) I can see the NOTIFYs being transmitted, so it's certain they are being transmitted. Reading and writing values also works fine, however the callback does not seem to work.

    What am I missing?

    Sincerely,
    Robert



  • @Robert-N have you had any success with notify egen connecting a pycom board as a client to a server (sensor) or is this not possible?



  • @jcaron I am sure that the callback works, I have gotten into the callback when using the nRF connect app as a server and sending notifications with that server. However after further tracing, it seems that I cannot properly subscribe to the NOTIFY characteristic. To subscribe for notifications it seems that you have to send a value to the descriptor, not the characteristic as I have been trying. The same problem got mentioned here: https://github.com/pycom/pycom-micropython-sigfox/issues/37, although it is still not clear how to write to the descriptor. Is there any way to write to the descriptor?



  • @Robert-N I mean, are you sure ˋchar.callback` is actually called? Add a trace there to make sure that happens. Just to make sure it’s not some stupid typo or something that prevents it from being executed.



  • @jcaron I am certain the services and characteristics are being transmitted, as I can read them. I am not quite sure what you mean by "callback being correctly installed", do I need to install the callback seperately? Is this not something that works out of the box?



  • @Robert-N have you checked that you actually get the service and characteristic and that the callback is correctly installed?


Log in to reply
 

Pycom on Twitter