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

  • Note that this instructions was written for an older version of pc-ble-driver-py, they might not work with the current latest version. Please create a new question where you post what you have tried, and we will help you get it working.

  • Hi Jagen,

    I'm currently working on sending command with the python script with the method that you suggested but seems like I'm still getting the error code. I had been struggling with this issue for quite sometime so your help will be greatly appreciated.

    Below are my error code.

      File "Command.py", line 244, in main
        collector.write_word_characteristic(conn)
      File "Command.py", line 226, in write_word_characteristic
        self.adapter.write_req(conn_handle, NusCollector.CUS_WR_UUID, byte_array)
      File "C:\Python38\lib\site-packages\pc_ble_driver_py\ble_driver.py", line 104, in wrapper
        err_code = wrapped(*args, **kwargs)
      File "C:\Python38\lib\site-packages\pc_ble_driver_py\ble_adapter.py", line 487, in write_req
        raise NordicSemiException("Characteristic value handler not found")
    pc_ble_driver_py.exceptions.NordicSemiException: Characteristic value handler not found

Reply
  • Hi Jagen,

    I'm currently working on sending command with the python script with the method that you suggested but seems like I'm still getting the error code. I had been struggling with this issue for quite sometime so your help will be greatly appreciated.

    Below are my error code.

      File "Command.py", line 244, in main
        collector.write_word_characteristic(conn)
      File "Command.py", line 226, in write_word_characteristic
        self.adapter.write_req(conn_handle, NusCollector.CUS_WR_UUID, byte_array)
      File "C:\Python38\lib\site-packages\pc_ble_driver_py\ble_driver.py", line 104, in wrapper
        err_code = wrapped(*args, **kwargs)
      File "C:\Python38\lib\site-packages\pc_ble_driver_py\ble_adapter.py", line 487, in write_req
        raise NordicSemiException("Characteristic value handler not found")
    pc_ble_driver_py.exceptions.NordicSemiException: Characteristic value handler not found

Children
Related