5 Replies Latest reply on Mar 14, 2020 8:01 AM by VictorZ_46

    [CYBT-423028] what is the best way to send a message over Mesh

    TiEt_4607661

      I have a CYBT-423028-EVAL and a CYBT-423028-02. I'm running a Mesh Level Server on the EVAL board and want to run a Level Client on the 423028-02, which changes the level of the level server. I'm doing the provisioning with a mobile app. Which API function should I use to send the message and which configurations do I need while provisioning?

       

      What I do for provisioning: Provision both devices(Level Server gets unicast address 0x0002 and Level Client gets 0x0004), bind app key to Generic Level Server(model ID 0x1002) in element 0x0002 of the Level Server, bind the same app key to Generic Level Client (model ID 0x1003) in element 0x0004 of the Level Client, set publish address of Generic Level Client (model ID 0x1003) to 0xFFFF for all nodes. Am I missing any steps or doing anything unnecessary?

       

      I'm using WICED Studio v6.2 because apparently there are missing platform files on v6.4 (BugS Report:  WICED6.4.0/Missing files )

       

      I can change the level of the server and read the current state using the mobile app.

       

      I can provide additional details if required.

        • 1. Re: [CYBT-423028] what is the best way to send a message over Mesh
          DheerajP_41

          Hi,

           

          Please see the the dimmer demo application where level client model is implemented. When you press the user button on the evaluation kit the level client messages are being sent (wiced_bt_mesh_model_level_client_set).

           

          Provisioning is taken care by the provisioner app (mobile) where the mesh_config_client model is preset. And the process is automated. (The source code comes along with the SDK).

           

          Thanks,

          -Dheeraj

          1 of 1 people found this helpful
          • 2. Re: [CYBT-423028] what is the best way to send a message over Mesh
            TiEt_4607661

            Hello Dheeraj,

             

            thanks for your response. I've been looking into the dimmer demo application with the help of AN227069. Right now I'm trying to figure out if I did the installation correctly.

             

            I don't have the dimmer demo application but I have lots of other demo applications in the path 20719-B1_Bluetooth/apps/snip/mesh/ when I use WICED Studio v6.2.1. Some examples are: mesh_level_server, mesh_level_client, mesh_onoff_server, mesh_onoff_client. I have more example files under .../apps/snip/ and .../apps/demo/. Do I have the wrong SDK or something? Or maybe there is something I didn't install?

             

            The application note says to install ModusToolbox(doesn't say which version) so I installed the only version I could find(v2.0.0) and when I launch it, I don't see my board in the list of Board Support Packages when I click New Application in ModusToolbox. I do see the CYBT-213043-MESH board in that list, which was used as an example in the application note explaining how the dimmer example works. Do you think it is possible that the dimmer example isn't compatible with CYBT-423028?

             

            I've tried the demo applications I have under .../snip/mesh/ and they worked on my CYBT-423028(I could see level server or level client nodes, as I mentioned in the first post), but the level client demo uses wiced_bt_mesh_create_event_from_wiced_hci() to create a wiced_bt_mesh_event_t, which is apparently used in wiced_bt_mesh_model_level_client_send_set(). I don't understand how I can use the create_event_from_wiced_hci function or even if it is the one I should use.

             

            If you think my installation is correct and that I should have the dimmer demo application, do you have any idea where the file might be stored? If there is a default path I could try to find it. And do you know which library contains the wiced_bt_mesh_model_level_client_set function? Maybe the name of the library might help me find the path or the correct SDK or something.

             

            Best regards,

            Tim

            • 3. Re: [CYBT-423028] what is the best way to send a message over Mesh
              VictorZ_46

              I looked through the discussion and I am not sure I understood what is the problem or what does not work. You configuration steps look right. The only thing I would do is avoid using 0xffff as a pub address. The pub address on the client should be set to the address of the server.

               

              If everything is done correctly, when you call create_event providing 0 for the dst and 0 for app_key_index, the mesh stack will use the pub address and bound app key. If the call to create_event returns NULL, that probably means that something is not right in the configuration steps.

              • 4. Re: [CYBT-423028] what is the best way to send a message over Mesh
                TiEt_4607661

                It seems wiced_bt_mesh_create_event returns NULL when dst is equal to zero, unless the company ID is 0xFFFF. See line 22 and 38 below. MESH_NODE_ID_INVALID is defined as 0x0000 in wiced_bt_mesh_models.h. I tried both with company ID equal to 0xFFFF and with company id something else and dst the unicast address of my destination. The function stopped returning NULL and actually created the event, but it still can't send the message. I've attached the definition of wiced_bt_mesh_create_event() from wiced_mesh_api.c below.

                 

                wiced_bt_mesh_event_t *wiced_bt_mesh_create_event(uint8_t element_idx, uint16_t company_id, uint16_t model_id, uint16_t dst, uint16_t app_key_idx)
                {
                    wiced_bt_mesh_event_t *p_event = (wiced_bt_mesh_event_t*)malloc(sizeof(wiced_bt_mesh_event_t));
                    if (p_event == NULL)
                    {
                        Log("create_unsolicited_event: wiced_bt_get_buffer failed\n");
                        return NULL;
                    }
                    memset(p_event, 0, sizeof(wiced_bt_mesh_event_t));
                
                
                    p_event->opcode = WICED_BT_MESH_OPCODE_UNKNOWN;
                    p_event->element_idx = element_idx;
                    p_event->company_id = company_id;
                    p_event->model_id = model_id;
                    // if it is special case with 0xffff company_id then just create mesh event with default ttl and 0x41 retransmit
                    if (company_id == 0xffff)
                    {
                        p_event->ttl = DEFAULT_TTL;
                        p_event->retrans_cnt = DEFAULT_RETRANSMISSION;
                    }
                    else if (dst != MESH_NODE_ID_INVALID)
                    {
                #if 0
                        else if (!foundation_find_appkey_(app_key_idx, &p_event->app_key_idx, NULL, NULL))
                        {
                            Log("create_unsolicited_event: no app_key_idx:%x\n", app_key_idx);
                            wiced_bt_free_buffer(p_event);
                            return NULL;
                        }
                #endif
                        p_event->dst = dst;
                        p_event->ttl = DEFAULT_TTL;
                        p_event->credential_flag = 0;
                        p_event->retrans_time = 0;
                        p_event->retrans_cnt = 0;
                    }
                    else
                    {
                #if 0
                        if (wiced_bt_mesh_core_get_publication(p_event))
                #endif
                        {
                            free(p_event);
                            return NULL;
                        }
                    }
                    p_event->src = dst;
                    p_event->app_key_idx = app_key_idx;
                    p_event->reply = 0;
                    return p_event;
                }
                
                
                • 5. Re: [CYBT-423028] what is the best way to send a message over Mesh
                  VictorZ_46

                  How do you guess the address of your destination. If device is a provisioner or a device that have access to provisioning database it would know all the addresses and all the app keys, so when it calls create event, it can specify where message is going and how it needs to be protected. 

                   

                  All other client devices (switch, dimmer,...) need to be configured how to "publish" the messages. For example, if you have a light and a switch, a provisioner needs to configure the switch, so that when user pushes the button, the message goes to a specific address or a group of addresses. In addition to that both light and a switch need to have the same app key for encryption.  A switch also needs to know that when it sends a message to the light, it should use this key. One addition step is required for controlling a group scenario is that the light needs to be configured to be a part of the group, i.e. subscribed to the messages destined for the group.

                   

                  If you use Cypress Windows, Android or iOS app to provision devices to the network, it will automatically add some app keys to all devices. If you provision devices to be a part of the group, the client devices (switches) will be configured to publish messages to the group address. And server devices (lights) will be configured to process messages destined to the group.

                   

                  I would suggest you to play with Windows app MeshClient. It has UI to configure pubs and subs and prints some traces. For example if you want to configure Level Client with address 0x0004 to publish Level Client model (0x1003) messages to a device with address 0x0005 following Pub Set will be sent. (Period 0 means that it is not a periodic publication)

                   

                  12:21:50.301 Model Pub Set addr:0004 elem:0004 comp:ffff model:1003 addr:0005 TTL:8 Period:0 Count:0 Interval:500 Cred:0

                  12:21:50.468 Model Pub Status from:4 status:0 Element:4 Pub addr:0005 Model ID:1003 AppKeyIdx:c37 TTL:8 Period:0 Count:0 Interval:500 Cred:0

                   

                  If your device is configured correctly, it can call create_event passing zeroes as DST and APP_KEY_IDX. If device is not configured for publications and you do not tell where message is going, create_event will return NULL.

                  1 of 1 people found this helpful