about nrf mesh:chat example

Hi,

I use 3 devices in the Mesh application. I am looking at the Mesh:chat example. I want this,

I want to press a button on one device and light LED1 on other devices.
I tried to do some things while doing this, but I was not successful.

I set up a button interrupt into the button interrupt,

void button_pressed(const struct device *dev, struct gpio_callback *cb,
uint32_t pins)
{
bt_mesh_chat_cli_private_message_send(chat,0x001A,‘0x4C454459414B0A’);
}

I wrote it down when I took the data,

static void handle_chat_private_message(struct bt_mesh_chat_cli *chat,
struct bt_mesh_msg_msg_ctx *ctx,
const uint8_t *msg)
{
/* Don't print own messages. */
if (address_is_local(chat->model, ctx->addr)) {
return;
}

if (strcmp((const char *)msg, ‘LEDYAK’) == 0) {
gpio_pin_set_dt(&led, 1);
}
shell_print(chat_shell, ‘<0x%04X>: *you* %s’, ctx->addr, msg);
}

I used this code. But I was not successful. Is there a solution?

Parents
  • In this case, bt_mesh_chat_cli_private_message_send() is the right function to use.

    There are several places that things could go wrong here. Here are two things that people commonly overlook:

    1. The DK LED is active low, meaning that it lights up when you set it low.
      Check carefully how the LEDs are setup, from hardware to Devicetree to driver API usage.

    2. The button input could bounce, leading to repeated calling of the interrupt function.

    Note that I am not claiming it's definitely one of those two issues. It could be something else.

    I strongly suggest you adopt an incremental development approach, start from the unmodified sample, add, and test each small feature at a time. Here is the order of addition I would suggest:

    1. Setup button with debouncing and handler
      1. The DK Buttons and LEDs library provide native button debouncing
        The Mesh samples make use of this library and can serve as a good usage sample
    2. Setup LEDs
    3. Confirm sending message works
    4. Setup sending Chat message to trigger upon button press 
      1. It's a good practice to just raise a flag or queue a job in the button handler, not actually executing the job there. The job could be blocking, causing system timing issues
      2. Confirm via logging that the other end receives the message
    5. Add LED behavior to message handling
Reply
  • In this case, bt_mesh_chat_cli_private_message_send() is the right function to use.

    There are several places that things could go wrong here. Here are two things that people commonly overlook:

    1. The DK LED is active low, meaning that it lights up when you set it low.
      Check carefully how the LEDs are setup, from hardware to Devicetree to driver API usage.

    2. The button input could bounce, leading to repeated calling of the interrupt function.

    Note that I am not claiming it's definitely one of those two issues. It could be something else.

    I strongly suggest you adopt an incremental development approach, start from the unmodified sample, add, and test each small feature at a time. Here is the order of addition I would suggest:

    1. Setup button with debouncing and handler
      1. The DK Buttons and LEDs library provide native button debouncing
        The Mesh samples make use of this library and can serve as a good usage sample
    2. Setup LEDs
    3. Confirm sending message works
    4. Setup sending Chat message to trigger upon button press 
      1. It's a good practice to just raise a flag or queue a job in the button handler, not actually executing the job there. The job could be blocking, causing system timing issues
      2. Confirm via logging that the other end receives the message
    5. Add LED behavior to message handling
Children
Related