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

Using BLE NUS SERVICE without UART

Hello

I would like to send my sensor data to a mobile application using BLE SDK 15. Someone suggested me to go through the BLE NUS SERVICE example which was a good one. I understood a lot of things but now my sensor values are coming on analog pins and not on UART pins. How do i send those values? Would i have to create a whole new service for doing this or could i somehow modify the same example to work according to my needs. Thanks!  

Parents
  • Hello,

    What type of sensor do you use? Do they communicate using the UART protocol? If they do, then you can only change the uart_init() function in main.c to use the pins that you use. If they use some other protocol, then you have to read using the correct protocol, and then pass them on to the UART service. 

     

    You don't need to create anything else.

    Whatever is passed on into ble_nus_data_send() will be sent to the connected device, as long as notifications is enabled.

     

    Best regards,

    Edvin

  • Hello Edvin, Thank you for your response. I have a couple of more doubts  on UART service example before closing out on this string. I would highly appreciate if you could help me out with those. My sensors give values on analog pins using SAADC without using any other serial interface protocol. Now, i do not need to keep uart_init() function in my program and inside uart_event_handle(app_uart_evt_t * p_event) function, instead of using app_uart_get function i would call my custom function to fetch sensor values and use ble_nus_data_send() function to send that value to my connected mobile application . is that right or am i missing something here?

    Lastly, In this example my nrf52840 board is a peer and application is nordic uart mobile application. So, when i send data from my application to the board, then void nus_data_handler function is called?? and when i send data from board to mobile application then uart_event_handle() function is called???is that right?? or is it vice-versa.  I am sorry, i tried to put breakpoints to analyze this behavior but was not able to crack it.

    It would be great if i could get answers these questions. 

    Thanks and Regards,

  • Yes, I'm trying to send data through ble_nus_data_send(). First, i just want to understand that how does this API work by sending a demo data after regular intervals. Can you please see in my code that what all i'm doing wrong. I just want to send a test value to nrf connect application. 

    static void timeout_handler()
    {
         uint32_t       err_code;
        static uint8_t index = 1; //no of bytes 
        static uint8_t data_array = 21; //Test value 
          uint16_t length = (uint16_t)index;
          
        
          err_code =   ble_nus_data_send(&m_nus, &data_array, &length, m_conn_handle);
    
             if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) &&
                             (err_code != NRF_ERROR_NOT_FOUND) )
                        {
                            APP_ERROR_CHECK(err_code);
                        }
    
            NRF_LOG_INFO("Value Received !");
    }
      

    Thanks,

  • Did you enable notifications in the nRF Connect app?

    BR,
    Edvin

  • Yes, as you can see in the image. I have enabled the notification. I believe there is a bug in my code. Thanks,

  • Ok, good.

    Can you check the return value of ble_nus_data_send()? Does it return NRF_SUCCESS, or one of the other values that are filtered out, NRF_ERROR_INVALID_STATE or NRF_ERROR_BUSY?

     

    If not NRF_SUCCESS, I suspect NRF_ERROR_INVALID_STATE. If so, I think you are missing something that needs to be set up in the ble_nus_c setup. Compare your project with the ble_app_uart example. A keyword is p_client->is_notification_enabled in ble_nus.c.

     

    But first check what ble_nus_data_send() returns.

     

    BR,

    Edvin

  • Hello Edvin,

    How can i check the return value ? I am getting 0x00000005 as error code in te return value. 

    Thanks,

Reply Children
No Data
Related