How to address 2 different elements of the same Node at the same time ?

Hi,

I am trying to create 2 elements with the same vendor model implemented.

My vendor model enables to switch on a pwm_led at a particular power during a given time. I have defined 2 pwm led on my dev kit (nrf52840 devkit) and I defined a vendor model for each of them.

struct led_ctx led_ctx[2] = {
	{
		.led_id = 0,
		.operating_mode = &operating_mode[0],
		.model_srv = BT_MESH_FORCED_WORKING_SRV_INIT(0, &forced_working_state[0])
	},
	{
		.led_id = 1,
		.operating_mode = &operating_mode[1],
		.model_srv = BT_MESH_FORCED_WORKING_SRV_INIT(1, &forced_working_state[1])
	}
};

BT_MESH_MODEL_PUB_DEFINE(forced_working_srv_pub1, NULL, 0);
BT_MESH_MODEL_PUB_DEFINE(forced_working_srv_pub2, NULL, 0);

static struct bt_mesh_elem elements[] = {
	BT_MESH_ELEM(
			1,
		    BT_MESH_MODEL_LIST(
			    BT_MESH_MODEL_CFG_SRV,
			    BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub)),
			BT_MESH_MODEL_LIST(
				BT_MESH_FORCED_WORKING_SRV(&led_ctx[0], &forced_working_srv_pub1))),
	BT_MESH_ELEM(
			2,
		    BT_MESH_MODEL_NONE,
			BT_MESH_MODEL_LIST(
				BT_MESH_FORCED_WORKING_SRV(&led_ctx[1], &forced_working_srv_pub2))),
};

static const struct bt_mesh_comp comp = {
	.cid = VENDOR_ID,
	.elem = elements,
	.elem_count = ARRAY_SIZE(elements),
};

It works fine : when I provision my node I see the 2 elements and each element have an instance of my model. When I send a BT mesh "SET" message to an element I succeed to power on the corresponding LED. But when I try to send a message to "all Nodes" only one of the 2 LED is powered on ... What can I do to address my two elements in the same time ?

I'm sorry if this question has already been asked.

Maureen

Parents
  • Hello Maureen,

    Well that makes sense, as there is only one node here that we are talking about. The nodes 'unicast address' is the same as the first element address of the node - so if you send the message "to the node", it will only be received by the first element. 

    What you need to do is to send the message to all elements, or at least the two elements in question. How are you currently sending it to all nodes?

    Regards,

    Elfving

  • Hello Elfving,

    Yes I agree.
    I want to sent the message to all elements that have the vendor server implemented as if my elements are nodes...

    To solve my problem, my function which handle the message keep the destination address of the message and a loop is looking for this address in the subscription list of all my elements. If this address is in a subscription list, the states of the models which subscription list belongs to are updated. But I wonder if there is a way to automatically do this.

    Regards

    Maureen

  • lalum said:
    implemented as if my elements are nodes...

    Could you expand on this? The elements are individually addressable, you don't have to pretend they are nodes. 

    lalum said:
    my function which handle the message keep the destination address of the message and a loop is looking for this address in the subscription list of all my elements. If this address is in a subscription list, the states of the models which subscription list belongs to are updated. But I wonder if there is a way to automatically do this.

    Are you saying that before sending the message to the address you want, you check an internal list of 'subscribed elements' to see if it is indeed subscribed to this?

    Do you want the message sent to the two elements, which you are already able to do individually, but you want it to be scalable enough to be sent to several elements automatically. If that is the case, I believe the issue could be solved by using a group address for these elements. Have you looked into that option?

    Regards,

    Elfving

  • Hi Elfving,

    You don't understand my problem so I'm going to try to be more clear...

    I have one node with 2 elements (my node is a nrf52840 DK and I have two leds that I consider as two different elements).

    Each led is linked to a custom model with a state "Timer" and a state "lightness". When I send a "SET" message to one element, the corresponding led is switched on at the given lightness during the given timer. 

    I can switch on the two led by sending a message with unicast address, no problem for this. But I want to be able to switch on the two led at the same time. So I subscribed my two LEDs to a group address. But, when I send a message with the group address as the destination, only the primary element receive the message and is switched on.

    Could you expand on this? The elements are individually addressable, you don't have to pretend they are nodes. 

    Yes I know, I can address my elements individually, no problem with that. My problem is that when two elements of the same node subscribe to the same group address, only the primary element receive the message when I use the group address as destination.

    Are you saying that before sending the message to the address you want, you check an internal list of 'subscribed elements' to see if it is indeed subscribed to this?

    No. I check the subscription list of my elements when I receive a message for a group. As my primary element is the only one that receive the message when the message is a message for a group, I have to check for all the other element if they subscribe to the group address too. If yes I update their state too.

    I hope it's more clear for you ... sorry for my poor level in english

    Regards

    Maureen

  • lalum said:

    I hope it's more clear for you ... sorry for my poor level in english

    No problem at all :) as long as we understand each other in the end.

    lalum said:
    But, when I send a message with the group address as the destination, only the primary element receive the message and is switched on.

    Okay. And you've remembered to make both of the elements subscribe to the group address? Does removing the subscription from the primary element make a difference?

    lalum said:
    I check the subscription list of my elements when I receive a message for a group. As my primary element is the only one that receive the message when the message is a message for a group, I have to check for all the other element if they subscribe to the group address too. If yes I update their state too.

    I see. This should normally be automatically handled by the stack, so there should be no need for this.

    Regards,

    Elfving

  • Hello Elfving,

    thank you for your reply !
    here is what i tried and the results :

    • Using the unicast address of the node : the two elements receive the message
    • Using a group address to which both elements are subscribed : only the primary element receive the message
    • Using a group address to which only one element is subscribed : the corresponding element receive the message (it works for the two elements)

    So I don't understand why my second element doesn't receive the message when I use the same group address for the 2 elements as you say it's managed by the stack...

    I wonder where I can define the element address ? I don't see anything in the nrf mesh app to do this, I can only configure the node address...

    Regards

    Maureen

Reply
  • Hello Elfving,

    thank you for your reply !
    here is what i tried and the results :

    • Using the unicast address of the node : the two elements receive the message
    • Using a group address to which both elements are subscribed : only the primary element receive the message
    • Using a group address to which only one element is subscribed : the corresponding element receive the message (it works for the two elements)

    So I don't understand why my second element doesn't receive the message when I use the same group address for the 2 elements as you say it's managed by the stack...

    I wonder where I can define the element address ? I don't see anything in the nrf mesh app to do this, I can only configure the node address...

    Regards

    Maureen

Children
  • Hello again Maureen,

    This is odd. So at this point you have completely removed all the extra loops and functionality and that you mentioned to make sure the message arrives in the right element, right? All of that is handled by the stack.

    lalum said:
    Using the unicast address of the node : the two elements receive the message

    I believe you mentioned earlier that both of the elements are able to be turned on individually using their unicast addresses. But now it seems that when you send a message to just the primary element of the node (the same as the unicast address of the node) its recieved by both elements? Then somethings changed. Did this change happen after you removed that extra functionality you added?

    lalum said:
    Using a group address to which both elements are subscribed : only the primary element receive the message

    Could you tell me what this group address is? Is it the same as the 'all nodes' group?

    Regards,

    Elfving

Related