Create a custom model in nrf mesh.

I am Creating a custom model for my application  using the chat client example.    My project is based on checking the battery percentage of a device using this model. So what are the steps that need to be taken while creating this model.  Also how to change the model name using the model ID. I have checked the vendor model development example. is there any other method to make the model.

Parents
  • Hi,

    The chat model implementation may be a good reference for making your own models, since it is a vendor specific model. I highly recommend that you have a look at the Chat sample walk-through, which explains how the chat model works and how it is implemented. With the walk-through, and studying the code, you should get a solid understanding of how it works and how to modify it towards what you need.

    I also recommend looking at the implementations of other mesh models, to see how to implement a typical server/client type model. Please remember that the difference between the SIG defined models and a vendor specific one, is basically the model ID and the size of the opcode for messages. This means you could base your model off of any of the existing models, provided that you change to using 3 byte opcodes for the messages, and use a proper model ID.

    Regards,
    Terje

  • i have created vendor model with op codes same as that of chat client example.

    #define BT_MESH_SPRINK_CLI_OP_SPRINK_ON_OFF BT_MESH_MODEL_OP_3(0x0A, \
                           BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID)

    #define BT_MESH_SPRINK_CLI_OP_BATTERY_PERC BT_MESH_MODEL_OP_3(0x0B, \
                           BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID)
                           
    #define BT_MESH_SPRINK_CLI_OP_FUNCTION_REPLY BT_MESH_MODEL_OP_3(0x0C, \
                           BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID)    
     
    is the opcodes given is correct.
    when i am sending data over the mesh its showning error <err> bt_mesh_access: Invalid message size for OpCode 0x00cb0059
    what will be the cause for this...
  • Hi,

    It basically means that the message doesn't have the exact size which you specified when defining what the message should look like, through use of the BT_MESH_LEN_EXACT macro.

    From the opcode, it looks like you are still using the Nordic Semiconductor vendor ID of 0x59, and with the third byte of the opcode being 0xCB, so none of the 0x0A, 0x0B or 0x0C that you quoted from your code.

    What is your BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID defined as, and what does your model definitions look like?

    Regards,
    Terje

Reply
  • Hi,

    It basically means that the message doesn't have the exact size which you specified when defining what the message should look like, through use of the BT_MESH_LEN_EXACT macro.

    From the opcode, it looks like you are still using the Nordic Semiconductor vendor ID of 0x59, and with the third byte of the opcode being 0xCB, so none of the 0x0A, 0x0B or 0x0C that you quoted from your code.

    What is your BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID defined as, and what does your model definitions look like?

    Regards,
    Terje

Children
  • #define BT_MESH_SPRINK_CLI_VENDOR_COMPANY_ID    CONFIG_BT_COMPANY_ID_NORDIC

    #define BT_MESH_SPRINK_CLI_VENDOR_MODEL_ID      0x0010 
    i have taken chat client example to give this opcodes. and given company id for nordic and vendor id have been given as 0x0010 . 
    [00:02:00.505,462] <err> bt_mesh_access: Invalid message size for OpCode 0x00cb0059  this is the error i am getting while sending the message
  • Hi,

    If you use the exact same vendor id and opcode as the chat client, then if you use a tool for testing the chat sample, it may send messages which do not fit for your changed model. The opcode would then be the same, but the content not correct for your model.

    Please note also that the size of messages for the model is defined somewhere in the model implementation. I do not know what you have named the c file for your model implementation, but in that file somewhere there would be use of the BT_MESH_LEN_EXACT macro, for defining the size of the message. The message that is sent when you test this, is not of that exact size. In order to fix the issue, you should either change the length defined using that macro, or the size of the message that you send, so that they correspond.

    Regards,
    Terje

  • thank you for the reply.  Also while giving our custom vedndor id do i need to follow any criteria or can i give it a raw value. Also the vendor mdoel ID 0x00A named as chat client. so if i need to give a custom name what should i need to do.

  • Hi,

    The vendor ID is also known as Company Identifier, and must be registered with the Bluetooth SIG. The way it works is you apply for a company identifier for your company, which is granted for a fee. In order to apply you must already register as a Bluetooth SIG member. This is similar to how you must be a Bluetooth SIG member in order to qualify Bluetooth products.

    When you have a Company Identifier, you have an address space of 64 possible 3 byte vendor specific opcodes, that you can use for Bluetooth Mesh. Those opcodes will then be unique to your company, and your company is the only entity to decide how to use them.

    Regards,
    Terje

Related