Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Mesh: Unknown message received by the node #24194

Closed
rhardik opened this issue Apr 8, 2020 · 3 comments
Closed

Bluetooth: Mesh: Unknown message received by the node #24194

rhardik opened this issue Apr 8, 2020 · 3 comments

Comments

@rhardik
Copy link

rhardik commented Apr 8, 2020

Describe the bug
I have setup for two devices Node-A (nRF52840 pca10056) and Node-B (nRF52 pca10040).
Node-B sends report continuously at interval of 2550 msec interval to Node-A.
Node-A receives a message with expected value but at the same time it gets one more message with garbage values.
Message length is 5 bytes so it's unsegmented message.

To Reproduce
Steps to reproduce the behavior:

  1. Follow zephyr setup guide
  2. $ git clone https://github.com/rajputh54/reproduce-zephyr-issues.git
  3. $ cd reproduce-zephyr-issues
  4. Copy node-a and node-b folders in zephyrproject or zephyr directory
  5. Compile node-a and node-b for nRF52 boards and flash the same.
  6. Now install nRF mesh app in Android phone.
  7. Provison node A and B
  8. configure Generic On Off Client (element section)
    • For Node-A, publish to 0xC000 and subscribe to 0xC001
    • For Node B publish to 0xC001 and subscribe to 0xC000
  9. Now press button-1 on Node-A device. Node-B will starts sending dummy envi report to Node-A.
    you can see in uart terminal or RTT viewer

Expected behavior
Node-A should get only one call to function envi_report every 2550 msec and print logs
temperature:32 airp:18 humidity:84
but Node-A gets the envi_report function call twice. First time it receives correct value and second call it gives some garbage value for airp and humidity
temperature:32 airp:18 humidity:84 Expected values
temperature:32 airp:3602 humidity:260 Garbage value for airp and humidity.

Impact
annoyance

Screenshots or Console output
Node-B (sender) console output
image

Node-A (receiver) console output
image

code snippet
To get full code please have a look at node-a/src/main.c and node-b/src/main.c

////Node-A envi_report function
static void envi_report(struct bt_mesh_model *model,
                struct bt_mesh_msg_ctx *ctx,
                struct net_buf_simple *buf)
{
        s8_t temperature = net_buf_simple_pull_u8(buf);
        u16_t airp = net_buf_simple_pull_le16(buf);
        u16_t humidity = net_buf_simple_pull_le16(buf);

       printk("------------------------\n");
       printk("-->[0x%04x] ", ctx->addr);
       printk("temperature:%hhd airp:%hu humidity:%hu\n", temperature, airp, humidity);
       printk("-------------------------\n");
}
//////Node-B envi report function
static inline void snd_envi_report(void)
{
        int ret;
        u16_t airp = 18, humidity = 84;
        s8_t temperature = die_temperature();
        #if 0
        printk("[<--0x%04x]:timestamp = %u\n", cfg->node_addr, timestamp);
        #endif
        bt_mesh_model_msg_init(mod_pub->msg, OP_ENVI_REPORT);
        net_buf_simple_add_u8(mod_pub->msg, temperature);
        net_buf_simple_add_le16(mod_pub->msg, airp);
        net_buf_simple_add_le16(mod_pub->msg, humidity);
        ret = bt_mesh_model_publish(mod_cli);
        if (ret) {
                printk("\n%s:bt_mesh_model_publish failed, ERR = %d\n", __func__, ret);
                return;
        }
        printk("------------------------\n");
        printk("temperature:%hhd airp:%hu humidity:%hu\n", temperature, airp, humidity);
        printk("-------------------------\n");
}
K_THREAD_DEFINE(envi_tid, 2048, envi_thread, NULL, NULL, NULL, 7, 0, K_NO_WAIT);
static void envi_thread(void)
{
        while (1) {

                if (envi_report_flg) {
                        k_sleep(K_MSEC(2500));
                        snd_envi_report();
                } else {
                        k_thread_suspend(envi_tid);
                }
        }
}

Environment

  • OS: Linux
  • Toolchain Zephyr SDK
  • Commit: b74cad5 (one can try with latest commit)
@rhardik rhardik added the bug The issue is a bug, or the PR is fixing a bug label Apr 8, 2020
@trond-snekvik trond-snekvik changed the title Unknown message received by the node Bluetooth: Mesh: Unknown message received by the node Apr 9, 2020
@LingaoM
Copy link
Collaborator

LingaoM commented Apr 9, 2020

@rajputh54 Can you send different data for every publish message ?
I'm notice that number 18 eq 0b0001 0010 and number 3602 eq 0b1110 0001 0010

@carlescufi carlescufi added question and removed bug The issue is a bug, or the PR is fixing a bug labels Apr 9, 2020
@LingaoM
Copy link
Collaborator

LingaoM commented Apr 9, 2020

While I'm found some buffer issure https://github.com/rajputh54/reproduce-zephyr-issues/blob/eb2f049467e778d20885b20561a9d6b48753b163/node-b/src/main.c#L118-L125

As you say above, every publish will occupy five octers (exclude opcode), but you allocated only four octers.

so, i'm guess that opcode OP_ENVI_REPORT --> 2 octers, and temperature --> 1 octer, and only one octer available for var airp (see #24194 (comment)), other value will be undefined.

Next: you should repair pub buffer to 2 + 1 + 2 + 2 octers.

@rhardik
Copy link
Author

rhardik commented Apr 9, 2020

Thanks a lot for your help !!!
As you suggested, It's working fine after adding enough pub buffer,

@rhardik rhardik closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants