Setting bluetooth characteristic in new firmware



  • Hello!

    I'm trying to use Wipy as a BLE sensor. The following code is working on firmware 1.18.2.r7. I'm using the nRF Connect and with notifications enabled, characteristic changes are updated.
    But with newer firmware it crashes on chr1.value(i) with "OSError: Erorr while sending BLE indication/notification".

    from network import Bluetooth
    import time
    
    bt = Bluetooth()
    bt.set_advertisement(name='test-sensor', service_uuid=b'1234567890123456')
    
    bt.advertise(True)
    
    srv1 = bt.service(uuid=0x3000, isprimary=True, nbr_chars=1)
    
    chr1 = srv1.characteristic(uuid=0x3001, properties=Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value=0)
    
    i = 1
    while i < 10:
        chr1.value(i)
        print('characteristic value = '+str(i))
        time.sleep(5)
        i+=1
    


  • @wituwitu According to the answer from @lmo, you can only set the characteristic once you actually have a client connected. You'll get an error if you try to set it when there's no client.



  • I also have this problem... I tried with another similar code, but the same error "OSError: Erorr while sending BLE indication/notification" is displayed on chr1.value(val).

    Anyone got a fix?


  • Banned

    This post is deleted!


  • @lmo

    I have the same issue.

    Anyone have a fix for this problem?

    Thanks



  • Thanks @jcaron, that was it. It would be nice if the characteristic could be set even if no client is connected, but I can probably work around that.



  • @lmo not sure I ever played with the BLE stuff on the Pycom modules, but shouldn’t you need to wait for a connection before sending updates? Though it would seem legitimate for it to just cache the value and don’t send anything if there’s no connection.

    Does it throw on the first call, or after a few updates?


Log in to reply
 

Pycom on Twitter