Connecting nRF52832 to OBDII using NUS (Issue: Receiving a response from OBDII)

Hi everyone, I'm trying to communicate with OBDII through NUS using nRF52832. I was able to initiate the connection, send commands to OBDII, and get responses on the ECUsim 2000. However, I wasn't able to get the responses sent back to nRF52832 through bluetooth.

I used the centeral ble_app_uart_c example from the SDK.

The OBDII NUS UUID is 0x0000FFF0-0000-1000-8000-00805F9B34FB

#define NUS_BASE_UUID {{0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xEF, 0xFF, 0x00, 0x00}}
#define BLE_UUID_NUS_SERVICE 0xFFF0
#define BLE_UUID_NUS_RX_CHARACTERISTIC 0XFFF2 
#define BLE_UUID_NUS_TX_CHARACTERISTIC 0xFFF1 

For the UUID Type I used:

#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_BLE

After I send commands from nRF32 to OBDII, I get the expected results on ECUsim 2000. However, these results are not sent back to nRF32!

while debugging the code, I found that IF statement of the on_hvx function (ble_nus_c.c)  is never met (always treated as FALSE), and I'm not sure why is this happening.

static void on_hvx(ble_nus_c_t * p_ble_nus_c, ble_evt_t const * p_ble_evt)
{
      // HVX can only occur from client sending.
      if ( (p_ble_nus_c->handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID)
      && (p_ble_evt->evt.gattc_evt.params.hvx.handle != p_ble_nus_c->handles.nus_tx_handle)
      && (p_ble_nus_c->evt_handler != NULL))
      {
              ble_nus_c_evt_t ble_nus_c_evt;

              ble_nus_c_evt.evt_type = BLE_NUS_C_EVT_NUS_TX_EVT;
              ble_nus_c_evt.p_data = (uint8_t *)p_ble_evt->evt.gattc_evt.params.hvx.data;
              ble_nus_c_evt.data_len = p_ble_evt->evt.gattc_evt.params.hvx.len;

              p_ble_nus_c->evt_handler(p_ble_nus_c, &ble_nus_c_evt);
              printf("Client sending data.");
      }
}

Could you please help me solve this issue to get the results sent back to nRF32 through bluetooth?

Parents
  • Hi,

    This is basically unmodified NUS except that you use different UUIDs?

    The if statement consists of three checks:

    • p_ble_nus_c->handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID
    • p_ble_evt->evt.gattc_evt.params.hvx.handle != p_ble_nus_c->handles.nus_tx_handle
    • p_ble_nus_c->evt_handler != NULL

    Have you checked (with a debugger) which of these are false? If not, can you do it? Based on that we would know more on where to look.

Reply
  • Hi,

    This is basically unmodified NUS except that you use different UUIDs?

    The if statement consists of three checks:

    • p_ble_nus_c->handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID
    • p_ble_evt->evt.gattc_evt.params.hvx.handle != p_ble_nus_c->handles.nus_tx_handle
    • p_ble_nus_c->evt_handler != NULL

    Have you checked (with a debugger) which of these are false? If not, can you do it? Based on that we would know more on where to look.

Children
  • Thanks for the response Einar.

    Yes, this is unmodified NUS from SDK 17.1, Different UUIDs and UUID type.

    There was a typo on the statements, these are the statements (the first two are FALSE):

    • p_ble_nus_c->handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID
    • p_ble_evt->evt.gattc_evt.params.hvx.handle == p_ble_nus_c->handles.nus_tx_handle
    • p_ble_nus_c->evt_handler != NULL
  • Hi,

    I see. Assuming there is actually a notification received which is for this service, it seems you have problems with the handles. If you just changed the UUIDs that should be fine, but perhaps you did a mistake in your changes. I suggest you compare with the ble_nus_c implementation (NUS client). If you do not have progress perhaps you can upload the code here so I can have a look?

  • Changing only the UUIDs does nothing (Connection won't be initialized and I won't be able to send commands to OBD), I would need to change the UUID type as well in main.c in order to be able to pair with OBD (I set the type to BLE_UUID_TYPE_BLE). I comapred all the other files in the SDK, everything is matching. I'm assuming that changing the type of the UUID affects the handles, and there's something needs to be updated on handling the UUIDs that I'm not aware/sure about. 

    The OBD is using 16bit UUID for the service and the characters (that's why I changed it to BLE_UUID_TYPE_BLE)

    Not sure how am I connecting to the OBD and can send commands, but I think it's done through the service UUID (0xFFF0), without it connection fails. the base UUID and the RX/TX UUIDs are not affecting the connection and sending the commands to OBD.

    I'm receiving the following error "0xFFF0 Service is not found", but I'm still able to connect and send commands to OBDII (but not able to receive results back).

     

  • If the peripheral (OBDII device) use a 16 bit UUID for the service then you essentially do the same thing, you still need to add the base UUID and refer to it for the characteristics, but the service UUID is set without a base. I suggest you refer to ble_dfu_buttonless_init() in components\ble\ble_services\ble_dfu\ble_dfu.c for an example of that.

  • Thanks for the reply Einar!

    I tried to test the code with another nRF device with 128-bit UUID and it's working. Then I changed the UUID type of the peripheral to 16-bit, and updated the UUID type in the central code, it worked as well.

    However, for the OBDII it keeps saying that 0xFFF0 Service UUID not found.

    it's still not clear for me why I'm getting this error. I will summarise the issue down hopefully you or others can guide me through how to overcome it.

    Goal: Communicating with OBD through NUS (UART over BLE).

    Hardware: nRF52832 ß à OBDII (connected car simulator ECUsim2000)

    Software: ble_app_uart_c from nRF5_SDK_17.1.0

     

    • Succeeded in initiating the connection between the two devices.
    • Able to send commands from nRF to OBDII through NUS.
      • Monitored the OBDII traffic using USB connected to ECUsim2000, proved that commands are received by OBDII and results are as expected.

     

    ISSUE:

    Not able to receive OBDII results back in nRF (due to nRF not being able to discover OBDII service)

    After debugging the software, and testing it with another BLE device (software is working with both 128bit UUIDs and 16bit UUIDs)

     

    Used Base UUID: {{0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xEF, 0xFF, 0x00, 0x00}}

                  Also tried: {{0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}

    Used Service UUID: 0xFFF0

    Used TX and RX UUIDS: 0xFFF1 and 0xFFF2 (tried flipping them)

    Used 16-bit UUID Type

     

    • The device finds the OBDII, connect with it, and can send commands to it. However, it’s not receiving the OBDII results back in the device due to the “OBDII FFF0 service not found”.

    Any help is appreciated. Thanks!

Related