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?

  • 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.

  • 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).

     

Related