Topics

[Zephyr-devel] [ #BluetoothMesh ] possible Bug .. without assigning subscription address to Model, it is reacting to subscription address assign to other Model #bluetoothmesh


vikrant8051 <vikrant8051@...>
 

Hi,
It was bug from my side & I've resolved it.
Now everything is working as expected.

Excuse me for that !!

On Wed, May 2, 2018 at 2:31 PM, Vikrant More <vikrant8051@...> wrote:
Hi,

I gone through my code once again & found that it was small bug from my side.
I had forgotten to add "break" in my customized version of $zephyr/samples/bluetooth/mesh .

Extremely sorry for that.

//------------------------------------------------------------------------doer.c----------------------------------------------------------------------------------------------------------------------

#include "common.h"

int8_t  gen_onoff_srv_state, last_gen_onoff_srv_state;
int16_t gen_level_srv_state, last_gen_level_srv_state;

void doer(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, uint16_t opcode)
{
    int err=0;

    int8_t tmp8;
   
    int16_t tmp16;

    struct net_buf_simple *msg;

    switch(opcode)
    {

        case 0x8201:    //GEN_ONOFF_SRV_GET

            msg = NET_BUF_SIMPLE(2 + 1 + 4);

            bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x04));

            net_buf_simple_add_u8(msg, gen_onoff_srv_state);

            if (bt_mesh_model_send(model, ctx, msg, NULL, NULL))
            {
                printk("Unable to send GEN_ONOFF_SRV Status response\n\r");
            }
       
           break;


        case 0x8203:    //GEN_ONOFF_SRV_UNACK

            msg = model->pub->msg;

            gen_onoff_srv_state = (unsigned char)global_state;

            if(last_gen_onoff_srv_state != gen_onoff_srv_state )
            {
                last_gen_onoff_srv_state = gen_onoff_srv_state;

                if(gen_onoff_srv_state != 0)
                {
                    NRF_P0->OUT &= ~(1<<13);    //LED ON
                }
                else
                {
                    NRF_P0->OUT |=  (1<<13);    //LED OFF   
                }

                if(model->pub->addr != BT_MESH_ADDR_UNASSIGNED)
                {

                    bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x04));
                    net_buf_simple_add_u8(msg, gen_onoff_srv_state);

                    err = bt_mesh_model_publish(model);

                    if(err)
                    {
                        printk("bt_mesh_model_publish err %d", err);
                    }

                }
            }

            break;

        case 0x8204:    //GEN_ONOFF_SRV_STATUS

            tmp8 = net_buf_simple_pull_u8(buf);

            NRF_P0->OUT ^= (1<<16);

            printk("Acknownledgement from GEN_ONOFF_SRV = %u\n\r",tmp8);

            break;

        case 0x8205:    //GEN_LEVEL_SRV_GET
           
            msg = NET_BUF_SIMPLE(10);

            bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x08));

            net_buf_simple_add_le16(msg, gen_level_srv_state);

            if(bt_mesh_model_send(model, ctx, msg, NULL, NULL))
            {
                printk("Unable to send GEN_LEVEL_SRV Status response\n\r");
            }

            break;

        case 0x8207:    //GEN_LEVEL_SRV_UNACK

            msg = model->pub->msg;

            gen_level_srv_state = (int16_t)global_state;

            if(last_gen_level_srv_state != gen_level_srv_state )
            {
                last_gen_level_srv_state = gen_level_srv_state;

                printk("gen_level_srv_state = %d \n\r" , gen_level_srv_state );
               
                if(gen_level_srv_state > 10000)
                {   
                    CLRB(NRF_P0->OUT,15);
                    SETB(NRF_P0->OUT,16);
                }
                else
                {   
                    CLRB(NRF_P0->OUT,16);
                    SETB(NRF_P0->OUT,15);
                }
                               
                if(model->pub->addr != BT_MESH_ADDR_UNASSIGNED)
                {

                    bt_mesh_model_msg_init(msg,BT_MESH_MODEL_OP_2(0x82, 0x08));

                    net_buf_simple_add_le16(msg,gen_level_srv_state);

                    err = bt_mesh_model_publish(model);

                    if (err)
                    {
                        printk("bt_mesh_model_publish err %d", err);
                    }

                }
            }       
   
            break;

        case 0x8208:    //GEN_LEVEL_SRV_STATUS

            tmp16 = net_buf_simple_pull_le16(buf);
            printk("Acknownledgement from GEN_LEVEL_SRV = %d\n\r",tmp16);

            break;

        case 0x820A:    //GEN_DELTA_SRV_UNACK
           
            break;

        case 0x820C:    //GEN_MOVE_SRV_UNACK
           
            break;

        default:

           break;
    }
}



On Wed, Apr 25, 2018 at 9:28 PM, Vikrant More <vikrant8051@...> wrote:
Hi Kai,

Please see attached mesh.zip file for what you had asked. (Refer DEVICE_composition.c for 
static struct bt_mesh_model root_models[] = {};
             static struct bt_mesh_elem elements[] = { }; )

I have break provided #ZephyrBluetoothMesh sample code into multiple files for simplicity.

Have you faced same issue ?

Please let me Know, if there is bug from my side & keep me in loop if you are going to ask further queries based on it.

Thank You !!

On Wed, Apr 25, 2018, 8:39 PM Vikrant More <vikrant8051@...> wrote:
Hi Kai,
Sorry, today I was busy & didn't get time to access my email. Right now I am on the way to my Home. Tomorrow I will definitely share what you have asked.

Thanks !!

On Wed, Apr 25, 2018, 9:21 AM Kai Ren <kren@...> wrote:
Hi vikrant8051,
Could you please share the following definitions?
             static struct bt_mesh_model root_models[] = {};
             static struct bt_mesh_elem elements[] = { };

Thanks!

Kai