Page 1 of 1

BLE Mesh when the LPN creates a friendship no group addresses are registered

Posted: Tue Jun 09, 2020 12:10 am
by mishafarms
I am playing with BLE Mesh and LPN. If my node already has a friendship and I provision a group subscription, when I send to the group the node gets the message. But if the node loses the friendship either because the node or the friend is reset or because I lose network connectivity, When the new friendship is established, I no longer get the group messages.

This is because they are not re-registered with the friend. I believe that the LPN should do this at a low layer. But I currently solved it by calling this code in my main. I think this is a bug in the LPN code. Am I correct? or should this be done in the prov_cb?
Michael

Code: Select all

static void register_sub_with_friend(void)
{
	// need a pointer to the composition data
	u16_t myGroups[CONFIG_BLE_MESH_LPN_GROUPS];
	int groupIdx = 0;

	const esp_ble_mesh_comp_t *myComp = esp_ble_mesh_get_composition_data();

	if (myComp == NULL)
	{
		ESP_LOGE(TAG, "No composite data found");
		// we are done now
		return;
	}

	// I got the composite. now walk the element list.

	for (int i = 0; i < myComp->element_count; i++)
	{
		// access the element
		const esp_ble_mesh_elem_t *myElement = &myComp->elements[i];

		// walk the SIG models

		for (int j = 0; j < myElement->sig_model_count; j++)
		{
			// now I need to look to see which groups are registered for this model

			const esp_ble_mesh_model_t *myModel = &myElement->sig_models[j];

			if (myModel == NULL)
			{
				// this shouldn't happen
				ESP_LOGE(TAG, "Model is NULL");
				continue;
			}

			for (int k = 0; k < CONFIG_BLE_MESH_MODEL_GROUP_COUNT; k++)
			{
				if (myModel->groups[k])
				{
					if (groupIdx < CONFIG_BLE_MESH_LPN_GROUPS)
					{
						myGroups[groupIdx++] = myModel->groups[k];
						ESP_LOGI(TAG, "Group %04x registered", myModel->groups[k]);
					}
				}
			}
		}

		// walk the SIG models

		for (int j = 0; j < myElement->vnd_model_count; j++)
		{
			// now I need to look to see which groups are registered for this model

			const esp_ble_mesh_model_t *myModel = &myElement->vnd_models[j];

			if (myModel == NULL)
			{
				// this shouldn't happen
				ESP_LOGE(TAG, "Model is NULL");
				continue;
			}

			for (int k = 0; k < CONFIG_BLE_MESH_MODEL_GROUP_COUNT; k++)
			{
				if (myModel->groups[k])
				{
					if (groupIdx < CONFIG_BLE_MESH_LPN_GROUPS)
					{
						myGroups[groupIdx++] = myModel->groups[k];
						ESP_LOGI(TAG, "Group %04x registered", myModel->groups[k]);
					}
				}
			}
		}
	}

	// delete all the groups, then add them again, this should be no problem and make sure that we subscribe at the
	// friend

	bt_mesh_lpn_group_del(myGroups, groupIdx);

	// now do it one at a time

	for (int i = 0; i < groupIdx; i++)
	{
		bt_mesh_lpn_group_add(myGroups[i]);
	}
}