Accessing mesh relay data from the application layer in Zephyr

Is there a way to access the data that comes into a provisioned node and is relayed on the mesh network, from the application layer in Zephyr?

I have a battery models erver and  I set it up for publishing to a certain address

On another device I subscribed to that address and in the RTT log I  see the data coming in and being relayed by the mesh stack but don't see a way to access it from my application.

There are callbacks in mesh model definitions , i.e BT_MESH_MODEL_CB and BT_MESH_MODEL_VND_CB  that use  bt_mesh_model_cb but it does not have any functions to examine the incoming data. What's the proper way to do this under Zephyr?
Thanks

Parents
  • The former. The model that the message is addressed to, in this case a battery server model. It is configured to publish to a group address. My expectation is  that if  node A  battery model is configured to publish to an address 123 and node B battery model is subscribed to receive messages from address 123, node B should receive a message from node A when it publishes it  If that understanding is correct, how can this message be examined at the application layer? Is  there an opcode handler that I need to implement? Sorry I'm still a newbie in mesh..Thank you

Reply
  • The former. The model that the message is addressed to, in this case a battery server model. It is configured to publish to a group address. My expectation is  that if  node A  battery model is configured to publish to an address 123 and node B battery model is subscribed to receive messages from address 123, node B should receive a message from node A when it publishes it  If that understanding is correct, how can this message be examined at the application layer? Is  there an opcode handler that I need to implement? Sorry I'm still a newbie in mesh..Thank you

Children
  • Hi,

    No worries.

    AndyM said:
    My expectation is  that if  node A  battery model is configured to publish to an address 123 and node B battery model is subscribed to receive messages from address 123, node B should receive a message from node A when it publishes it 

    This is correct, given that:

    • The models are of correct types for the message (e.g. a battery server model publishing a Generic Battery Status message, and a battery client model receiving it.)
    • Both models are bound to the same application key (through configuration)
    AndyM said:
    how can this message be examined at the application layer? Is  there an opcode handler that I need to implement?

    Please have a look at the API documentation for the Generic Battery Server and the Generic Battery Client libraries. For the server model, the state (i.e. the battery state) is kept in memory controlled by the application layer. For the client side, the call to bt_mesh_battery_cli_get() will either block (filling the provided memory with the response before it returns) or it will call a callback function (if said memory pointer is NULL).

    Regards,
    Terje

  • Update

    I added a battery model client and set up  a handler but I'm still not getting any battery info on the receiving side

    The client is instantiated as follows

    struct bt_mesh_battery_cli  _batt_client = BT_MESH_BATTERY_CLI_INIT(&batt_cli_handler);
    struct bt_mesh_model root_models[] = {
        BT_MESH_MODEL_CFG_SRV,
        BT_MESH_MODEL_HEALTH_SRV(&_health_srv, &_health_pub),          
        //TODO: FW reporting. Possibly use level server?
        // config and health clients needed for mesh shell,
        BT_MESH_MODEL_BATTERY_SRV(&_batt_srv),          
        BT_MESH_MODEL_CFG_CLI(&_config_client),
        BT_MESH_MODEL_BATTERY_CLI(&_batt_client),
    };
    static struct bt_mesh_elem elements[] = {
        BT_MESH_ELEM(0, root_models, vnd_models),
    };
    I then provision the device and enable publish on the battery model.
    mesh mod-pub 0x00ab 0x100c 0xC002 0 0 5 74 2 200
    That succeeds and I see messages from my "get" opcode handler in the debug log
    Then I provision a second device and subscribe to the battery server like so
     mesh mod-sub-add 0x100 0xC002 0x100c
    This also succeeds 
    I see that the messages arrive  in the log (see below)
    But my batt_cli_handler function is not called.
    What am I missing?
    Thanks

    00> [00:03:55.746,795] <dbg> bt_mesh_net: bt_mesh_net_decode: 28 bytes: 689acc3f34f33bdb64a2426c9b21cf38aed1a8ff82ee42a7dd145947
    00> [00:03:55.746,826] <dbg> bt_mesh_net_keys: bt_mesh_net_cred_find:
    00> [00:03:55.746,826] <dbg> bt_mesh_net: net_decrypt: NID 0x68
    00> [00:03:55.746,826] <dbg> bt_mesh_net: net_decrypt: IVI 0 net->iv_index 0x00000000
    00> [00:03:55.746,856] <dbg> bt_mesh_net: net_decrypt: src 0x00ab
    00> [00:03:55.746,948] <dbg> bt_mesh_net: bt_mesh_net_decode: Decryption successful. Payload len 24
    00> [00:03:55.746,978] <dbg> bt_mesh_net: bt_mesh_net_decode: src 0x00ab dst 0xc002 ttl 5
    00> [00:03:55.747,039] <dbg> bt_mesh_net: bt_mesh_net_decode: PDU: 68050000b400abc0026361ef25f1233a49acf4bcc8ad5865
    00> [00:03:55.747,161] <dbg> bt_mesh_net: bt_mesh_net_relay: TTL 5 CTL 0 dst 0xc002
    00> [00:03:55.747,192] <dbg> bt_mesh_net: bt_mesh_net_relay: Relaying packet. TTL is now 4
  • Update2

    Set up publication and subscription to battery model - all succeeded

    Battery client and server set up as above

    Tried calling bt_mesh_battery_cli_get(batt_client,NULL,NULL) - get an error -125

    Stumped. Please help

    Thanks

Related