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

How to turn on LED base on message sent by ble_app_uart?

For example I want to turn on LED whenever I send 'a' text from my phone. How could I do cause I do not know where a message is stored. I am using ble_app_uart example 

  • Hello,

    The ble_app_uart example handle's its data received over BLE in the nus_data_handler function on line 196 of the example.
    As you can see in the source code of the example, it only iterates through the received data, and immediately outputs it on UART. The data is thus not 'stored' anywhere other than the event in which it was received.
    In this data handler, you may append a check to see what has been received, and if a certain character is received (such as 'a' in your case), you may toggle a LED.
    The toggling of a LED is demonstrated in the Blinky example, so you may take this functionality and merge it into your ble_app_uart, to have the LED toggle whenever a specific character or message is received.

    Best regards,
    Karl

  • Xiam said:
    its work, thank you a lot

    No problem at all, I am happy to hear that you achieved the desired functionality.

    Good luck with your development! 

    Best regards,
    Karl

  • Hi Karl

    Can I ask you another question? How can I collecting data from board over UART? Cause I connected LED to a button, then whenever I press a button I want a message "LED ON" is sent to my phone, still using ble app uart example

    Thank you 

  • Hello again,

    Xiam said:
    Can I ask you another question?

    Of course! it is no problem at all.
    For future reference, I would however recommend that you open a new ticket for a new question, but seeing how this is closely related to your original ticket, this is fine for now.

    Xiam said:
    How can I collecting data from board over UART? Cause I connected LED to a button, then whenever I press a button I want a message "LED ON" is sent to my phone, still using ble app uart example

    The sending of the UART data is done in the uart_event_handler function of the example.
    If the APP_UART_DATA_READY event is generated, that means that data has been received over UART, and that this data is located in the UART RX buffer. This data is then retrieved from the UART RX buffer, and queued for sending over BLE using ble_nus_data_send.

    To achieve the functionality you describe, you may copy the contents of the APP_UART_DATA_READY case into your button-press handler, remove the call to app_uart_get (since you do not need to retrieve anything from the UART RX buffer), and substitute it and it processing with a c string containing "LED ON".
    Then, this will be passed to ble_nus_data_send and queued for sending.

    Try this, and let me know if you are able to send the "LED ON" string to your mobile phone using this method.

    Best regards,
    Karl

Related