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?

  • Hi mhakbilen,

    Is your goal having the behavior of "pressing one button on a node turns on the light on another," or is your goal evaluating the customization of the Mesh: Chat sample?

    If your goal is the button-light behavior, then please look into the Bluetooth Mesh: Light switch and Bluetooth Mesh: Light samples. They use the Generic OnOff Client and Server and are the intended way to achieve that behavior.

    Hieu

  • No, I want to send a message. For example, to send a "Hello" message and take the action I want. 

    I want to send messages to devices that are grouped in Mesh:Chat software

  • 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
  • Hi,

    When I write chat private 0x0001 hello over the terminal myself, the led lights up on all mesh devices. I'm sure the led part is working. It receives the message and lights the led. But when there is a button, it does not light when pressed. When I look at the button example, I see that the configuration is correct. I share the code with you.

    chat_arastatek.rar

    Would you test code please.

  • At the same time, when I write that function into the button interrupt, the bluetooth connection is interrupted.

Related