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

NRF52840 Automatically send a message

I have two of the nrf52840 boards and want one to implement a cascade reconciliation between them. That is device A and B have similar secret keys but need to make them match. To do this they repeatedly send each other the parity bits of different segments of the key.

How could I go about getting device A to send its parity bit to B and have B make a decision based on this and send back the correct parity bit? I understand what the messages must contain but am not sure how to create and send this information between them. I have worked a fair bit in the UART example for central and peripheral but have not found anything to create and send a message.

Parents
  • Hello,

    We are talking about sending over Bluetooth Low Energy here? Or do you mean UART?

    Why don't you just use pairing and bonding (BLE encryption), which is part of the BLE specification? Are you sure that you want to implement your own encryption implementation?

    If your question is really, how do I send a message from the peripheral to the central and from the central to the peripheral, then I suggest that you check out the ble_app_uart's function ble_nus_data_send() which is called from main.c (in the uart_event_handle() function). You can call this from wherever you like.

    On the central side, you can look at the function ble_nus_c_string_send(), which is almost identical (the central equivalent of ble_nus_data_send()).

    Best regards,

    Edvin

Reply
  • Hello,

    We are talking about sending over Bluetooth Low Energy here? Or do you mean UART?

    Why don't you just use pairing and bonding (BLE encryption), which is part of the BLE specification? Are you sure that you want to implement your own encryption implementation?

    If your question is really, how do I send a message from the peripheral to the central and from the central to the peripheral, then I suggest that you check out the ble_app_uart's function ble_nus_data_send() which is called from main.c (in the uart_event_handle() function). You can call this from wherever you like.

    On the central side, you can look at the function ble_nus_c_string_send(), which is almost identical (the central equivalent of ble_nus_data_send()).

    Best regards,

    Edvin

Children
  • Hi Edvin, thanks for your reply.

    I am trying to send over BLE but am working in the Uart example. I am also working on a project to develop some novel encryption scheme so cannot use the inbuilt methods.

    I see what you are talking about and it makes sense. When one device has calculated the data it must send I can simply call ble_nus_data_send(). How can I then get the other device to then perform a calculation and send a response upon receiving this data?

  • The other device will get the payload from your ble_nus_data_send() in an event. Then you can do some calculations, and use ble_nus_c_string_send() to send the response back.

    The events that you get when the other device sends data is:

    ble_nus_c_evt_handler() -> switch-case BLE_NUS_C_EVT_NUS_TX_EVT on the central

    and 

    nus_data_handler() -> switch-case BLE_NUS_EVT_RX_DATA on the peripheral.

Related