<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107846/hsl-mesh-server-defintion-macro-issue</link><description>I am building off the example app for nrf connect SDK light server . I can successfully flash and test that example. 
 
 I was trying to extend it to include the HSL server and I am running into an issue with this code: 
 I get the error: expression must</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 Feb 2024 05:49:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107846/hsl-mesh-server-defintion-macro-issue" /><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/467287?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 05:49:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6fc55e63-3b9d-4d85-995a-de32062d238e</guid><dc:creator>parksj10</dc:creator><description>&lt;p&gt;FWIW to anyone seeing this in the future, I solved it by refactoring like so:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;

static struct bt_mesh_onoff_srv onoff_srv_0 = BT_MESH_ONOFF_SRV_INIT(&amp;amp;onoff_handlers);
static struct bt_mesh_lightness_srv lightness_srv_0 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
static struct bt_mesh_light_hsl_srv light_hsl_srv_0 = BT_MESH_LIGHT_HSL_SRV_INIT(&amp;amp;lightness_srv_0, &amp;amp;hue_handlers, &amp;amp;saturation_handlers);
static struct bt_mesh_onoff_srv onoff_srv_1 = BT_MESH_ONOFF_SRV_INIT(&amp;amp;onoff_handlers);
static struct bt_mesh_lightness_srv lightness_srv_1 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
static struct bt_mesh_light_hsl_srv light_hsl_srv_1 = BT_MESH_LIGHT_HSL_SRV_INIT(&amp;amp;lightness_srv_1, &amp;amp;hue_handlers, &amp;amp;saturation_handlers);


struct led_ctx
{
	struct k_work_delayable onoff_work;
	struct k_work_delayable lightness_work;
	struct k_work_delayable sat_work;
	struct k_work_delayable hue_work;

	struct bt_mesh_onoff_srv *onoff;
	struct bt_mesh_lightness_srv *lightness;
	struct bt_mesh_light_hsl_srv *light_hsl;
	struct bt_mesh_light_hue_srv *hue;
	struct bt_mesh_light_sat_srv *sat;

	uint32_t onoff_remaining;
	bool onoff_value;
	uint32_t lightness_remaining;
	uint16_t lightness_value;
	uint32_t hue_remaining;
	uint16_t hue_value;
	uint32_t sat_remaining;
	uint16_t sat_value;
	uint16_t element_idx;
	// 2. link element_idx to this context, then lookup the ctx based on element of the model
	// 3. also rearrange elements to created for each led (element one is led 1, element 2 is led 2)
};

static const LED_COUNT = 2;
struct led_ctx led_ctx[LED_COUNT] = {{
	.onoff = &amp;amp;onoff_srv_0,
	.lightness = &amp;amp;lightness_srv_0,
	.light_hsl = &amp;amp;light_hsl_srv_0,
	.hue = &amp;amp;light_hsl_srv_0.hue,
	.sat = &amp;amp;light_hsl_srv_0.sat,
},
{
	.onoff = &amp;amp;onoff_srv_1,
	.lightness = &amp;amp;lightness_srv_1,
	.light_hsl = &amp;amp;light_hsl_srv_1,
	.hue = &amp;amp;light_hsl_srv_1.hue,
	.sat = &amp;amp;light_hsl_srv_1.sat,
}};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/466671?ContentTypeID=1</link><pubDate>Tue, 30 Jan 2024 07:56:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2db25103-e85a-4660-b464-f60f1fd6f8ce</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;That is basic C programming issue. You cannot initialize a whole struct this way. You can initialize pointers to a struct but not the whole struct as a constant initializer.&lt;/p&gt;
&lt;p&gt;I suggest that you omit .lightness initialization at this point and do a memcpy from .lightness_srv_1 into a lightness struct inside&amp;nbsp;model_handler_init&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/466663?ContentTypeID=1</link><pubDate>Tue, 30 Jan 2024 07:29:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f36dd66f-fed1-4fd3-9c8d-fcf6ab5520a2</guid><dc:creator>parksj10</dc:creator><description>&lt;p&gt;Please see the original post, this is not possible. I need to add the HSL server as well. The HSL server takes the lightness server as an argument. I cannot define them both in the led_ctx variable&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/466658?ContentTypeID=1</link><pubDate>Tue, 30 Jan 2024 06:28:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:584475cf-5377-441d-9673-47b7020b65ec</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Right, I do not know why I did not see this at the first glance but the compiler says it clearly that you are not using the constant in the initializer&amp;nbsp; for .lightness. Instead do it like this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#if DT_NODE_EXISTS(DT_ALIAS(led0))
	{
     .lightness = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_srv_handlers),
	},
#endif
#if DT_NODE_EXISTS(DT_ALIAS(led1))
    {
     .lightness = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_srv_handlers),
	 },
#endif
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;No need to have additional&amp;nbsp;static&amp;nbsp;variables&amp;nbsp;lightness_srv_0 and&amp;nbsp;lightness_srv_1&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/466618?ContentTypeID=1</link><pubDate>Mon, 29 Jan 2024 20:12:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f38d5dd7-094e-43b7-930b-20f7b151ecb2</guid><dc:creator>parksj10</dc:creator><description>&lt;p&gt;That is indeed a typo, but it isn&amp;rsquo;t the root problem. If I fix that the base&amp;nbsp;problem still exists.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Mesh server defintion macro issue</title><link>https://devzone.nordicsemi.com/thread/466457?ContentTypeID=1</link><pubDate>Mon, 29 Jan 2024 11:18:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:425c0e27-a751-4bfe-9872-1cacf04d295d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I think it is a copy paste issue in your code. You have not created an instance for øightness_srv_1 since you have&amp;nbsp; this below checking for node exists for led0 twice&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#if DT_NODE_EXISTS(DT_ALIAS(led0))
	static struct bt_mesh_lightness_srv lightness_srv_0 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
#endif
#if DT_NODE_EXISTS(DT_ALIAS(led0))
	static struct bt_mesh_lightness_srv lightness_srv_1 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You need to change it to&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#if DT_NODE_EXISTS(DT_ALIAS(led0))
	static struct bt_mesh_lightness_srv lightness_srv_0 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
#endif
#if DT_NODE_EXISTS(DT_ALIAS(led1))
	static struct bt_mesh_lightness_srv lightness_srv_1 = BT_MESH_LIGHTNESS_SRV_INIT(&amp;amp;lightness_handlers);
#endif&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>