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
  • Dear Hieu,
    First of all thank you for your deep support.

    Mr Muhammed is our Nordic FAE. His responsibility is only Nordic.
    But sometimes there is topic we cannot go one step further.

    In this case we really would like to your professional review.

    This topic also we did many of research, we applied your all suggestions but we didnt go one step further.

    Could you please review our code, i believe that with your professional point of view you will guide us faster.

    Mr Muhammed is already attached our project file

    Best regards,

  • Dear Muhammed and Ekmekci,

    We can help you debug your project when necessary. However, I must politely point out that you haven't examined all the suggestions that I have made yet.

    The fact that the receiving behavior is working correctly is good information. That indicates that the issue lies with the sending.

    Then it is only a matter of testing whether the button works like you expect it to or not. A major part of my reply points out common issues when dealing with buttons and calling potentially blocking APIs.

    Please go over them first.

    Best regards,

    Hieu

  • I've followed all your steps. I've set up a thread, but dont work.

    Therefore,we are especially requesting help.

    chat_arastatek_V1.rar

  • I also installed k_work structure, unfortunately bluetooth disconnects every time.

  • The struct bt_mesh_chat_cli* you use were never initialized. It is just null. This causes your use of bt_mesh_chat_cli_private_message_send() to be invalid and result in a fault.

    You need to use a valid struct bt_mesh_chat_cli instance, such as that in model_handler.c.

Reply Children
No Data
Related