This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF Dongle as UART client python

Hi, I'm trying to write a simple python application on Windows 7 that communicates with a BLE peripheral running Nordic UART Service. I'm using the nRF dongle and pyserial and can get prints from the dongle when it is connecting to the peripheral (e.g. The device has the Nordic UART Service) but I can't send any data. I can't find any information about the python api regarding Nordic UART.

The nRF Dongle has been flashed with "ble_app_uart_c_pca10031_s130.hex"

What do I need to be able to send/receive data from a pyhton app to a BLE peripheral?

Parents
  • Hi,

    You can use pc-ble-driver-py to communicate with peripherals from your python program. See the examples in python/pc_ble_driver_py/examples for help getting started.

    [EDIT:]

    To use the Nordic UART service to read and write data, you have to add the UUIDs to your driver. An example of how this is done can be seen in the source of the BLE transport layer for the DFU service in nrfutil.

    Based on the HRS example code, adding the corresponding UUIDs for NUS will then be as follows.

    Define the UUIDs inside the HRCollector class:

        BASE_UUID     = BLEUUIDBase([0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93, 
                                     0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E])
    	NUS_TX_UUID   = BLEUUID(0x0003, BASE_UUID)
    

    Add your BASE_UUID to the driver (in HRCollector.open()):

    self.adapter.driver.ble_vs_uuid_add(HRCollector.BASE_UUID)
    

    Enable notification (in HRCollector.connect_and_discover()):

    self.adapter.enable_notification(conn_handle=new_conn, uuid=HRCollector.NUS_TX_UUID)
    

    Best regards,

    Jørgen

  • Hi thanks for your response. I'm have looked at the heart_rate_collector example and I get connected to my peripheral but when i try to write to it with write to a custom uuid (Nordic UART Service, 6E400002B5A3F393E0A9E50E24DCCA9E) I get an exception File "C:\Python27\lib\site-packages\pc_ble_driver_py\ble_adapter.py", line 282, in write_cmd raise NordicSemiException('Characteristic value handler not found') What shall a custom write_cmd look like?

Reply
  • Hi thanks for your response. I'm have looked at the heart_rate_collector example and I get connected to my peripheral but when i try to write to it with write to a custom uuid (Nordic UART Service, 6E400002B5A3F393E0A9E50E24DCCA9E) I get an exception File "C:\Python27\lib\site-packages\pc_ble_driver_py\ble_adapter.py", line 282, in write_cmd raise NordicSemiException('Characteristic value handler not found') What shall a custom write_cmd look like?

Children
No Data
Related